Auto selecting last trading day of the month

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #180439 quote
    smp
    Participant
    Average

    Hi guys,

    I have completed a strategy trading on the last trading day of each month but the code seems a little “clunky”, does anyone know how I can improve the code I have written to always trade on the last trading day of the month?

    Area of the code to improve:

    =========================

     

    // Defines the End of Month and End of Quarter trading days.
    TradingYear = 2021
    JanEOM = Month=1 AND Day=29 // Friday, 29 Jan 2021
    FebEOM = Month=2 AND Day=26 // Friday, 26 Feb 2021
    MarEOM = Month=3 AND Day=31 // Wednesday, 31 Mar 2021
    AprEOM = Month=4 AND Day=30 // Friday, 30 Apr 2021
    MayEOM = Month=5 AND Day=31 // Monday, 31 May 2021
    JunEOM = Month=6 AND Day=30 // Wednesday, 30 Jun 2021
    JulEOM = Month=7 AND Day=30 // Friday, 30 Jul 2021
    AugEOM = Month=8 AND Day=31 // Tuesday, 31 Aug 2021
    SepEOM = Month=9 AND Day=30 // Thursday, 30 Sep 2021
    OctEOM = Month=10 AND Day=29 // Friday, 29 Oct 2021
    NovEOM = Month=11 AND Day=30 // Tuesday, 30 Nov 2021
    DecEOM = Month=12 AND Day=31 // Friday, 31 Dec 2021
    //EOMDate = JanEOM OR FebEOM OR AprEOM OR MayEOM OR JulEOM OR AugEOM OR OctEOM OR NovEOM
    //EOQDate = MarEOM OR JunEOM OR SepEOM OR DecEOM
    #180443 quote
    robertogozzi
    Moderator
    Master

    This is a code snippet that calculates the last trading day of the month https://www.prorealcode.com/topic/codes-for-not-opening-trades-at-month-end/#post-175920

    smp thanked this post
    #180445 quote
    smp
    Participant
    Average

    Thank you, my save hard coding each day every month.  I Will still have to ensure the holidays and time differences plus daylight saving hours are put in every as PRC has no way to determine this!  Or has it?

    #180456 quote
    robertogozzi
    Moderator
    Master

    As to DST  you have to account for it according to the instrument or asset traded, as there’s no way to automatically detect it.

    As to holidays, well… you can’t start any trade as the market is closed. The only issue is when you want to close open positions BEFORE the holiday, in which case you will have to read a news calendar every year (they are usually available prior to December 31st) and set them manually in your code each year.

    smp thanked this post
    #180470 quote
    smp
    Participant
    Average

    Thank you for your time.  I have manually incorporated holidays now.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Auto selecting last trading day of the month


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
smp @smpaxton Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by smp
4 years, 3 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 10/27/2021
Status: Active
Attachments: No files
Logo Logo
Loading...