Download MetaTrader 5

draw 96 line MAs with only 100 line code

To add comments, please log in or register
Find out the most discussed Forum topics. Have a look at the Wall section!
Loong
1260
Loong 2010.01.11 12:39 

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:
Rashid Umarov
Admin
11812
Rashid Umarov 2010.01.11 18:52  

Try use something like that:

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

investeo
4098
investeo 2010.01.12 02:28  

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



Loong
1260
Loong 2010.01.12 11:02  

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?

 

Loong
1260
Loong 2010.01.12 11:11  

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:
Rashid Umarov
Admin
11812
Rashid Umarov 2010.01.12 11:14  
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
Rashid Umarov
Admin
11812
Rashid Umarov 2010.01.12 11:16  

Please, format your code with built tools.


investeo
4098
investeo 2010.01.12 11:22  
Rosh   :

Please, format your code with built tools.



thank you for a clue, fixed
Loong
1260
Loong 2010.01.12 13:57  
Rosh   :

Please, format your code with built tools.



OK. But the hesternal comment seem too old to edit.
Loong
1260
Loong 2010.01.12 14:11  
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? 

Rashid Umarov
Admin
11812
Rashid Umarov 2010.01.12 15:18  
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
12
To add comments, please log in or register