Cumulating strategy does not work
Forums › ProRealTime English forum › ProOrder support › Cumulating strategy does not work
- This topic has 13 replies, 4 voices, and was last updated 7 years ago by Nicolas.
-
-
02/15/2017 at 12:20 PM #25139
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:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748DEFPARAM 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=50once ssMA = closeMA = average[MAperiod](close)aa=ssMA+Stepbb=ssMA-Stepif(MA>aa) THENssMA = MAELSIF (MA<bb) THENssMA = MAELSEssMA = ssMAENDIFIF ssMA>ssMA[1] THENk=1ELSIF ssMA<ssMA[1] THENk=-1ELSEk=0ENDIF// Long tradesIF k=1 THENBUY 1 CONTRACT AT MARKETENDIF// Sell long tradesIF k=-1 THENSELL AT MARKETENDIF// Short tradesIF k=-1 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Exit short tradesIF k=1 THENEXITSHORT AT MARKETENDIF// Stop lossSET STOP pLOSS sl02/15/2017 at 4:13 PM #25154Sorry, 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.
02/15/2017 at 5:16 PM #25155Hello Petrus,
maybe like this?
12345678if exit-short-condition = 1 thenexitshort at marketbuy 1 contract at marketendifif enter-long-condition = 1 thenbuy 1 contract at marketendifThe difference is “exitshort 1 contract at market” and “exitshort at market”. The second version closes all short position at the same time.
02/15/2017 at 5:25 PM #2516002/15/2017 at 5:44 PM #25169@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.1 user thanked author for this post.
02/15/2017 at 6:15 PM #25179Hi 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?
02/15/2017 at 7:02 PM #25192Hi 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.
02/16/2017 at 8:24 AM #25242Hi 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?
1 user thanked author for this post.
02/16/2017 at 9:26 AM #25252Hi,
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.
02/16/2017 at 9:31 AM #2525402/16/2017 at 9:31 AM #2525502/16/2017 at 9:33 AM #2525602/16/2017 at 9:39 AM #2525902/16/2017 at 10:16 AM #25260About 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” ..
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on