Trading Day of Month

Forums ProRealTime English forum ProOrder support Trading Day of Month

Viewing 15 posts - 1 through 15 (of 17 total)
  • #114902

    Hi all,

     

    I want to code out a simple system that goes long on the 3rd to last trading day of the month and then exits on the last day of the month. Does anyone know how to code this simple idea? I can’t fathom how to reliably identify the trading day of the month, using the DAY, MONTH, YEAR functions.

    Any help would be greatly appreciated.

     

    Thanks

    #114905

    There you go (non tested):

    you need to add TradeON to your conditions to enter a trade.

     

    #114909

    Roberto – That is the third day of the month and not the third to last day of the month.

    We will need some calculation based on month and year to know how many days are in any month so that we can decide if it is three days from the end of the month.

    We also need to know if we are counting trading days or actual days. It is more complicated than I want to get into after a glass of wine!

    #114911

    He wrote “on the 3rd to last trading day”.

     

    #114922

    Third to last is three trading days before the end of the month. Your code starts counting three days from the start of the month.

    We need to know which month and year it is and then calculate how many days are in that month (allowing for leap years), then we need to know what day of the week three days before the end is and tweak our count back if it is a Sunday (unless the OP is happy with six candle weeks). We will then know what the third trading day before the end of the months date is and can just check to see if today is that day or not.

    #114923

    This is some date math functions I made, despite many errors in past years data https://www.prorealcode.com/topic/tomorrows-date/

    So at the beginning of each month trading should be disabled, then max days in the month should be detected, then counting backwords from the last day, 3 trading days need to be found, to reenable trading.

    It’s not as straightforward but can be done.

    #114943

    Cheers guys. I figured it would be a challenge. I’ll have a play around with Roberto’s functions.

    #114979

    Maybe something of interest related to this strategy here: (snippets to find  last day and last trading day of the month)

    coding help about buy and sell on certain days of the month

    #115036

    This sindicator will return the 3rd last trading day of the month (if the month ends on Monday it will return Thursday). It uses my functions that will be automatically imported when you import the indicator:

    You can clear a flag, say variable TradeON (set it to  0), at the beginning of the month, then reenable it when OpenDay=DayStart.

    You can remove OPEN from Date, Year and Month if you prefer using those returned when a candle close, instead of when it opens.

    This is the sample code for the strategy:

     

     

    3 users thanked author for this post.
    #115125

    Thanks you so much Roberto, that really is a very useful set of functions. Many thanks for sharing them and helping with this. Alas the system ideas was not profitable, over the long term. The anecdotal evidence over the last few years looked like the might have been some alpha there in the T bonds but going back to 2000 it fails miserably. Nevermind. Good be able to test it.

     

    1 user thanked author for this post.
    #184855

    Hi guys many thanks for this thread. Roberto – I have one question to u – What about if I want to go long on a specfic day and date – how can I do this. I tried this but does not work:

    //Set Buy- and SellTime
    BuyTime = 0
    SellTime = 0
    //Set Entry date

    IF (date = 20210113) and (time=220000) Then
    BuyTime = 1
    ENDIF

    IF (date = 20210118) and (time=220000) Then
    SellTime = 1
    ENDIF

    Greetings

    Salah

    #184857

    What timeframe are you using?

     

    #184858

    daily

    #184860

    That’s why it doesn’t work. In a Daily TF you cannot access times, so there will never be 220000.

    This is because code is always executed when a candle closes.

    You have to have to use a TF with candles closing on a 1-hour boundary.

    #184984

    Many thanks Robert – what do I need to change in my code then?

    Greetings

Viewing 15 posts - 1 through 15 (of 17 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login