how to set target and stop for backtesting?
Forums › ProRealTime English forum › ProOrder support › how to set target and stop for backtesting?
- This topic has 12 replies, 3 voices, and was last updated 6 years ago by
Malend.
-
-
09/05/2019 at 10:33 AM #106570
Hello,
I try to backtest a strategy in a tickchart. Everytime the a bullish candle crosses the bullish sma50 with the opening below the sma 50 and the close above the sma20, or a bearish candle crosses the bearish sma5o with the opening above the sma 50 and the close below the sma20, I want to buy 1 contract with a target from 5 and a stoploss from 2
This is what I have created, but I see in the output of the backtest that something isn’t right. I see profits and losses far above my presets.
Thank you, Marc123456789101112131415161718192021222324252627282930313233343536// moving averagesm50 = Average[50]//LONG - crossing bullish candle through bullish sma50 from below.// The body of the previous candle needs to be below the sma50c1 = open[1] < m50 and close[1] < m50c2 = open < m50 and close > m50// bullish sma50c3 = m50[1] =< m50// Long conditionsL = c1 and c2 and c3//SHORT - crossing bearish candle through bearish sma50 from above.// The body of the previous candle needs to be above the sma50c4 = open[1] > m50 and close[1] > m50c5 = open > m50 and close < m50//bearish sma50c6 = m50[1] => m50// Short conditionsS = c4 and c5 and c6// Buy LongIF L THENBUY 1 CONTRACTS AT MARKETENDIF// Sell ShortIF S THENSELLSHORT 1 CONTRACTS AT MARKETENDIF// Stops en TargetsSET STOP loss 2SET TARGET PROFIT 509/05/2019 at 10:38 AM #106571Please use the ProOrder forum for automated trading related question, and the ‘insert code button’ to add a embed a code in a post.
If you want to use takeprofit and stoploss values in points, you should use the pprofit and ploss instruction instead:
123// Stops en TargetsSET STOP ploss 2 //2 points/pipsSET TARGET pPROFIT 5 //5 points/pips09/05/2019 at 10:51 AM #10657609/05/2019 at 11:09 AM #106579Hi again, I still have strange losses and profits in my backtest list. If 1 point = $50,- then the max of my loss will be constantly $100,- and my profits will be always $250,-
Now I have variable profits and losses.I want to check how often the strategy as described above reaches the target or the stop.
So I guess there is something else I didn’t do right.
Thanks, Marc
09/05/2019 at 11:28 AM #10658609/05/2019 at 11:29 AM #10659009/05/2019 at 11:31 AM #106591So I guess there is something else I didn’t do right.
Try below as the 1st line of code
1DEFPARAM CUMULATEORDERS = False09/05/2019 at 12:12 PM #106599Thanks Graham,
Makes definitely sense.
I also see some bugs in my strategy definitions and what happens when I am in a buy postion and a sell signal shows up.Work for me to do. Great.
Thanks a lot, again. Marc
1 user thanked author for this post.
09/05/2019 at 12:17 PM #10660009/05/2019 at 9:12 PM #10664909/05/2019 at 9:16 PM #106650The only thing I would like to have is that when I am in an a position that the TA or the SL stops that position, and not a start from a new postion the other direction. It can open a new position, but better for me would be to have only one psotion open.
09/05/2019 at 9:43 PM #106656but better for me would be to have only one psotion open.
Which version / code are you referring to … your original code, my version or some new version of yours?
Always best to post the code then others may spot the reason for your Issue.
Also if you have optimised a lot of variables then it is very useful to post the .itf with the optimiser already set up with variable names, range and steps … as I did in the .itf I posted above to help you. Makes it easier / quicker for folks to help and improve further.
Cheers
1 user thanked author for this post.
09/06/2019 at 8:26 AM #106677 -
AuthorPosts
Find exclusive trading pro-tools on