mql5

MQL5 Convert OnCalculate to OnTick


I am trying to convert an indicator to EA.

The Indicator have the following parameters and I like to spin it into EA.

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &Time[],
                const double &open[],
                const double &High[],
                const double &Low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])

Can someone help me what is the equal of rates_total, prev_calculated?


Solution

  • Inside an EA those values don't exist. They are internal variables for Metatrader to track how many bars have been calculated on the chart in the indicator program environment.

    For an EA you need to re-create this logic and track the bars on the chart yourself.

    rates_total = How may bars are available on the chart. prev_calculated = How many bars have you calculated with your program.

    For the rest of the data you can get from MqlRates structure

    https://www.mql5.com/en/docs/constants/structures/mqlrates https://www.mql5.com/en/docs/series/copyrates