lmrf:
Hi.
I am very new to MQL4, so I don't have much experience programing with this language. I am used to Metastock EA language, wich is far different from MQL4. So I would like to know if there is a way to express a function similar to Metastock function "BarsSince(EventXX)". In other words, I need a code to tell if an Event XX ocurred at least 2 bars ago.
Best regards.
Use iBarShift().
If you know the datetime of the event, iBarShift.
Otherwise loop through the bars to determine when. For example MA crossover:
for (int shift=0; shift < Bars; shift++){ double fast.now = iMA(NULL,0,18, 0, MODE_EMA, PRICE_TYPICAL, shift+0), slow.now = iMA(NULL,0,36, 0, MODE_EMA, PRICE_TYPICAL, shift+0), fast.prev = iMA(NULL,0,18, 0, MODE_EMA, PRICE_TYPICAL, shift+1), slow.prev = iMA(NULL,0,36, 0, MODE_EMA, PRICE_TYPICAL, shift+1); if ( (fast.now-slow.now)*(fast.prev-slow.prev) < 0 ){ break; // Moving averages crossed at Time[shift] } }
Thanks for the help. I will follow your suggestions and see what I can do.
Best regards.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi.
I am very new to MQL4, so I don't have much experience programing with this language. I am used to Metastock EA language, wich is far different from MQL4. So I would like to know if there is a way to express a function similar to Metastock function "BarsSince(EventXX)". In other words, I need a code to tell if an Event XX ocurred at least 2 bars ago.
Best regards.