initial stop at 3*ATR

 

Hello,

I am trying to set initial stop at 3 times current ATR.

I want to get current ATR with: 

input double          ATRHandle                    =iATR(_Symbol,PERIOD_CURRENT,14);

and use it like this:

input double          Signal_StopLevel             =3*ATRHandle;

But I get "constant expected" mistake.

Can anyoune help?

 
Demosfen:

Hello,

I am trying to set initial stop at 3 times current ATR.

I want to get current ATR with: 

and use it like this:

But I get "constant expected" mistake.

Can anyoune help?

double atr = iATR(_Symbol,PERIOD_CURRENT,14) * 3;
 

In Mql5 you need to access the indicator values with CopyBuffer like so:

input int ATR_Period=14;
int ATR_Handle;
double ATR_Current;
double ATR_StopLevel;

int OnInit() {
  ATR_Handle=iATR(_Symbol,PERIOD_CURRENT,ATR_Period);
  if(ATR_Handle==INVALID_HANDLE) { Print("error creating iATR handle: ",GetLastError()); return INIT_FAILED; }
  return INIT_SUCCEEDED;
}

void OnTick() {
  static double s_buffer[1];
  int amount=1;
  int shift=0;
  if(CopyBuffer(ATR_Handle,MAIN_LINE,shift,amount,s_buffer)!=amount) { Print("error copying indicator buffer: ",GetLastError()); ExpertRemove(); return; }
  ATR_Current=s_buffer[0];
  ATR_StopLevel=3.0*ATR_Current;
  ...
}
 
lippmaje:

In Mql5 you need to access the indicator values with CopyBuffer like so:

It works, thanks a lot!