draw 96 line MAs with only 100 line code

 

Some time ago (at least before 2009.11.07), I can use a function to set plot line color, such as 
 PlotIndexSetInteger(i,PLOT_LINE_COLOR,iColor);
without explicit declare statement, such as
 #property indicator_color1  Red
But now(2010.01.11), I must write many "#property" in my multi-line indicator,
otherwise my indicator will draw all line with a default color (Silver?).
I like the old characteristic (set color without explicit declare property).
I hope to resume it.
This indicator is only 211 lines (include empty and comment line),
but 96 lines is occupied by indicator_color!

Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Language Basics / Preprocessor / Program Properties (#property) - Documentation on MQL5
Files:
 

Try use something like that:

PlotIndexSetInteger(i,PLOT_COLOR_INDEXES,iNumberOfColors);
PlotIndexSetInteger(i,PLOT_LINE_COLOR,iColor);

 

I played a little with your code and it seems there is a flaw in MT5 concerning number of PLOT_COLOR_INDEXES


int OnInit()
  {
 
  
   IndicatorSetString(INDICATOR_SHORTNAME,"LoongMAx96");//+IntegerToString(AsSeries)
//--- indicator buffers mapping
   color iColor = Red;
   bool bReturn = SequenceQuadratic(iParam,iNum,2,2); 
   int iTmp;               //temporary variable for bug of MT5
   for(int i=0; i<iNum; i++)
   {
      MAA[i].Init();
      iTmp=iParam[i];      //You CANNOT assign a array member with a member of another array,
      MAA[i].mParam=iTmp;  //so you need a temporary variable.
      iColor = ColorInc96(i);
      MAA[i].mSetIndexBuffer(i,INDICATOR_DATA);
      MAA[i].mPlotIndexSetInteger(i,PLOT_DRAW_TYPE,DRAW_LINE);
      MAA[i].mPlotIndexSetInteger(i,PLOT_LINE_STYLE,STYLE_SOLID);
      MAA[i].mPlotIndexSetInteger(i,PLOT_COLOR_INDEXES,63);
      MAA[i].mPlotIndexSetInteger(i,PLOT_LINE_COLOR,ColorInc96(i));
      MAA[i].mPlotIndexSetString(i,PLOT_LABEL,"MA"+IntegerToString(i,2,'0')+"(color:"+IntegerToString(iColor)+")");//Print(IntegerToString())
      MAA[i].mhandle=iMA(NULL,0,MAA[i].mParam,shift,smootMode,price); //Symbol()
   }
   if(AsSeries) {
      for(int i=0; i<iNum; i++)
      {
         MAA[i].mArraySetAsSeries(true);
      }
   }
   return(0);

  }


gives you




and

int OnInit()
  {
 
  
   IndicatorSetString(INDICATOR_SHORTNAME,"LoongMAx96");//+IntegerToString(AsSeries)
//--- indicator buffers mapping
   color iColor = Red;
   bool bReturn = SequenceQuadratic(iParam,iNum,2,2); 
   int iTmp;               //temporary variable for bug of MT5
   for(int i=0; i<iNum; i++)
   {
      MAA[i].Init();
      iTmp=iParam[i];      //You CANNOT assign a array member with a member of another array,
      MAA[i].mParam=iTmp;  //so you need a temporary variable.
      iColor = ColorInc96(i);
      MAA[i].mSetIndexBuffer(i,INDICATOR_DATA);
      MAA[i].mPlotIndexSetInteger(i,PLOT_DRAW_TYPE,DRAW_LINE);
      MAA[i].mPlotIndexSetInteger(i,PLOT_LINE_STYLE,STYLE_SOLID);
      MAA[i].mPlotIndexSetInteger(i,PLOT_COLOR_INDEXES,64);
      MAA[i].mPlotIndexSetInteger(i,PLOT_LINE_COLOR,ColorInc96(i));
      MAA[i].mPlotIndexSetString(i,PLOT_LABEL,"MA"+IntegerToString(i,2,'0')+"(color:"+IntegerToString(iColor)+")");//Print(IntegerToString())
      MAA[i].mhandle=iMA(NULL,0,MAA[i].mParam,shift,smootMode,price); //Symbol()
   }
   if(AsSeries) {
      for(int i=0; i<iNum; i++)
      {
         MAA[i].mArraySetAsSeries(true);
      }
   }
   return(0);

  }

gives




that is value  PLOT_COLOR_INDEXES greater than 63 resets all color values to default silver

cheerz



 

Thank 'Rosh' and 'investeo'!
I test this sentence,

MAA[i].mPlotIndexSetInteger(i,PLOT_COLOR_INDEXES,63);


It 's OK! The indicator work fine.
I may delete those "#property indicator_color".

Just I test lot of iNumberOfColors in

MAA[i].mPlotIndexSetInteger(i,PLOT_COLOR_INDEXES,iNumberOfColors);


the result is ...
If (iNumberOfColors>=1 And iNumberOfColors<=63) then all line have right color.
Else  all line's color values will be default silver.
So I think, PLOT_COLOR_INDEXES may not be 'The number of colors'?
A bug of document?

 

And seem ArraySetAsSeries to do nothing?

I delete

   if(AsSeries) {
      for(int i=0; i<iNum; i++)
      {
         MAA[i].mArraySetAsSeries(true);
      }
   }

But the indicator seems not affected?

Files:
 
Loong   :

Thank 'Rosh' and 'investeo'!

...

If (iNumberOfColors>=1 And iNumberOfColors<=63) then all line have right color.

Else  all line's color values will be default silver.
So I think, PLOT_COLOR_INDEXES may not be 'The number of colors'?
A bug of document?

 

Have you ever tried the expression

MAA[i].mPlotIndexSetInteger(i,PLOT_COLOR_INDEXES,0);
? It must work too because numbering of array elements starts with 0. See also Other Operations
 

Please, format your code with built tools.


 
Rosh   :

Please, format your code with built tools.



thank you for a clue, fixed
 
Rosh   :

Please, format your code with built tools.



OK. But the hesternal comment seem too old to edit.
 
Rosh   :

Have you ever tried the expression

? It must work too because numbering of array elements starts with 0. See also Other Operations


Yes, I tried.

MAA[i].mPlotIndexSetInteger(i,PLOT_COLOR_INDEXES,0);

It cause all line's color values to be default silver.

Is it a bug? 

 
Loong   :


Yes, I tried.

It cause all line's color values to be default silver.

Is it a bug? 


It's difficult to say, see for example indicator ColorLine
Reason: