Histogram Not Drawing properly

 

Hello Friends


Please Help me check while the Histogram isn't drawing properly. I'm trying to convert from mql4 to mql5.

I'm getting correct buffer values but the drawings are not correct


#property copyright ""
#property link      ""
#property version   "1.00"
#property strict
#property indicator_chart_window

#property indicator_buffers 10
#property indicator_plots 10
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
#property indicator_color3 Yellow
#property indicator_color4 Yellow
#property indicator_color5 White
#property indicator_color6 White
#property indicator_color7 Red
#property indicator_color8 DodgerBlue

#property indicator_color9 DodgerBlue  // arrup[]
#property indicator_width9 1
#property indicator_color10 Red         // arrdwn[]
#property indicator_width10 1

//+------------------------------------------------------------------+
//|                        Global Variables                          |
//+------------------------------------------------------------------+
string unused_string;
double unused_double = 1.1;

input string Label1 = "=== Bar Width setting ===";
input int Bar_Width = 3;
input string Label2 = "=== Color settings ===";
input color Bull_Long_Color = DodgerBlue;
input color Bear_Short_Color = Red;
input color ROAD_Color = Yellow;

input bool   alertsOn         = false;
input bool   alertsMessage    = true;
input bool   PushNotifications= false; // Push Notifications
input bool   alertsSound      = true;
input bool   alertsEmail      = false;

double param_1 = 3.0;
double param_2 = 4.75;
double param_3 = 3.75;

double buffer_BullLong[];
double buffer_BearShort[];
double buffer_RoadHigh[];
double buffer_RoadLow[];
double buffer_Temp1[];
double buffer_Temp2[];
double buffer_HAOpen[];
double buffer_HAClose[];
double buffer_ArrowUp[];
double buffer_ArrowDown[];

double ma_low[], ma_high[], ATR[];
int    maHigh, maLow, atrHandle;

//+------------------------------------------------------------------+
//|                            Init                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
//SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 1, Bull_Long_Color);
//SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 1, Bear_Short_Color);
//SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 1, ROAD_Color);
//SetIndexStyle(3, DRAW_LINE, STYLE_SOLID, 1, ROAD_Color);
//SetIndexStyle(4, DRAW_HISTOGRAM, STYLE_SOLID, 1);
//SetIndexStyle(5, DRAW_HISTOGRAM, STYLE_SOLID, 1);
//SetIndexStyle(6, DRAW_HISTOGRAM, STYLE_SOLID, Bar_Width, Bear_Short_Color);
//SetIndexStyle(7, DRAW_HISTOGRAM, STYLE_SOLID, Bar_Width, Bull_Long_Color);

   SetIndexBuffer(0, buffer_BullLong, INDICATOR_DATA);
   PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_NONE);
   PlotIndexSetInteger(0, PLOT_LINE_COLOR, Bull_Long_Color);
   PlotIndexSetInteger(0, PLOT_LINE_STYLE, STYLE_SOLID);
   PlotIndexSetInteger(0, PLOT_LINE_WIDTH, 1);

   SetIndexBuffer(1, buffer_BearShort, INDICATOR_DATA);
   PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_NONE);
   PlotIndexSetInteger(1, PLOT_LINE_COLOR, Bear_Short_Color);
   PlotIndexSetInteger(1, PLOT_LINE_STYLE, STYLE_SOLID);
   PlotIndexSetInteger(1, PLOT_LINE_WIDTH, 1);

   SetIndexBuffer(2, buffer_RoadLow, INDICATOR_DATA);
   PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(2, PLOT_LINE_COLOR, ROAD_Color);
   PlotIndexSetInteger(2, PLOT_LINE_STYLE, STYLE_SOLID);
   PlotIndexSetInteger(2, PLOT_LINE_WIDTH, 1);

   SetIndexBuffer(3, buffer_RoadHigh, INDICATOR_DATA);
   PlotIndexSetInteger(3, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(3, PLOT_LINE_COLOR, ROAD_Color);
   PlotIndexSetInteger(3, PLOT_LINE_STYLE, STYLE_SOLID);
   PlotIndexSetInteger(3, PLOT_LINE_WIDTH, 1);

   SetIndexBuffer(4, buffer_Temp1, INDICATOR_DATA);
   PlotIndexSetInteger(4, PLOT_DRAW_TYPE, DRAW_NONE);
   PlotIndexSetInteger(4, PLOT_LINE_STYLE, STYLE_SOLID);
   PlotIndexSetInteger(4, PLOT_LINE_WIDTH, 1);
//PlotIndexSetInteger(4, PLOT_COLOR_INDEXES, Bull_Long_Color);

   SetIndexBuffer(5, buffer_Temp2, INDICATOR_DATA);
   PlotIndexSetInteger(5, PLOT_DRAW_TYPE, DRAW_NONE);
   PlotIndexSetInteger(5, PLOT_LINE_STYLE, STYLE_SOLID);
   PlotIndexSetInteger(5, PLOT_LINE_WIDTH, 1);
//PlotIndexSetInteger(5, PLOT_COLOR_INDEXES, Bull_Long_Color);

   SetIndexBuffer(6, buffer_HAOpen, INDICATOR_DATA);
   PlotIndexSetInteger(6, PLOT_DRAW_TYPE, DRAW_NONE);
   PlotIndexSetInteger(6, PLOT_LINE_COLOR, Bear_Short_Color);
   PlotIndexSetInteger(6, PLOT_LINE_WIDTH, Bar_Width);

   SetIndexBuffer(7, buffer_HAClose, INDICATOR_DATA);
   PlotIndexSetInteger(7, PLOT_DRAW_TYPE, DRAW_HISTOGRAM);
   PlotIndexSetInteger(7, PLOT_LINE_COLOR, Bull_Long_Color);
   PlotIndexSetInteger(7, PLOT_LINE_WIDTH, Bar_Width);

   SetIndexBuffer(8, buffer_ArrowUp, INDICATOR_DATA);
   PlotIndexSetInteger(8, PLOT_DRAW_TYPE, DRAW_ARROW);
   PlotIndexSetInteger(8, PLOT_ARROW, 117);

   SetIndexBuffer(9, buffer_ArrowDown, INDICATOR_DATA);
   PlotIndexSetInteger(9, PLOT_DRAW_TYPE, DRAW_ARROW);
   PlotIndexSetInteger(9, PLOT_ARROW, 117);

   string indicator_short_name = "DHA";
   IndicatorSetString(INDICATOR_SHORTNAME, indicator_short_name);

   PlotIndexSetString(0, PLOT_LABEL, NULL);
   PlotIndexSetString(1, PLOT_LABEL, NULL);
   PlotIndexSetString(2, PLOT_LABEL, "ROAD High");
   PlotIndexSetString(3, PLOT_LABEL, "ROAD Low");
   PlotIndexSetString(4, PLOT_LABEL, NULL);
   PlotIndexSetString(5, PLOT_LABEL, NULL);
   PlotIndexSetString(6, PLOT_LABEL, "HA_Open");
   PlotIndexSetString(7, PLOT_LABEL, "HA_Close");
   PlotIndexSetString(8, PLOT_LABEL, "Diamond Up");
   PlotIndexSetString(9, PLOT_LABEL, "Diamond Down");

   PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 10);
   PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, 10);
   PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, 10);
   PlotIndexSetInteger(3, PLOT_DRAW_BEGIN, 10);
   PlotIndexSetInteger(4, PLOT_DRAW_BEGIN, 10);
   PlotIndexSetInteger(5, PLOT_DRAW_BEGIN, 10);
   PlotIndexSetInteger(6, PLOT_DRAW_BEGIN, 10);
   PlotIndexSetInteger(7, PLOT_DRAW_BEGIN, 10);

   maHigh = iMA(Symbol(), PERIOD_CURRENT, 9, 1, MODE_SMA, PRICE_HIGH);
   maLow  = iMA(Symbol(), PERIOD_CURRENT, 9, 1, MODE_SMA, PRICE_LOW);
   atrHandle = iATR(Symbol(),0,100);



   return 0;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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[])
  {

   ArraySetAsSeries(time, true);
   ArraySetAsSeries(open, true);
   ArraySetAsSeries(high, true);
   ArraySetAsSeries(low, true);
   ArraySetAsSeries(close, true);
   ArraySetAsSeries(buffer_BullLong, true);
   ArraySetAsSeries(buffer_BearShort, true);
   ArraySetAsSeries(buffer_RoadHigh, true);
   ArraySetAsSeries(buffer_RoadLow, true);
   ArraySetAsSeries(buffer_Temp1, true);
   ArraySetAsSeries(buffer_Temp2, true);
   ArraySetAsSeries(buffer_HAOpen, true);
   ArraySetAsSeries(buffer_HAClose, true);
   ArraySetAsSeries(buffer_ArrowUp, true);
   ArraySetAsSeries(buffer_ArrowDown, true);
   ArraySetAsSeries(ma_high, true);
   ArraySetAsSeries(ma_low, true);
   ArraySetAsSeries(ATR, true);
   
   if(CopyBuffer(maHigh, 0, 0, rates_total, ma_high) < rates_total-1)
      return 0;
   if(CopyBuffer(maLow, 0, 0, rates_total, ma_low) < rates_total-1)
      return 0;
   if(CopyBuffer(atrHandle, 0, 0, rates_total, ATR) < rates_total-1)
      return 0;
      
   
   
   
   start(rates_total, prev_calculated, ma_high, ma_low, ATR, 0, time, open, high, low, close);

//  }

   return(rates_total);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start(int rates_total,
          int prev_calculated,
          const double &MaHigh[],
          const double &MaLow[],
          const double &Atr[],
          int shift,
          const datetime &Time[],
          const double &Open[],
          const double &High[],
          const double &Low[],
          const double &Close[])
  {
   double atr;
   double ha_open_temp;
   double ha_close_temp;

   int counted_bars = IndicatorCountedMQL4(prev_calculated);
   if(counted_bars == 0)
      counted_bars = 10;

   int bars_to_process = rates_total - counted_bars - 1;

   for(int i = bars_to_process; i >= 0; i--)
     {
      buffer_BullLong[i] = EMPTY_VALUE;
      buffer_BearShort[i] = EMPTY_VALUE;
      buffer_RoadHigh[i] = EMPTY_VALUE;
      buffer_RoadLow[i] = EMPTY_VALUE;
      buffer_Temp1[i] = EMPTY_VALUE;
      buffer_Temp2[i] = EMPTY_VALUE;

      buffer_RoadHigh[i] = (MaHigh[i] - MaLow[i]) / param_2 + MaLow[i];
      buffer_RoadLow[i]  = param_1 * (MaHigh[i] - MaLow[i]) / param_3 + MaLow[i];

      // Determine whether to plot Bull or Bear colors based on Close price
      if(Close[i] > buffer_RoadLow[i])
        {
         buffer_BullLong[i] = High[i];
         buffer_BearShort[i] = Low[i];
        }
      else  if(Close[i] < buffer_RoadHigh[i])
        {
         buffer_BearShort[i] = High[i];
         buffer_BullLong[i] = Low[i];
        }
      else if(Close[i] < buffer_RoadLow[i] && Close[i] > buffer_RoadHigh[i])
        {
         buffer_Temp1[i] = High[i];
         buffer_Temp2[i] = Low[i];
        }
     }
     
   for(int i=0;i<10;i++)
     {
      Print(i, ", ", buffer_HAClose[i]);
     }

   if(rates_total <= 10)
      return 0;

   if(counted_bars < 0)
      return -1;

   if(counted_bars > 0)
      counted_bars--;

   for(int i = rates_total - counted_bars - 1; i >= 0; i--)
     {
      buffer_HAOpen[i] = EMPTY_VALUE;
      buffer_HAClose[i] = EMPTY_VALUE;
      buffer_ArrowUp[i] = EMPTY_VALUE;
      buffer_ArrowDown[i] = EMPTY_VALUE;
      
      atr=Atr[i]/2;

      ha_close_temp = NormalizeDouble((Open[i] + High[i] + Low[i] + Close[i]) / 4.0, Digits());
      ha_close_temp = (ha_close_temp + Close[i]) / 2.0;
      ha_open_temp = (buffer_HAOpen[i + 1] + buffer_HAClose[i + 1]) / 2.0;
      
      buffer_HAOpen[i] = ha_open_temp;
      buffer_HAClose[i] = ha_close_temp;
      // Print(i, ", ", buffer_HAOpen[i], ", ", buffer_HAClose[i]);
      // Show arrow when HA bar touches one of the Road lines and then closes above/below both lines
      if(i < rates_total - 1)
        {
         // Buy signal: HA candle touches one of the Road lines and closes above both lines and Previous candle closes below either one
         if(((Low[i] <= buffer_RoadHigh[i] || Low[i] <= buffer_RoadLow[i]) &&
             buffer_HAClose[i] > buffer_RoadHigh[i] && buffer_HAClose[i] > buffer_RoadLow[i]) &&
            (buffer_HAClose[i + 1] <= buffer_RoadHigh[i + 1] || buffer_HAClose[i + 1] <= buffer_RoadLow[i + 1]))
           {
            buffer_ArrowUp[i] = Low[i] - 2*atr;
            //Alert("Buy signal at bar ", i+1, " - HA Close: ", buffer_HAClose[i+1]);
           }
         // Sell signal: HA candle touches one of the Road lines and closes below both lines and previous candle closes above either one
         else
            if(((High[i] >= buffer_RoadHigh[i] || High[i] >= buffer_RoadLow[i]) &&
                buffer_HAClose[i] < buffer_RoadHigh[i] && buffer_HAClose[i] < buffer_RoadLow[i]) &&
               (buffer_HAClose[i + 1] >= buffer_RoadHigh[i + 1] || buffer_HAClose[i + 1] >= buffer_RoadLow[i + 1]))
              {
               buffer_ArrowDown[i] = High[i] + 2*atr;
              }
        }
     }
   //manageAlerts(Time[1]);
   return 0;
  }
 

This is the MQL4 version

 


This is the MQL5 version

 
It might be that you put the histogram drawing style on the wrong buffers 
 
From what I see after looking more closely...it's an indicator based on heiken ashi, and you're missing half of the heiken ashi calculation in the code!
 

sorry but this is a complicated situation - I've never seen heiken ashi code working as Series in MQL5. This is an MQL4 indicator which a complete disaster to convert. You would have to start over even with the calculations I think - unless anyone has an educated suggestion, but I don't know if there's an easy conversion method.


I've done what I could to help

#property version   "1.00"
#property strict
#property indicator_chart_window

#property indicator_buffers 13
#property indicator_plots   10

//Signal arrows
#property indicator_width1  1
#property indicator_width2  1

//Color candles [Buffer 3 - 7 (or indexes 2 - 6) are reserved by DRAW_COLOR_CANDLES]
#property indicator_type3   DRAW_COLOR_CANDLES
#property indicator_color3  clrDodgerBlue, clrRed

//Lines
#property indicator_width8  1
#property indicator_width9  1
#property indicator_width10 1
#property indicator_width11 1


string unused_string;
double unused_double = 1.1;

input string Label1 = "=== Bar Width setting ===";
input int Bar_Width = 3;
input string Label2 = "=== Color settings ===";
input color Bull_Long_Color = DodgerBlue;
input color Bear_Short_Color = Red;
input color ROAD_Color = Yellow;

input bool   alertsOn         = false;
input bool   alertsMessage    = true;
input bool   PushNotifications= false; // Push Notifications
input bool   alertsSound      = true;
input bool   alertsEmail      = false;

double param_1 = 3.0;
double param_2 = 4.75;
double param_3 = 3.75;

double buffer_BullLong[];
double buffer_BearShort[];
double buffer_RoadHigh[];
double buffer_RoadLow[];
double buffer_Temp1[];
double buffer_Temp2[];

double buffer_HAOpen[];
double buffer_HAClose[];
double buffer_HAHigh[];
double buffer_HALow[];
double ExtColorBuffer[];

double buffer_ArrowUp[];
double buffer_ArrowDown[];

double ma_low[], ma_high[], ATR[];
int    maHigh, maLow, atrHandle;

//+------------------------------------------------------------------+
//|                            Init                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   //Signal arrows
   SetIndexBuffer(0, buffer_ArrowDown, INDICATOR_DATA);
   PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_ARROW);
   PlotIndexSetInteger(0, PLOT_ARROW, 117);
   PlotIndexSetInteger(0, PLOT_LINE_COLOR, clrRed);
   
   SetIndexBuffer(1, buffer_ArrowUp, INDICATOR_DATA);
   PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_ARROW);
   PlotIndexSetInteger(1, PLOT_ARROW, 117); 
   PlotIndexSetInteger(1, PLOT_LINE_COLOR, clrDodgerBlue);
   
   //HA candles
   SetIndexBuffer(2, buffer_HAOpen, INDICATOR_DATA);
   SetIndexBuffer(3, buffer_HAClose, INDICATOR_DATA);
   SetIndexBuffer(4, buffer_HAHigh, INDICATOR_DATA);
   SetIndexBuffer(5, buffer_HALow, INDICATOR_DATA);
   SetIndexBuffer(6, ExtColorBuffer, INDICATOR_COLOR_INDEX);
     
   //Lines
   SetIndexBuffer(7, buffer_RoadLow, INDICATOR_DATA);
   SetIndexBuffer(8, buffer_RoadHigh, INDICATOR_DATA);
   SetIndexBuffer(9, buffer_BullLong, INDICATOR_DATA);
   SetIndexBuffer(10, buffer_BearShort, INDICATOR_DATA);

   PlotIndexSetInteger(7, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(7, PLOT_LINE_COLOR, ROAD_Color);
   PlotIndexSetInteger(7, PLOT_LINE_STYLE, STYLE_SOLID);
   PlotIndexSetInteger(7, PLOT_LINE_WIDTH, 1);
   
   PlotIndexSetInteger(8, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(8, PLOT_LINE_COLOR, ROAD_Color);
   PlotIndexSetInteger(8, PLOT_LINE_STYLE, STYLE_SOLID);
   PlotIndexSetInteger(8, PLOT_LINE_WIDTH, 1);
   
   PlotIndexSetInteger(9, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(9, PLOT_LINE_COLOR, Bull_Long_Color);
   PlotIndexSetInteger(9, PLOT_LINE_STYLE, STYLE_SOLID);
   PlotIndexSetInteger(9, PLOT_LINE_WIDTH, 1);

   PlotIndexSetInteger(10, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(10, PLOT_LINE_COLOR, Bear_Short_Color);
   PlotIndexSetInteger(10, PLOT_LINE_STYLE, STYLE_SOLID);
   PlotIndexSetInteger(10, PLOT_LINE_WIDTH, 1);

   SetIndexBuffer(11, ma_high, INDICATOR_CALCULATIONS);
   SetIndexBuffer(12, ma_low, INDICATOR_CALCULATIONS);
   SetIndexBuffer(13, ATR, INDICATOR_CALCULATIONS);


   string indicator_short_name = "DHA";
   IndicatorSetString(INDICATOR_SHORTNAME, indicator_short_name);
   
   PlotIndexSetString(0, PLOT_LABEL, "HA_Open");
   PlotIndexSetString(1, PLOT_LABEL, "HA_Close");
   PlotIndexSetString(2, PLOT_LABEL, "HA_High");
   PlotIndexSetString(3, PLOT_LABEL, "HA_Low");
   PlotIndexSetString(4, PLOT_LABEL, "ExtColorBuffer");
   PlotIndexSetString(5, PLOT_LABEL, "ArrowDown");
   PlotIndexSetString(6, PLOT_LABEL, "ArrowUp");
   PlotIndexSetString(7, PLOT_LABEL, "RoadLow");
   PlotIndexSetString(8, PLOT_LABEL, "RoadHigh");
   PlotIndexSetString(9, PLOT_LABEL, "BullLong");
   PlotIndexSetString(10, PLOT_LABEL, "BearShort");
   
   maHigh = iMA(Symbol(), PERIOD_CURRENT, 9, 1, MODE_SMA, PRICE_HIGH);
   maLow  = iMA(Symbol(), PERIOD_CURRENT, 9, 1, MODE_SMA, PRICE_LOW);
   atrHandle = iATR(Symbol(), 0, 100);

   return INIT_SUCCEEDED;
  }



void OnDeinit(const int reason)
  {
  }


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[])
  {
   //ArraySetAsSeries(time, true);
   //ArraySetAsSeries(open, true);
   //ArraySetAsSeries(high, true);
   //ArraySetAsSeries(low, true);
   //ArraySetAsSeries(close, true);
   //ArraySetAsSeries(buffer_HAOpen, true);
   //ArraySetAsSeries(buffer_HAClose, true);
   //ArraySetAsSeries(buffer_HAHigh, true);
   //ArraySetAsSeries(buffer_HALow, true);
   //ArraySetAsSeries(ExtColorBuffer, true);   
   //ArraySetAsSeries(buffer_BullLong, true);
   //ArraySetAsSeries(buffer_BearShort, true);
   //ArraySetAsSeries(buffer_RoadHigh, true);
   //ArraySetAsSeries(buffer_RoadLow, true);
   //ArraySetAsSeries(buffer_Temp1, true);
   //ArraySetAsSeries(buffer_Temp2, true);
   //ArraySetAsSeries(buffer_ArrowUp, true);
   //ArraySetAsSeries(buffer_ArrowDown, true);
   //ArraySetAsSeries(ma_high, true);
   //ArraySetAsSeries(ma_low, true);
   //ArraySetAsSeries(ATR, true);

   if (CopyBuffer(maHigh, 0, 0, rates_total, ma_high) == -1){ Print("Something wrong with maHigh buffer");}

   if (CopyBuffer(maLow, 0, 0, rates_total, ma_low) == -1){ Print("Something wrong with maLow buffer");}

   if (CopyBuffer(atrHandle, 0, 0, rates_total, ATR) == -1){ Print("Something wrong with ATR buffer");}

   process(rates_total, prev_calculated, ma_high, ma_low, ATR, 0, time, open, high, low, close);  

   return(rates_total);
  }


void process(const int rates_total,
           int prev_calculated,
           const double &MaHigh[],
           const double &MaLow[],
           const double &Atr[],
           int shift,
           const datetime &Time[],
           const double &Open[],
           const double &High[],
           const double &Low[],
           const double &Close[])
{
    int start;
    //--- preliminary calculations
    if (prev_calculated == 0)
    {
        buffer_HAClose[0] = Low[0];
        buffer_HAOpen[0] = High[0];
        buffer_HAHigh[0] = Open[0];
        buffer_HALow[0] = Close[0];
        start = 1;
    }
    else
    {
        start = prev_calculated - 1;
    }

    for (int i = start; i < rates_total && !IsStopped(); i++)
    {
        buffer_BullLong[i] = EMPTY_VALUE;
        buffer_BearShort[i] = EMPTY_VALUE;
        buffer_RoadHigh[i] = EMPTY_VALUE;
        buffer_RoadLow[i] = EMPTY_VALUE;

        buffer_RoadHigh[i] = (MaHigh[i] - MaLow[i]) / param_2 + MaLow[i];
        buffer_RoadLow[i]  = param_1 * (MaHigh[i] - MaLow[i]) / param_3 + MaLow[i];

        if (Close[i] > buffer_RoadLow[i])
        {
            buffer_BullLong[i] = High[i];
            buffer_BearShort[i] = Low[i];
        }
        else if (Close[i] < buffer_RoadHigh[i])
        {
            buffer_BearShort[i] = High[i];
            buffer_BullLong[i] = Low[i];
        }
    }

    for (int i = start; i < rates_total && !IsStopped(); i++)
    {
        double ha_open;
        double ha_close;
        double ha_high;
        double ha_low;

        buffer_ArrowUp[i] = EMPTY_VALUE;
        buffer_ArrowDown[i] = EMPTY_VALUE;

        ha_open = (buffer_HAOpen[i - 1] + buffer_HAClose[i - 1]) / 2.0;
        ha_close = (Open[i] + High[i] + Low[i] + Close[i]) / 4.0;
        ha_high = MathMax(High[i], MathMax(ha_open, ha_close));
        ha_low = MathMin(Low[i], MathMin(ha_open, ha_close));

        buffer_HAClose[i] = ha_close;
        buffer_HAOpen[i] = ha_open;
        buffer_HAHigh[i] = ha_high;
        buffer_HALow[i] = ha_low;

        if (ha_open < ha_close)
        {
            ExtColorBuffer[i] = 0;
        }
        else
        {
            ExtColorBuffer[i] = 1; 
        }

        double atr = ATR[i];

        if (((Low[i] <= buffer_RoadHigh[i] || Low[i] <= buffer_RoadLow[i]) &&
        
             buffer_HAClose[i] > buffer_RoadHigh[i] && buffer_HAClose[i] > buffer_RoadLow[i]) &&
             
            (buffer_HAClose[i - 1] <= buffer_RoadHigh[i - 1] || buffer_HAClose[i - 1] <= buffer_RoadLow[i - 1]))
        {
            buffer_ArrowUp[i] = Low[i] - 1 * atr;
        }
        else if (((High[i] >= buffer_RoadHigh[i] || High[i] >= buffer_RoadLow[i]) &&
        
                  buffer_HAClose[i] < buffer_RoadHigh[i] && buffer_HAClose[i] < buffer_RoadLow[i]) &&
                  
                 (buffer_HAClose[i - 1] >= buffer_RoadHigh[i - 1] || buffer_HAClose[i - 1] >= buffer_RoadLow[i - 1]))
        {
            buffer_ArrowDown[i] = High[i] + 1 * atr;
        }
        else
        {
            buffer_ArrowUp[i] = EMPTY_VALUE;
            buffer_ArrowDown[i] = EMPTY_VALUE;
        }
    }
}


Files:
 

optimizing the MA handles so the plot doesn't drop:


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 calculated_maHigh = BarsCalculated(maHigh);
    int calculated_maLow = BarsCalculated(maLow);
    int calculated_ATR = BarsCalculated(atrHandle);
    
    if (calculated_maHigh < rates_total || calculated_maLow < rates_total || calculated_ATR < rates_total) return 0;

    int to_copy;
    
    if (prev_calculated == 0 || prev_calculated < 0){
        to_copy = rates_total;
    } 
    else{
        to_copy = rates_total - prev_calculated;
        if (prev_calculated > 0) to_copy++;
    }
    
   // Retrieve new data from buffers
   if (CopyBuffer(maHigh, 0, 0, to_copy, ma_high) <= 0) { Print("Error copying maHigh"); return 0; }
   if (CopyBuffer(maLow, 0, 0, to_copy, ma_low) <= 0) { Print("Error copying maLow"); return 0; }
   if (CopyBuffer(atrHandle, 0, 0, to_copy, ATR) <= 0) { Print("Error copying ATR"); return 0; }

   process(rates_total, prev_calculated, ma_high, ma_low, ATR, 0, time, open, high, low, close);  

   return(rates_total);
  }


and a mistake has been made, please adjust it to:

#property indicator_buffers 14
#property indicator_plots   10
 
Final version with the fixes and optimization 
Files:
 
Conor Mcnamara #:
Final version with the fixes and optimization 



Thank you so much Sir

I'll test it out 

I really appreciate this