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:
HAshi_Advanced2.mq5
11 kb
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

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
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