Help with Calculating Number of Bars between Two EMA Crossover point and Ask Price touching the Slow EMA.

 

Dear

Good day

I am learning to code EA for two timeframe EMA trading strategy. I need to count/calculate the number of bars from when FAST EMA crosses SLOW EMA  and when the Ask Prices retraces back and touches on or below SLOW EMA. I need to record this number as well as be able to get the Highest price between these two point. But I need to continue counting the bars until when the trend reverses.

Anyone who can help how to accomplish this please.

Regards

Comparative Analysis of 10 Trend Strategies
Comparative Analysis of 10 Trend Strategies
  • www.mql5.com
The article provides a brief overview of ten trend following strategies, as well as their testing results and comparative analysis. Based on the obtained results, we draw a general conclusion about the appropriateness, advantages and disadvantages of trend following trading.
 
The problem is well stated and it is a major one. What about you have already done as a code
 
ArraySetAsSeries(time, true);

datetime currentTime = TimeCurrent();
datetime barOpenTime = time[0];

static int count;

// make a bool variable called "crossover" turn true when you find the crossover

if(crossover && (currentTime - barOpenTime == PeriodSeconds())){

        count += 1; //continues to count new bars after the crossover
}
 
Niyoshaka Stanley Lameck:

To be honest, it’s not very clear what you are talking about. Take a screenshot and mark on it the bars whose number you want to count.

That is, this is basically understandable:

Niyoshaka Stanley Lameck:
from when FAST EMA crosses SLOW EMA

But the following is not clear:

Niyoshaka Stanley Lameck:
when the Ask Prices retraces back and touches on or below SLOW EMA
 
Conor Mcnamara #:

Thanks Conor, much appreciated. Will adopt your suggestion 

 
Conor Mcnamara #:
ArraySetAsSeries(time, true); datetime currentTime = TimeCurrent(); datetime barOpenTime = time[0];

I have tried this but getting an error "array required". am I skipping/missing something?

Still can't get it working

 

Also, trying to retrieve EMA cross over time. When I run the tester on historical data, i get a message saying "Wrong datetime" Where am I getting it wrong?

Please assist

 
hello, i purchased a robot and i am failing to upload it in to my experts advisors folder in my trading app. please i need help.