Adapting TakeProfit & StopLoss to Changing Volatility

 

Hello,

i want to ask how you change your Sl & TP settings in a backtest over a longer time? I mean I personally cant always use RR for TP and SL (and because it makes the backtest very slow) because of the SL.

I tried it with this code:

//ATR
double atr_Ref = iATR(Symbol(),PERIOD_D1,ATR,(round(((TimeCurrent()-Starttest)/60/_Period)*6/7)));       
double atr = iATR(Symbol(),PERIOD_D1,ATR,1);
double atr_Change = atr/atr_Ref;


But there is a a zero divide because of this part; when i use comment it shows the right integer, but it doesnt work here...  What is the fault and other question: Does anybody have a better solution for changing TP,.. if Volatility changes?

(round(((TimeCurrent()-Starttest)/60/_Period)*6/7))


Greeting
 

1) round(..) gets bigger and bigger and so the shift var in iATR(...,round()).

2) after some time you'll get beyond the starttest and the iATR will be zero and that causes the zero-devide 2 lines later - I guess.

 

the integer is just growing with the time. Its just the plan to count 1,2,3,.. with every day. I think its more problem with the format, isnt it? I dont understand your answer right now.

Ebery other idea that works in backtest? i tried it for a year with DayOfYear() and the backtest was worse than before without it. But isnt it necessary for a good EA because of the changing(for example middle 2014 very low, now higher)?

 

1) But mt4 count 'backwards'! Bar[0] is the most recent bar: Daily-Charts: Time[0] is always today's open time, Time[1] is always yesterday's open time (normally).

2) I guess you have checked: (..)/60/_Period: Is it  ((..)/60)/_Period   or   (..)/(60/_Period)?

 
I think its just the Problem with the shift why i ask, but now in the afternoon i have woken up i think why i dont use the daily ATR as a Multiplier, why complicated..
Reason: