hi in the above code first PlotIndexSetInteger(0,PLOT_LINE_COLOR,plot_color[0]);
change the color of the plot indicator but second
PlotIndexSetInteger(0,PLOT_LINE_COLOR,plot_color[1]);
don't affect the color
I used "Draw_Histogram" type
Why?
tks for your help
You haven't shown all the code. Your piece cannot be compiled.
Check out the example from the help: DRAW_HISTOGRAM - The example shows how to work and this example works.

- www.mql5.com
You haven't shown all the code. Your piece cannot be compiled.
Check out the example from the help: DRAW_HISTOGRAM - The example shows how to work and this example works.
//+------------------------------------------------------------------+ //| asadi_MA_Histogram.mq5 | //| Copyright 2021, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property indicator_separate_window #property indicator_buffers 2 #property indicator_plots 2 //--- plot Histogram #property indicator_label1 "Histogram" #property indicator_type1 DRAW_HISTOGRAM //#property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot NONE #property indicator_type2 DRAW_NONE //--- input variables input int PeriodMA = 7; // Period MA input int MA_Period = 21;// Moving average period input ENUM_MA_METHOD MethodMA = MODE_SMMA; input ENUM_APPLIED_PRICE AppliedToMA = PRICE_MEDIAN; //--- indicator buffers double Histogram_Buffer[]; double Temp_Buffer[]; //--- MA Handle int MA_Handle; //--- Color color colors[]={clrRed,clrBlue,clrGreen}; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Histogram_Buffer,INDICATOR_DATA); SetIndexBuffer(1,Temp_Buffer,INDICATOR_DATA); //--- Number of initial bars without drawing and values in the DataWindow PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,(2*PeriodMA)); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,(2*PeriodMA)); //--- Set digits IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //--- iMA MA_Handle = iMA(_Symbol,_Period,MA_Period,0,MethodMA,AppliedToMA); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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[]) { //--- check bars if(rates_total <= PeriodMA) return(0); //---Reverse Array indexing ArraySetAsSeries(Histogram_Buffer,true); ArraySetAsSeries(Temp_Buffer,true); //--- Array for local use here double Ave_MA_Local[]; ArraySetAsSeries(Ave_MA_Local,true); int limit = rates_total - prev_calculated; if(limit == 0) limit = 1; if(prev_calculated == 0) limit = limit - PeriodMA; //--- loop over bars to draw histogram for(int i=limit; i>=0; i--) { //--- calculate sum double sum = 0.0; CopyBuffer(MA_Handle,0,i,PeriodMA,Ave_MA_Local); for(int j=0; j<PeriodMA; j++) sum = sum + Ave_MA_Local[j]; //--- fill buffer to draw histogram Temp_Buffer[i] = sum / PeriodMA; double temp1 = Temp_Buffer[i] - (Temp_Buffer[i] - Temp_Buffer[i+1])*2; double temp2 = Temp_Buffer[i] + (Temp_Buffer[i] - temp1)*2; double temp3 = temp2 - temp1; if(temp3 > 0) { PlotIndexSetInteger(0,PLOT_LINE_COLOR,colors[0]); Histogram_Buffer[i] = temp3; } else if(temp3 < 0) { PlotIndexSetInteger(0,PLOT_LINE_COLOR,colors[1]); Histogram_Buffer[i] = temp3; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //+------------------------------------------------------------------+
Hi this is my code
i thought PlotIndexSetInteger function can change the bars of a histogram
so that 1 bar be red and the other be greean(for examole)
but its wrong, this function can change the color of all bars in a histogram together.
when this function runs all bars together changes color.
that's the point.

- www.mql5.com

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hi in the above code first PlotIndexSetInteger(0,PLOT_LINE_COLOR,plot_color[0]);
change the color of the plot indicator but second
PlotIndexSetInteger(0,PLOT_LINE_COLOR,plot_color[1]);
don't affect the color
I used "Draw_Histogram" type
Why?
tks for your help