how calculate a price with ATR ?

 

Hi guys  how  calcolate a stop loss with ATR ? anyone  have some example ?

i find but not have a good  example

i tryed

   double atrSL = 2.0;  
SL = NormalizeDouble(OpenPrice - (ATR_Value * atrSL), Digits());

but not return me  a price correct

 

Simply get the ATR value and add to your entry price, your example should be correct, as long as your OpenPrice and ATR_Value are correct.

Then you should normalize the price to tick size, instead of Digits, but this is another problem.

 
Fabio Cavalloni #:

Simply get the ATR value and add to your entry price, your example should be correct, as long as your OpenPrice and ATR_Value are correct.

Then you should normalize the price to tick size, instead of Digits, but this is another problem.

i try to print a value

2025.03.27 23:15:28.587 TradeManager (EURUSD,M15)       ATR_Value: 10.0
2025.03.27 23:15:28.587 TradeManager (EURUSD,M15)       Point(): 2.0
2025.03.27 23:15:28.587 TradeManager (EURUSD,M15)       OpenPrice EURUSD
2025.03.27 23:15:28.587 TradeManager (EURUSD,M15)       Calculated SL: 21.07903
2025.03.27 23:15:28.587 TradeManager (EURUSD,M15)       OpenPrice 1.07903

why return me 21.07903 , but calc [rpbably is not correct  anypne  have a right  calc ?

 
Stefano Cerbioni #:

i try to print a value

why return me 21.07903 , but calc [rpbably is not correct  anypne  have a right  calc ?

your ATR_Value should be a 0.XXX not a whole number.

Show your calculation method to get ATR_Value

 

I used to to this

int OnInit()
  {

   atr_handle = iATR(Symbol(), 0, atr_period);

   ArraySetAsSeries(atr_buf, true);

   return(INIT_SUCCEEDED);
  }


void OnTick()
 {

   if(CopyBuffer(atr_handle, 0, 0, 1, atr_buf) < 0)
     {
      Print("UNABLE TO GET REQUESTED DATA FOR ATR. REVERTING.");
     } 

     double stopLossATR = atr_buf[0] * atr_stop_multiplier;

     double buy_stopLoss_atr = (ask - stopLossATR) - SL * _Point;
     double sell_stopLoss_atr = (bid + stopLossATR) + SL * _Point;
 }

there are also dedicated trend following indicators based on ATR stop as to which you can use for a trailing atr stop loss