I need help!!Regarding the issue with the indicator line drawing.

 
//+------------------------------------------------------------------+
//|                                                          ATR.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Average True Range with EMA Channel"
#property strict

//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1  White
#property indicator_color2  White
#property indicator_color3  Yellow // Color for EMA line
//--- input parameter
input int InpAtrPeriod = 35; // ATR Period
input int InpEmaPeriod = 35; // EMA Period
//--- buffers
double ExtATRBuffer[];
double ExtTRBuffer[];
double ATRC1[];
double ATRC2[];
double EMA[];

extern bool CalculateOnBarClose = true; // Flag to control if calculation is done on new bar only
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
    string short_name;
    //--- indicator buffers mapping
    IndicatorBuffers(5); // Total 5 buffers used
    IndicatorDigits(Digits);
    //--- indicator lines
    SetIndexBuffer(0, ATRC1);
    SetIndexStyle(0, DRAW_LINE);
    SetIndexBuffer(1, ATRC2);
    SetIndexStyle(1, DRAW_LINE);
    SetIndexBuffer(2, EMA);
    SetIndexStyle(2, DRAW_LINE);
    SetIndexBuffer(3, ExtATRBuffer);
    SetIndexStyle(3, DRAW_NONE); // No drawing
    SetIndexBuffer(4, ExtTRBuffer);
    SetIndexStyle(4, DRAW_NONE); // No drawing
    //--- name for DataWindow and indicator subwindow label
    short_name = "ATR Channel with EMA";
    IndicatorShortName(short_name);
    SetIndexLabel(0, short_name + " (Upper)");
    SetIndexLabel(1, short_name + " (Lower)");
    SetIndexLabel(2, "EMA");
    //--- check for input parameter
    if (InpAtrPeriod <= 0 || InpEmaPeriod <= 0)
    {
        Print("Wrong input parameter ATR Period or EMA Period");
        return (INIT_FAILED);
    }
    //---
    SetIndexDrawBegin(0, InpAtrPeriod);
    SetIndexDrawBegin(1, InpAtrPeriod);
    SetIndexDrawBegin(2, InpEmaPeriod);
    //---
    return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Average True Range and EMA Channel calculation                   |
//+------------------------------------------------------------------+
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[])
{
    int i, limit;
      
    //--- check for bars count and input parameter
    if (rates_total <= InpAtrPeriod || InpAtrPeriod <= 0 || InpEmaPeriod <= 0)
        return (0);
    //--- counting from 0 to rates_total
    ArraySetAsSeries(ExtATRBuffer, true);
    ArraySetAsSeries(ExtTRBuffer, true);
    ArraySetAsSeries(ATRC1, true);
    ArraySetAsSeries(ATRC2, true);
    ArraySetAsSeries(EMA, true);
    ArraySetAsSeries(open, true);
    ArraySetAsSeries(high, true);
    ArraySetAsSeries(low, true);
    ArraySetAsSeries(close, true);
    //--- preliminary calculations
   
    if (prev_calculated == 0)
    {
        ExtTRBuffer[0] = 0.0;
        ExtATRBuffer[0] = 0.0;
        //--- filling out the array of True Range values for each period
        for (i = 1; i < rates_total; i++)
            ExtTRBuffer[i] = MathMax(high[i], close[i - 1]) - MathMin(low[i], close[i - 1]);
        //--- first AtrPeriod values of the indicator are not calculated
        double firstValue = 0.0;
        for (i = 1; i <= InpAtrPeriod; i++)
        {
            ExtATRBuffer[i] = 0.0;
            firstValue += ExtTRBuffer[i];
        }
        //--- calculating the first value of the indicator
        firstValue /= InpAtrPeriod;
        ExtATRBuffer[InpAtrPeriod] = firstValue;
        limit = InpAtrPeriod + 1;
    }
    else
        limit = prev_calculated - 1;

    //--- the main loop of calculations for ATR
    for (i = limit; i < rates_total; i++)
    {
        ExtTRBuffer[i] = MathMax(high[i], close[i - 1]) - MathMin(low[i], close[i - 1]);
        ExtATRBuffer[i] = (ExtATRBuffer[i - 1] * (InpAtrPeriod - 1) + ExtTRBuffer[i]) / InpAtrPeriod; // SMMA
    }
    
    //--- calculate EMA
    for (i = limit; i < rates_total; i++)
    {
        EMA[i] = iMA(NULL, 0, InpEmaPeriod, 0, MODE_EMA, PRICE_CLOSE, i);
    }

    //--- calculate ATR channels using EMA and ATR values
    for (i = limit; i < rates_total; i++)
    {
        ATRC1[i] = EMA[i] + 0.5 * ExtATRBuffer[i];
        ATRC2[i] = EMA[i] - 0.5 * ExtATRBuffer[i];
    }

    //--- return value of prev_calculated for next call
    return (rates_total);
}
//+------------------------------------------------------------------+

This is MT4 code. As a beginner in programming, I've encountered some challenges. While testing this code, I noticed that the latter part of the lines isn't being drawn. I would be incredibly grateful if any of you skilled programmers could help me resolve this issue.

 
  1. Why did you post your MT4 question in the MT5 Indicators section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. I have moved this thread.


  2.         limit = prev_calculated - 1;
    
        //--- the main loop of calculations for ATR
        for (i = limit; i < rates_total; i++)
    

    Your buffers and arrays are set as-series. Yet, your loop is running non-series (towards oldest bars).
              How to do your lookbacks correctly #9#14 & #19 (2016)

 
William Roeder #:
  1. Why did you post your MT4 question in the MT5 Indicators section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. I have moved this thread.


  2. Your buffers and arrays are set as-series. Yet, your loop is running non-series (towards oldest bars).
              How to do your lookbacks correctly #9#14 & #19 (2016)

Sorry sir, it's my first time to use the forum, I will pay attention, thank you for you reply.