1 TRADE PER DAY

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #179862 quote
    coh123
    Participant
    New

    Hi there,

     

    This forum has been incredibly useful so far for a lot of things so thank you.

    I have seen a couple of posts regarding the 1 trade per day coding but non of them seem to work for me so I was wondering if there was just a standard code you can input into the strategy?

    Many thanks

    #179863 quote
    MauroPro
    Participant
    Veteran
    Try to add this to your code: singleDayTrade = (barIndex-tradeIndex(1)>intradayBarIndex)

    #179873 quote
    coh123
    Participant
    New
    Thanks for trying but it doesn’t seem to work.
    #179876 quote
    MauroPro
    Participant
    Veteran
    Very strange, it should work. In any case, try this snippet (Nicolas): if intradaybarindex=0 or day<>day[1] then count=0 endif if ( (not onmarket and onmarket[1] and not onmarket[2]) or (tradeindex(1)=tradeindex(2) and tradeindex(1)=barindex[1] and tradeindex(1)>0) or (not onmarket and onmarket[1])) then count=count+1 endif Then: if “myConditions” and count<1 then …  

    #179879 quote
    coh123
    Participant
    New
    Unfortunately that doesn’t work either. I’ll put the code below to see if anyone can figure out why… // Definition of code parameters DEFPARAM CumulateOrders = False // Cumulating positions deactivated // Conditions to enter long positions indicator1 = (DHigh(1) + DLow(1) + DClose(1))/3-(DHigh(1)-DLow(1)) c1 = (close <= indicator1) indicator2 = RSI[14](close) c2 = (indicator2 <= 30) indicator3 = MACDline[12,26,9](close) c3 = (indicator3 <= -0.0015) indicator4 = DLow(1)-2*(DHigh(1)-(DHigh(1) + DLow(1) + DClose(1))/3) c4 = (close >= indicator4) if intradaybarindex=0 or day<>day[1] then count=0 endif if ( (not onmarket and onmarket[1] and not onmarket[2]) or (tradeindex(1)=tradeindex(2) and tradeindex(1)=barindex[1] and tradeindex(1)>0) or (not onmarket and onmarket[1])) then count=count+1 endif // initiate a new BUY order if c1 AND c2 AND c3 AND c4 and count<1 THEN BUY 10 CONTRACT AT MARKET endif   // Conditions to exit long positions indicator5 = MACDline[12,26,9](close) c5 = (indicator5 >= 0) IF c5 THEN SELL AT MARKET ENDIF // Conditions to enter short positions indicator6 = MACDline[12,26,9](close) c6 = (indicator6 >= 0.0015) indicator7 = RSI[14](close) c7 = (indicator7 >= 70) indicator8 = (DHigh(1) + DLow(1) + DClose(1))/3+(DHigh(1)-DLow(1)) c8 = (close >= indicator8) indicator9 = DHigh(1)+2*((DHigh(1) + DLow(1) + DClose(1))/3-DLow(1)) c9 = (close <= indicator9) IF c6 AND c7 AND c8 AND c9 and count<1 THEN SELLSHORT 10 CONTRACT AT MARKET ENDIF // Conditions to exit short positions indicator10 = MACDline[12,26,9](close) c10 = (indicator10 <= -0.0015) IF c10 THEN EXITSHORT AT MARKET ENDIF   // Stops and targets SET STOP pLOSS 6 SET TARGET pPROFIT 32
    #179884 quote
    robertogozzi
    Moderator
    Master
    OTD (One Trade per Day) works fine for me:
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = (DHigh(1) + DLow(1) + DClose(1))/3-(DHigh(1)-DLow(1))
    c1 = (close <= indicator1)
    indicator2 = RSI[14](close)
    c2 = (indicator2 <= 30)
    indicator3 = MACDline[12,26,9](close)
    c3 = (indicator3 <= -0.0015)
    indicator4 = DLow(1)-2*(DHigh(1)-(DHigh(1) + DLow(1) + DClose(1))/3)
    c4 = (close >= indicator4)
    
    //if intradaybarindex=0 or day<>day[1] then
    //count=0
    //endif
    
    //if ( (not onmarket and onmarket[1] and not onmarket[2]) or (tradeindex(1)=tradeindex(2) and tradeindex(1)=barindex[1] and tradeindex(1)>0) or (not onmarket and onmarket[1])) then
    //count=count+1
    //endif
    OTD = (Barindex - TradeIndex(1) > IntradayBarIndex) //OR 1
    // initiate a new BUY order
    //if c1 AND c2 AND c3 AND c4 and count<1 THEN
    if c1 AND c2 AND c3 AND c4 and OTD THEN
    BUY 10 CONTRACT AT MARKET
    endif
    
     
    
    // Conditions to exit long positions
    indicator5 = MACDline[12,26,9](close)
    c5 = (indicator5 >= 0)
    
    IF c5 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator6 = MACDline[12,26,9](close)
    c6 = (indicator6 >= 0.0015)
    indicator7 = RSI[14](close)
    c7 = (indicator7 >= 70)
    indicator8 = (DHigh(1) + DLow(1) + DClose(1))/3+(DHigh(1)-DLow(1))
    c8 = (close >= indicator8)
    indicator9 = DHigh(1)+2*((DHigh(1) + DLow(1) + DClose(1))/3-DLow(1))
    c9 = (close <= indicator9)
    
    //IF c6 AND c7 AND c8 AND c9 and count<1 THEN
    IF c6 AND c7 AND c8 AND c9 and OTD THEN
    SELLSHORT 10 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator10 = MACDline[12,26,9](close)
    c10 = (indicator10 <= -0.0015)
    
    IF c10 THEN
    EXITSHORT AT MARKET
    ENDIF
    
     
    
    // Stops and targets
    SET STOP pLOSS 6
    SET TARGET pPROFIT 32
    try backtesting the same code, just removing the two comment slashes from line 21.
    #179888 quote
    coh123
    Participant
    New
    Hi Roberto, Really appreciate you integrating the code for me! It is quite strange because I backtested the code you sent back as well as the code I had previously and over 6 years yours bankrupted the account and the other made £4k haha. I tested again with a larger account size and it just had a steady stream of losses till money lost again. Is there something in the code that perhaps makes it sell? Again, I’m still very much learning but something doesn’t seem quite right! 🙂
    #179894 quote
    PeterSt
    Participant
    Master
    IF c6 AND c7 AND c8 AND c9 and OTD THEN
      SELLSHORT 10 CONTRACT AT MARKET
    ENDIF
     
    // Conditions to exit short positions
    indicator10 = MACDline[12,26,9](close)
    c10 = (indicator10 <= -0.0015)
     
    IF c10 THEN
      EXITSHORT AT MARKET
    ENDIF
    No matter the origin, if you code like that (above), it becomes unreadable for yourself. Also, the result will be unpredictable (which is almost the same ;-)).
     // Conditions to exit short positions
    indicator10 = MACDline[12,26,9](close)
    c10 = (indicator10 <= -0.0015)
    
    IF c6 AND c7 AND c8 AND c9 and OTD THEN
      SELLSHORT 10 CONTRACT AT MARKET
    ELSIF c10 THEN
      EXITSHORT AT MARKET
    ENDIF
    If you code like the above, you depict mutual exclusive situations, which with the first example are not mutually exclusive at all. A bit more tightly coded would be like this :
    IF c6 AND c7 AND c8 AND c9 and OTD THEN
      SELLSHORT 10 CONTRACT AT MARKET
    ELSE 
    
      // Conditions to exit short positions
    
      indicator10 = MACDline[12,26,9](close)
      c10 = (indicator10 <= -0.0015)
    
      If c10 THEN
        EXITSHORT AT MARKET
      ENDIF
    
    ENDIF
    
    
    But this still would leave you with all kind of doubts, and it should be like this :
    If Not OnMarket then
    
      EnteredMarket = 0
    
      If Not EnteredMarket then   // Superfluous here, but good habit.
    
        // Conditions to go Short.
    
        IF c6 AND c7 AND c8 AND c9 and OTD THEN
          SELLSHORT 10 CONTRACT AT MARKET
          EnteredMarket = 1
        ENDIF 
    
      ENDIF
    
      If Not EnteredMarket then   // Nit superfluous at all.
    
        // Other conditions for going Short or ... Long.
    
        IF ... then
          // ...
          EnteredMarket = 1
        ENDIF
    
      ENDIF
    
    ENDIF   // Not OnMarket ?
    
    If Not EnteredMarket then   // A bit of overkill, but in certain situations even this is good habit.
    
      If ShortOnMarket then
    
        // Conditions to exit short positions
    
        indicator10 = MACDline[12,26,9](close)
        c10 = (indicator10 <= -0.0015)
    
        If c10 THEN
          EXITSHORT AT MARKET
        ENDIF
    
      ENDIF   // ShortOnMarket ?
    
    ENDIF   // Not EnteredMarket ?
    This leaves no doubt about what is happening and “what you are doing”; Try to rebuild the code like this and you may automatically run into the culprit(s) why it is not working out, even before running your re-coded program. Never think this is long-winded and a waste of time, because clarity above all ! Good luck now !
    #179895 quote
    PeterSt
    Participant
    Master
    I found a bug ! 🙂
    If Not OnMarket then
     
      EnteredMarket = 0
     
      If Not EnteredMarket then   // Superfluous here, but good habit.
     
    // The above is wrong and it should be like this :
    
    EnteredMarket = 0
    
    If Not OnMarket then
      
      If Not EnteredMarket then   // Superfluous here, but good habit.
     
    coh123 thanked this post
    #179939 quote
    coh123
    Participant
    New
    Wow, that has worked. I’m really grateful thank you.
    #188013 quote
    drive
    Participant
    Junior
    Thx, Roberto but really dont know what you are meaning, thx for your support
    #188014 quote
    robertogozzi
    Moderator
    Master
    Thx, Roberto but really dont know what you are meaning, thx for your support
    Why are you answering here? Please do NO scatter infor all over the forum! Keep posting in your own topic. Thanks 🙂
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

1 TRADE PER DAY


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
coh123 @coh123 Participant
Summary

This topic contains 11 replies,
has 5 voices, and was last updated by robertogozzi
4 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/18/2021
Status: Active
Attachments: No files
Logo Logo
Loading...