Dear all, I have tested all kind of coding regarding the ATR stop and ATR limit without success. I have follwoed earlier forum discussions but it wont work. I show my code and would appreciate if someone could comment!
This is for backtesting;
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
cond1 = X
cond2 = X
longconditions = cond1 and cond2
//Entry level
entrylevel = Close - 0.5*AverageTrueRange[10](close)
IF NOT LongOnMarket AND longConditions THEN
BUY 60000 cash AT entrylevel limit
ENDIF
//Reset Target / stop
IF NOT ONMARKET THEN
atrstop= 0
atrtarget= 0
endif
// ATR Stops and targets
IF LONGONMARKET THEN
atrstop = atrlimit - (5* AverageTrueRange[10](CLOSE)) (ALSO Tested without +/- and atrlimit)
atrtarget = atrlimit +(2* AverageTrueRange[10](CLOSE))
Endif
// STOP AND TARGET
SET STOP LOSS atrstop
SET TARGET PROFIT atrtarget
Best regards
Johan
>> For clarity of messages on ProRealCode’s forums, please use the “insert code PRT” button to separate the text of the code part! Thank you! <<
Hi,
Unless I’ve read too fast, first thing that comes to mind is: your atrlimit is not defined, so your atrstop in line 18 is probably either not defined, or if atrlimit=0 your atrstop is either negative or equal to zero (when you test without the -(5*…)), in any case it wouldn’t work without a positive value for the stop amount “atrstop”
Best way to find out what happens when debugging personal code is to use the “graph” command at the end of your backtest code. It will open an extra window displaying all values asked by a “graph” line (up to 5 values at the same time last time I checked). For example:
graph atrstop as "my atr stop"
Hi
Nothing comes up when I write the graph command.
By “nothing”, do you mean there ‘s no graph window opened when adding any graph line at the end of your backtest code? Or do you mean there is a graph window, but you don’t see an atrstop line in the window?
Sorry, yes no window comes up
It didn’t work, but I solved my coding. Thanks anyway
Hi,
Would you be willing to share your fixed code?
Thanks
Rob