Cumulating strategy does not work

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #25139 quote
    Pere
    Participant
    Veteran

    I want to program a Probacktest with following conditions:
    Every time I get a long signal, it has to buy 1 long share at market, cumulating the trades with every following long signal until it gets a short signal.
    In this moment, I want to exit (sell) ALL the long trades and buy 1 short. If the next step is again short, it has to sellshort another one, cumulating it with the last short. If the signal is long, it has to sellshort ALL the short trades and buy one long, and so one.

    I coded following backtest, but it doesn’t work correctly, there is probably some instruction missing. Can someone help me?

    The code is:

    DEFPARAM CumulateOrders = true  // cumulate orders, if not turn it off with "false"
    //***Stair step Moving Average
    //parameters :
    //Step = 10// 0.0010 forex 10 pips, adapt to item you are trading
    //MAperiod = 7
    //sl=50
    once ssMA = close
    MA = average[MAperiod](close)
    aa=ssMA+Step
    bb=ssMA-Step
    if(MA>aa) THEN
    ssMA = MA
    ELSIF (MA<bb) THEN
    ssMA = MA
    ELSE
    ssMA = ssMA
    ENDIF
    
    IF ssMA>ssMA[1] THEN
    k=1
    ELSIF ssMA<ssMA[1] THEN
    k=-1
    ELSE
    k=0
    ENDIF
    
    // Long trades
    IF k=1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Sell long trades
    IF k=-1 THEN
    SELL AT MARKET
    ENDIF
    
    // Short trades
    IF k=-1 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Exit short trades
    IF k=1 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stop loss
    SET STOP pLOSS sl
    #25154 quote
    Pere
    Participant
    Veteran

    Sorry, there is an error on my text:

    Instead of

    If the signal is long, it has to sellshort ALL the short trades and buy one long, and so one.

    It should be:

    If the signal is long, it has to exitshort (buy) ALL the short trades and buy one long, and so one.

    On the code is probably missing an instruction to sell or buy ALL the trades, but I don’t know which one.

    #25155 quote
    Derek
    Participant
    Veteran

    Hello Petrus,

    maybe like this?

    if exit-short-condition = 1 then
    exitshort at market
    buy 1 contract at market
    endif
    
    if enter-long-condition = 1 then
    buy 1 contract at market
    endif

    The difference is “exitshort 1 contract at market” and “exitshort at market”. The second version closes all short position at the same time.

    #25160 quote
    JC_Bywan
    Moderator
    Master

    Hi Petrus,

    I edit the code in your message to make it appear in PRT style

    >> For clarity of messages on ProRealCode’s forums, please use the “insert PRT code” button to separate the text of the code part! Thank you! <<

    #25169 quote
    Pere
    Participant
    Veteran

    @Derek Thank you Derek. But I think I had it already so:

    For buying long conditions I have “BUY 1 CONTRACT AT MARKET” and to sell ALL the longs “SELL AT MARKET”.

    For selling shorts I wrote “SELLSHORT 1 CONTRACT AT MARKET”, and to buy ALL the shorts “EXITSHORT AT MARKET”, which should close ALL the shorts.

    The only thing that is missing is the instruction “BUY 1 CONTRACT AT MARKET” after this “EXITSHORT”, which should buy one long trade after closing all the shorts. I will try that, thanks.


    @Noobywan
    Yes, I know that I should use the “insert PRT code” for the code part, but I couldn’t find this button when I wrote the post. However, I already can see it now, on the reply of this post. Maybe it was a temporary error. Thanks.

    JC_Bywan thanked this post
    #25179 quote
    JC_Bywan
    Moderator
    Master

    Hi again,

    I have tried on french index, with parameters as indicated in comments, it doesn’t make money on the timeframe I tried (maybe it is designed for a higher timeframe), but it seems to do what is expected of it: buying one contract each time k=1, selling all long and buying one short when k=-1, adding 1 short each time k=-1, exiting all of them shorts and buying one long if k=1… I haven’t noticed incorrect behaviour so far.

    Could you be more specific about what doesn’t seem correct when you run it? it doesn’t start? orders don’t seem to follow k behaviour? other observation?

    #25192 quote
    Pere
    Participant
    Veteran

    Hi Noobywan.

    I was comparing the results of the Probacktest with a different histogram indicator where I had different parameter values. That’s the reason because I thought that the backtest did not work correctly. I changed the parameters and it seems now to work well. I agree that the other problem is that this strategy does not make money, but I have to work more in this idea. What I only wanted to know is that the instructions to sell or to exitshort closed all the trades, not only one, and it also seems now to be correct. Thanks for the help.

    #25242 quote
    Pere
    Participant
    Veteran

    Hi again Noobywan.

    Today I cannot see again the button “Insert PRT code”, as you can see in the image attached. Is there any solution?

    I also attach another image of another post where I cannot insert an image. I click on Attach/Edit image, try to upload the image but get always the same HTTP error. How can I attach the image?

    JC_Bywan thanked this post
    No-PRT-code.jpg No-PRT-code.jpg 2017-02-16_8-20-16.jpg 2017-02-16_8-20-16.jpg
    #25252 quote
    JC_Bywan
    Moderator
    Master

    Hi,

    Thanks for the feedback, first problem about “insert prt code” button was known in very specific cases (but as moderator I can’t make the difference between somebody not using it and somebody not having it), second problem about inserting an image we’ll let Nicolas know.

    #25254 quote
    Pere
    Participant
    Veteran

    Hi Noobywan. I have now the Insert PRT code button again!

    #25255 quote
    Nicolas
    Keymaster
    Master

    Adding images in comments are still not possible, sorry for this.

    About the missing button, it doesn’t appear on some specific screen widths to prevent bugs with smartphone or tablet. What is your screen resolution?

    #25256 quote
    Pere
    Participant
    Veteran

    Noobywan, please send also the attached image to Nicolas referring to the Stair Step indicator, as I cannot insert it there. Thanks.

    StairStep.jpg StairStep.jpg
    #25259 quote
    Pere
    Participant
    Veteran

    Hi Nicolas. My screen resolution is 3840×2160, but the problem is that the button sometimes appears and sometimes disappears. Now I have it on the PC, but not on the mobile.

    #25260 quote
    Nicolas
    Keymaster
    Master

    About the stair step histogram you want to make, you only give signals when the new step is made, and then reset it to zero, that’s why you think the histogram is missing. Once you set a variable to a number, it will never go back until you give it a new value, and that’s what you made with the “else signals = 0” ..

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

Cumulating strategy does not work


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Pere @petrus Participant
Summary

This topic contains 13 replies,
has 4 voices, and was last updated by Nicolas
9 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/15/2017
Status: Active
Attachments: No files
Logo Logo
Loading...