0

I need to do somthing like this

if ( iAO( Symbol(),PERIOD_M1, 0) <= iAO( Symbol(), PERIOD_M5, 0) )

{

....

}

But iAO( Symbol(), PERIOD_M5, 0) does not work when my chart timeframe is M1 (It return 0 always).

Is it possible to obtain the real returned value of this function in M1?


UPDATE

I found out that the problem is something related with the bars number at the different time frames. something like this:

int BM1 = iBars(NULL,PERIOD_M1);

where

int BM5 = BM1/5;

or

int BM5 = iBars(NULL,PERIOD_BM5);

So, if i do this it does works if i'm in timeframe M1.

int i, n=0, Counted_bars;   

Counted_bars=IndicatorCounted();  

i=Bars-Counted_bars-1;



   while(i>=0)                     

   { 

        if (  iAO( Symbol(),PERIOD_M1, i) <= iAO( Symbol(), PERIOD_M5, i/5)  )

        {

...

        }

i--;

}

But it only works when i'm programing a indicator. It does not works in a Expert Advisor. ¿Any idea?

kenorb
  • 155,785
  • 88
  • 678
  • 743
Iván Rodríguez
  • 447
  • 4
  • 10
  • mql4 or mql5? it will work in mql4, for mql5 you need to have handle, copy elements into arrays etc. – Daniel Kniaz May 09 '19 at 08:17
  • Thank you for your response. I'm writing it in MQL4. I found out that the problem is something related with the bars number at the different time frames. something like this: **int BM1 = iBars(NULL,PERIOD_M1)** where **BM5 = BM1/5** But it only works when i'm programing a indicator. It does no works in a Expert Advisor. ¿Any idea? – Iván Rodríguez May 09 '19 at 22:58
  • 1
    0 is still the current bar. if you need `i`-th bar, you may need to convert time and bars. `iBarShift` gives the index from time – Daniel Kniaz May 11 '19 at 10:09
  • It does works!! Thank you so much!! – Iván Rodríguez May 12 '19 at 00:23

0 Answers0