help coding time/date-based strategy

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #191813 quote
    ullle73
    Participant
    Senior

    i found this interesting pic in a thread here at prorealcode.

     

    Could anyone help me code following.

    • go long at the last third day of the month(T -3), exit long after 3 first day of following month (T +3)
    • go short at last 8 days of the month (T -8), exit short after 4 days (T -4)
    • SL long X
    • SL short Y
    Skarmbild-2022-04-15-230451.jpg Skarmbild-2022-04-15-230451.jpg
    #191876 quote
    robertogozzi
    Moderator
    Legend

    There you go:

    DEFPARAM CumulateOrders = FALSE
    LongSL  = 50 * PipSize
    ShortSL = LongSL
    //
    IF Month <> Month[1] THEN        //When the current bar's month <> previous one's then a new month just started...
       WeekDay   = DayOfWeek         //...so we need to start counting weekdays from scratch
       ThisMonth = Month
       ThisYear  = Year
       LastDay   = 31
       Last3rd   = 99
       Last8th   = 99
       Tally     = 0
       TradeON   = Not OnMarket
       If ThisMonth = 4 or ThisMonth = 6 or ThisMonth = 9 or ThisMonth = 11 Then
          LastDay = 30
       Endif
       //Check if it's a Leap year
       If ThisMonth = 2 Then
          LastDay = 28
          If ThisYear mod 4 = 0 Then
             If ThisYear mod 100 = 0 Then
                If ThisYear mod 400 = 0 Then
                   LastDay = 29
                Endif
             Else
                LastDay = 29
             Endif
          Endif
       Endif
       //Start Counting
       EOM = 0                            //EOM = End Of Month
       FOR i = 2 TO LastDay
          WeekDay = WeekDay + 1
          If WeekDay <= 5 Then
             EOM = i
          Elsif WeekDay = 7 Then
             WeekDay = 0
          Endif
       Next
    Endif
    //
    Last8th = EOM - 8    //Eighth Last Day of the month (it can't be known if it's a holiday)
    Last3rd = EOM - 3    //Third  Last Day of the month (it can't be known if it's a holiday)
    //
    IF Not OnMarket AND Day > Last8th AND Day <> Day[1] AND Day < Last3rd AND TradeON THEN
       SELLSHORT 1 CONTRACT AT MARKET
       SET STOP pLOSS ShortSL
       TradeON = 0
       Tally   = 1
    ENDIF
    IF ShortOnMarket AND Day <> Day[1] THEN
       Tally = Tally + 1
       IF Tally >= 4 THEN
          Tally  = 0
          TradeON = 1
          EXITSHORT AT MARKET
       ENDIF
    ENDIF
    //
    IF Day >= Last3rd AND Day <= LastDay AND Day > Last8th AND Day <> Day[1] AND TradeON THEN
       BUY 1 CONTRACT AT MARKET
       SET STOP pLOSS LongSL
       TradeON = 0
       Tally   = 99
    ENDIF
    IF LongOnMarket AND Day <> Day[1] AND Tally < 3 THEN
       Tally = Tally + 1
       IF Tally = 3 THEN
          Tally   = 0
          TradeON = 1
          SELL AT MARKET
       ENDIF
    ENDIF
    //graph LastDay
    //graph Last8th
    //graph Last3rd
    //graph Day
    //graph Tally
    HannesA thanked this post
    MySystem-2.itf
    #192264 quote
    ullle73
    Participant
    Senior

    thanks again roberto 😀

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

help coding time/date-based strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
ullle73 @jonas_rydqvist Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/15/2022
Status: Active
Attachments: 2 files
Logo Logo
Loading...