EA using ATR, current ATR stops reading/crashes???

 

Hi

I have an EA that uses iATR it seems that on current bars sometimes the EA seems to just stop reading ATR and the ATR value just freezes.

For example see the attached image:

Now the ATR indicator shows 0.0019 which is correct, the EA shows 0.0017, when the current bar closes, this value corrects itself but then it is a bit late :(

I have tried using iCustom but the same issue is there current I use this:

double Atr(int shift){
     double res;
      int theAtrPeriod;
   if(Period() == PERIOD_M1)
      theAtrPeriod = AtrPeriod;
   else
      theAtrPeriod = AtrPeriod2;
     
      res = iATR(Symbol(),Period(),theAtrPeriod,shift);  
 
    return(NormalizeDouble(res,Digits));
  }

Has anyone come accross this before? My EA is quite complex, it follows a very specific pattern that I have manually traded for a good while now.

Thanks

Antony

 

Hi

I posted a video of this, to see what is happening i recommend using the 720 resolution on the site:

https://www.youtube.com/watch?v=oRI1f1F_Tck

Thanks

Antony

 

I have come across things like this before (with MT4). I have usually found that the discrepancies were the result of invalid assumptions (yes, even mine).

For example, is the comment really showing the ATR for the same number of bars, and for the same bars? Was it refreshed at the same time as the lower indicator?

It looks like it's possible that the upper number is the lower number delayed one bar. maybe change the indicator digits displayed to Digits+4 (or similar) to check

 

Hi

Thanks for the reply, I just tried that idea, (Digits+4) the value from the EA still freezes at the same point :(

Your theory is possible but would only apply to the point where the EA is checking of the current candle, as my pattern using 3 candles, the ATR of the first candles is checked after the candles have closed and then the final candle, the ATR is being checked when the candle is still open (trending).

This is the sort of code I use for the current candel, it compares the current candle ATR with the previous:

 if(Atr(0)<=Atr(1)){comm = comm + "<<===This condition is not satisfied";Comment(comm);Print(comm);return(0);}

As you can see I am looking for a high ATR value on the current candle then the previous.

Thank you

Antony

 

But then again in the comment area I am using this which returns the correct value (most of the time lol)

 comm=comm+"\nCurrent Atr: "+(Atr(0))+" ";
     comm=comm+"\nPrevious Atr: "+(Atr(0+1))+" ";
 

Hi

Thanks guy but I solved it, I re-arranged the order of the functions, I didn't know that was so important?

Thanks

Antony

 
tonyjms2005:
Thanks guy but I solved it, I re-arranged the order of the functions, I didn't know that was so important?

The order of functions are irreverent. Global variables used in the functions must be declared before use or it won't compile.

 

I have found that setting a buffer value and then reading it straight away 'does strange things'

I set buffers in one bar-history-loop, and use the value in a following loop