indicator colour

samjesse

Active Trader
Aug 30, 2011
118
0
27
Hi

I am not sure why my indicator is not changing color. please help thx.

MQL5:
double iBuf[];  
double iBuf_colour[];
 
int OnInit()
  {
   SetIndexBuffer(0,iBuf,INDICATOR_DATA);
   SetIndexBuffer(1, iBuf_colour,INDICATOR_COLOR_INDEX);
   PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2); 
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,Red);  
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Blue); 
}
 
 
int OnCalculate(...)
{
   for(int x = 0; x < ArraySize(itemp); x++) 
   {
      iBuf[x] = itemp[x];
      if(x>6) iBuf_colour[x]=0;
      else iBuf_colour[x]=1;
   }
 
}
 
Last edited by a moderator:

Enivid

Administrator
Staff member
Nov 30, 2008
18,535
1,355
144
Odesa
www.earnforex.com
It'd better if you could also show your #property declarations for this indicator.

I don't know why do you use PlotIndexSetInteger for color setting. I do it with #property:

MQL5:
#property indicator_color1 clrYellow, clrWhite

Then, you color values are incorrect. MQL5 now uses 'clr' prefix for all colors.
 
Last edited:

samjesse

Active Trader
Aug 30, 2011
118
0
27
did you mean this way?
it is still not plotting the indicator in 2 colors.

MQL5:
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_style1  STYLE_SOLID
#property indicator_color1  clrRed, clrBlue
 
 
int OnInit()
  {
 
   SetIndexBuffer(0,iBuf,INDICATOR_DATA);
   SetIndexBuffer(1, iBuf_colour,INDICATOR_COLOR_INDEX);
   PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2); 
 return(0);
}
 
int OnCalculate(const int rates_total,...
 
   for(int x = 0; x < ArraySize(itemp); x++) 
   {
      iBuf[x] = itemp[x];
      if(x>6) iBuf_colour[x]=0;
      else iBuf_colour[x]=1;
}
   return 1;
 
Last edited by a moderator:

samjesse

Active Trader
Aug 30, 2011
118
0
27
when I use the following line, it plots the indicator in Red only.
MQL5:
#property indicator_type1 DRAW_LINE

When I use the following line, it does not plot it at all.
MQL5:
#property indicator_type1 DRAW_COLOR_LINE

here are the relevant sections of the code:
MQL5:
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_color1 clrRed, clrBlue
 
 
// Indicator buffers
double itemp[300];
double iBuf[];   
double iBuf_colour[];
 
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,iBuf,INDICATOR_DATA);
   SetIndexBuffer(1, iBuf_colour,INDICATOR_COLOR_INDEX);
 
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE); 
   ArraySetAsSeries(iBuf, true);
 
int OnCalculate(const int rates_total,...
 
   for(int x = 0; x < ArraySize(itemp); x++) 
   {
      iBuf[x] = itemp[x];
      if(x<6) iBuf_colour[x]=1;
      else iBuf_colour[x]=0;
//Alert(x + "  colour is  " + iBuf_colour[x]);    <<<< all is well 
}
  return (rates_total);
  }
 
Last edited by a moderator: