How to have 2 PAIRS of DRAW_FILLING in 1 Indicator

 

I want to have 2 clouds with DRAW_FILLING  in 1 indicator.

I duplicated all the buffers of the official DRAW_FILLING.mq5

https://www.mql5.com/en/docs/customind/indicators_examples/draw_filling


and the result is that I have only 1 ribbon of MAs. Notice in the ''data window'' of MT5, there are 3 buffers instead of 4.


//+------------------------------------------------------------------+
//|                                                 DRAW_FILLINAG.mq5 |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

#property description "An indicator to demonstrate DRAW_FILLINAG"
#property description "It draws a channel between two MAs in a separate window"
#property description "The fill color is changed randomly"
#property description "after every NAA ticksAA"

#property indicator_separate_window
#property indicator_buffers 2*2
#property indicator_plots   1*2
//--- plot IntersectionAA
#property indicator_label1  "IntersectionAA"
#property indicator_type1   DRAW_FILLING
#property indicator_color1  clrRed,clrBlue
#property indicator_width1  1
//--- input parameters
input int      FastAA=13;          // The period of a FastAA MA
input int      SlowAA=21;          // The period of a SlowAA MA
input int      shiftAA=1;          // B shiftAA of MAs towards the future (positive)
input int      NAA=5;              // NAumber of ticksAA to change
//--- Indicator buffers
double         IntersectionABuffer1AA[];
double         IntersectionABuffer2AA[];
int fast_handleAA;
int slow_handleAA;
//--- An array to store colorsAA
color colorsAA[]= {clrRed,clrBlue,clrGreen,clrAquamarine,clrBlanchedAlmond,clrBrown,clrCoral,clrDarkSlateGray};
//---
//---
//---
//---
//--- plot IntersectionBB
#property indicator_label1  "IntersectionBB"
#property indicator_type1   DRAW_FILLING
#property indicator_color1  clrLime,clrGhostWhite
#property indicator_width1  1
//--- input parameters
input int      FastBB=13*3;          // The period of a FastBB MA
input int      SlowBB=21*3;          // The period of a SlowBB MA
input int      shiftBB=1*3;          // B shiftBB of MAs towards the future (positive)
input int      NBB=5*3;              // NAumber of ticksBB to change
//--- Indicator buffers
double         IntersectionABuffer1BB[];
double         IntersectionABuffer2BB[];
int fast_handleBB;
int slow_handleBB;
//--- An array to store colorsBB
color colorsBB[]= {clrLime,clrGhostWhite,clrGainsboro,clrViolet,clrDarkBlue,clrDarkGoldenrod,clrDarkSalmon,clrOldLace};


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
 SetIndexBuffer(0,IntersectionABuffer1AA,INDICATOR_DATA);
 SetIndexBuffer(1,IntersectionABuffer2AA,INDICATOR_DATA);
//---
 PlotIndexSetInteger(0,PLOT_SHIFT,shiftAA);
//---
 fast_handleAA=iMA(_Symbol,_Period,FastAA,0,MODE_SMA,PRICE_CLOSE);
 slow_handleAA=iMA(_Symbol,_Period,SlowAA,0,MODE_SMA,PRICE_CLOSE);
//---
//---
//---
//---
//---
//--- indicator buffers mapping
 SetIndexBuffer(2,IntersectionABuffer1BB,INDICATOR_DATA);
 SetIndexBuffer(3,IntersectionABuffer2BB,INDICATOR_DATA);
//---
 PlotIndexSetInteger(2,PLOT_SHIFT,shiftBB);
//---
 fast_handleBB=iMA(_Symbol,_Period,FastBB,0,MODE_SMA,PRICE_CLOSE);
 slow_handleBB=iMA(_Symbol,_Period,SlowBB,0,MODE_SMA,PRICE_CLOSE);
//---
 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[])
{
 static int ticksAA=0;
//--- Calculate ticksAA to change the style, color and width of the line
 ticksAA++;
//--- If a sufficient number of ticksAA has been accumulated
 if(ticksAA>=NAA)
 {
  //--- Change the line properties
  ChangeLineAppearanceAA();
  //--- Reset the counter of ticksAA to zero
  ticksAA=0;
 }
//--- Make the first calculation of the indicator, or data has changed and requires a complete recalculation
 if(prev_calculated==0)
 {
  //--- Copy all the values of the indicators to the appropriate buffers
  int copied1AA=CopyBuffer(fast_handleAA,0,0,rates_total,IntersectionABuffer1AA);
  int copied2AA=CopyBuffer(slow_handleAA,0,0,rates_total,IntersectionABuffer2AA);
 }
 else // Fill only those data that are updated
 {
  //--- Get the difference in bars between the current and previous start of OnCalculate()
  int to_copyAA=rates_total-prev_calculated;
  //--- If there is no difference, we still copy one value - on the zero bar
  if(to_copyAA==0) to_copyAA=1;
  //--- copy to_copyAA values to the very end of indicator buffers
  int copied1AA=CopyBuffer(fast_handleAA,0,0,to_copyAA,IntersectionABuffer1AA);
  int copied2AA=CopyBuffer(slow_handleAA,0,0,to_copyAA,IntersectionABuffer2AA);
 }
 //---
 //---
 //---
 static int ticksBB=0;
//--- Calculate ticksBB to change the style, color and width of the line
 ticksBB++;
//--- If a sufficient number of ticksBB has been accumulated
 if(ticksBB>=NBB)
 {
  //--- Change the line properties
  ChangeLineAppearanceBB();
  //--- Reset the counter of ticksBB to zero
  ticksBB=0;
 }
//--- Make the first calculation of the indicator, or data has changed and requires a complete recalculation
 if(prev_calculated==0)
 {
  //--- Copy all the values of the indicators to the appropriate buffers
  int copied1BB=CopyBuffer(fast_handleBB,0,0,rates_total,IntersectionABuffer1BB);
  int copied2BB=CopyBuffer(slow_handleBB,0,0,rates_total,IntersectionABuffer2BB);
 }
 else // Fill only those data that are updated
 {
  //--- Get the difference in bars between the current and previous start of OnCalculate()
  int to_copyBB=rates_total-prev_calculated;
  //--- If there is no difference, we still copy one value - on the zero bar
  if(to_copyBB==0) to_copyBB=1;
  //--- copy to_copyBB values to the very end of indicator buffers
  int copied1BB=CopyBuffer(fast_handleBB,0,0,to_copyBB,IntersectionABuffer1BB);
  int copied2BB=CopyBuffer(slow_handleBB,0,0,to_copyBB,IntersectionABuffer2BB);
 }
//--- return value of prev_calculated for next call
 return(rates_total);
}
//+------------------------------------------------------------------+
//| Changes the colorsAA of the channel filling                        |
//+------------------------------------------------------------------+
void ChangeLineAppearanceAA()
{
//--- B string for the formation of information about the line properties
 string comm="";
//--- B block for changing the color of the line
 int number=MathRand(); // Get a random number
//--- The divisor is equal to the size of the colorsAA[] array
 int size=ArraySize(colorsAA);
//--- Get the index to select a new color as the remainder of integer division
 int color_index1=number%size;
//--- Set the first color as the PLOT_LINAE_COLOR property
 PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,colorsAA[color_index1]);
//--- Write the first color
 comm=comm+"\r\nColor1 "+(string)colorsAA[color_index1];
//--- Get the index to select a new color as the remainder of integer division
 number=MathRand(); // Get a random number
 int color_index2=number%size;
//--- Set the second color as the PLOT_LINAE_COLOR property
 PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,colorsAA[color_index2]);
//--- Write the second color
 comm=comm+"\r\nColor2 "+(string)colorsAA[color_index2];
//--- Show the information on the chart using a comment
 Comment(comm);
}
//+------------------------------------------------------------------+
//| Changes the colorsBB of the channel filling                        |
//+------------------------------------------------------------------+
void ChangeLineAppearanceBB()
{
//--- B string for the formation of information about the line properties
 string comm="";
//--- B block for changing the color of the line
 int number=MathRand(); // Get a random number
//--- The divisor is equal to the size of the colorsBB[] array
 int size=ArraySize(colorsBB);
//--- Get the index to select a new color as the remainder of integer division
 int color_index1=number%size;
//--- Set the first color as the PLOT_LINAE_COLOR property
 PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,colorsBB[color_index1]);
//--- Write the first color
 comm=comm+"\r\nColor1 "+(string)colorsBB[color_index1];
//--- Get the index to select a new color as the remainder of integer division
 number=MathRand(); // Get a random number
 int color_index2=number%size;
//--- Set the second color as the PLOT_LINAE_COLOR property
 PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,colorsBB[color_index2]);
//--- Write the second color
 comm=comm+"\r\nColor2 "+(string)colorsBB[color_index2];
//--- Show the information on the chart using a comment
 Comment(comm);
}
//+------------------------------------------------------------------+
Documentation on MQL5: Custom Indicators / Indicator Styles in Examples / DRAW_FILLING
Documentation on MQL5: Custom Indicators / Indicator Styles in Examples / DRAW_FILLING
  • www.mql5.com
DRAW_FILLING - Indicator Styles in Examples - Custom Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
You have 2 times the same plot properties with index "1".
 
Alain Verleyen #:
You have 2 times the same plot properties with index "1".

Yes I corrected the code. THe 2 ribbons are printed, but the new ribbon doesn't change the color. I was careful to change ''

PlotIndexSetInteger(2,PLOT_LINE_COLOR,0,colorsBBB[color_index1]);
 in the new function 
ChangeLineAppearanceBBB()

THe color of ribbonBBB is the original color #property indicator_color2  clrViolet,clrDarkGoldenrod

//+------------------------------------------------------------------+
//|                                                 DRAW_FILLING.mq5 |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
 
#property description "An indicator to demonstrate DRAW_FILLING"
#property description "It draws a channel between two MAs in a separate window"
#property description "The fill color is changed randomly"
#property description "after every N ticks"
 
#property indicator_separate_window
#property indicator_buffers 2*2
#property indicator_plots   1*2
//---
//---

//--- plot IntersectionAAA
#property indicator_label1  "IntersectionAAA"
#property indicator_type1   DRAW_FILLING
#property indicator_color1  clrRed,clrBlue
#property indicator_width1  1
//--- input parameters
input int      FastAAA=13;          // The period of a FastAAA MA
input int      SlowAAA=21;          // The period of a SlowAAA MA
input int      shiftAAA=1;          // A shiftAAA of MAs towards the future (positive)
input int      N=5;              // Number of ticks to change 
//--- Indicator buffers
double         IntersectionBuffer1AAA[];
double         IntersectionBuffer2AAA[];
int fast_handleAAA;
int slow_handleAAA;
//--- An array to store colorsAAA
color colorsAAA[]={clrRed,clrBlue,clrGreen,clrAquamarine,clrBlanchedAlmond,clrBrown,clrCoral,clrDarkSlateGray};
//---
//---

//--- plot IntersectionBBB
#property indicator_label2  "IntersectionBBB"
#property indicator_type2   DRAW_FILLING
#property indicator_color2  clrViolet,clrDarkGoldenrod
#property indicator_width2  1
//--- input parameters
input int      FastBBB=13*5;          // The period of a FastBBB MA
input int      SlowBBB=21*5;          // The period of a SlowBBB MA
input int      shiftBBB=1*5;          // A shiftBBB of MAs towards the future (positive)
//input int      N=5;              // Number of ticks to change 
//--- Indicator buffers
double         IntersectionBuffer1BBB[];
double         IntersectionBuffer2BBB[];
int fast_handleBBB;
int slow_handleBBB;
//--- An array to store colorsBBB
color colorsBBB[]={clrLime,clrGhostWhite,clrGainsboro,clrViolet,clrDarkBlue,clrDarkGoldenrod,clrDarkSalmon,clrOldLace};
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,IntersectionBuffer1AAA,INDICATOR_DATA);
   SetIndexBuffer(1,IntersectionBuffer2AAA,INDICATOR_DATA);
//---
   PlotIndexSetInteger(0,PLOT_SHIFT,shiftAAA);
//---
   fast_handleAAA=iMA(_Symbol,_Period,FastAAA,0,MODE_SMA,PRICE_CLOSE);
   slow_handleAAA=iMA(_Symbol,_Period,SlowAAA,0,MODE_SMA,PRICE_CLOSE);
   
   
   
   
   
//--- indicator buffers mapping
   SetIndexBuffer(2,IntersectionBuffer1BBB,INDICATOR_DATA);
   SetIndexBuffer(3,IntersectionBuffer2BBB,INDICATOR_DATA);
//---
   PlotIndexSetInteger(2,PLOT_SHIFT,shiftBBB);
//---
   fast_handleBBB=iMA(_Symbol,_Period,FastBBB,0,MODE_SMA,PRICE_CLOSE);
   slow_handleBBB=iMA(_Symbol,_Period,SlowBBB,0,MODE_SMA,PRICE_CLOSE);
   
   
//---
   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[])
  {
   static int ticksAAA=0;
//--- Calculate ticksAAA to change the style, color and width of the line
   ticksAAA++;
//--- If a sufficient number of ticksAAA has been accumulated
   if(ticksAAA>=N)
     {
      //--- Change the line properties
      ChangeLineAppearanceAAA();
      //--- Reset the counter of ticksAAA to zero
      ticksAAA=0;
     }
 
//--- Make the first calculation of the indicator, or data has changed and requires a complete recalculation
   if(prev_calculated==0)
     {
      //--- Copy all the values of the indicators to the appropriate buffers
      int copied1AAA=CopyBuffer(fast_handleAAA,0,0,rates_total,IntersectionBuffer1AAA);
      int copied2AAA=CopyBuffer(slow_handleAAA,0,0,rates_total,IntersectionBuffer2AAA);
     }
   else // Fill only those data that are updated
     {
      //--- Get the difference in bars between the current and previous start of OnCalculate()
      int to_copyAAA=rates_total-prev_calculated;
      //--- If there is no difference, we still copy one value - on the zero bar
      if(to_copyAAA==0) to_copyAAA=1;
      //--- copy to_copyAAA values to the very end of indicator buffers
      int copied1AAA=CopyBuffer(fast_handleAAA,0,0,to_copyAAA,IntersectionBuffer1AAA);
      int copied2AAA=CopyBuffer(slow_handleAAA,0,0,to_copyAAA,IntersectionBuffer2AAA);
     }
     
     
     
     
   static int ticksBBB=0;
//--- Calculate ticksBBB to change the style, color and width of the line
   ticksBBB++;
//--- If a sufficient number of ticksBBB has been accumulated
   if(ticksBBB>=N)
     {
      //--- Change the line properties
      ChangeLineAppearanceBBB();
      //--- Reset the counter of ticksBBB to zero
      ticksBBB=0;
     }
 
//--- Make the first calculation of the indicator, or data has changed and requires a complete recalculation
   if(prev_calculated==0)
     {
      //--- Copy all the values of the indicators to the appropriate buffers
      int copied1BBB=CopyBuffer(fast_handleBBB,0,0,rates_total,IntersectionBuffer1BBB);
      int copied2BBB=CopyBuffer(slow_handleBBB,0,0,rates_total,IntersectionBuffer2BBB);
     }
   else // Fill only those data that are updated
     {
      //--- Get the difference in bars between the current and previous start of OnCalculate()
      int to_copyBBB=rates_total-prev_calculated;
      //--- If there is no difference, we still copy one value - on the zero bar
      if(to_copyBBB==0) to_copyBBB=1;
      //--- copy to_copyBBB values to the very end of indicator buffers
      int copied1BBB=CopyBuffer(fast_handleBBB,0,0,to_copyBBB,IntersectionBuffer1BBB);
      int copied2BBB=CopyBuffer(slow_handleBBB,0,0,to_copyBBB,IntersectionBuffer2BBB);
     }
     
     
     
     
     
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Changes the colorsAAA of the channel filling                        |
//+------------------------------------------------------------------+
void ChangeLineAppearanceAAA()
  {
//--- A string for the formation of information about the line properties
   string comm="";
//--- A block for changing the color of the line
   int number=MathRand(); // Get a random number
//--- The divisor is equal to the size of the colorsAAA[] array
   int size=ArraySize(colorsAAA);
 
//--- Get the index to select a new color as the remainder of integer division
   int color_index1=number%size;
//--- Set the first color as the PLOT_LINE_COLOR property
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,colorsAAA[color_index1]);
//--- Write the first color
   comm=comm+"\r\nColor1 "+(string)colorsAAA[color_index1];
 
//--- Get the index to select a new color as the remainder of integer division
   number=MathRand(); // Get a random number
   int color_index2=number%size;
//--- Set the second color as the PLOT_LINE_COLOR property
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,colorsAAA[color_index2]);
//--- Write the second color
   comm=comm+"\r\nColor2 "+(string)colorsAAA[color_index2];
//--- Show the information on the chart using a comment
   Comment(comm);
  }
//+------------------------------------------------------------------+
//| Changes the colorsBBB of the channel filling                        |
//+------------------------------------------------------------------+
void ChangeLineAppearanceBBB()
  {
//--- A string for the formation of information about the line properties
   string comm="";
//--- A block for changing the color of the line
   int number=MathRand(); // Get a random number
//--- The divisor is equal to the size of the colorsBBB[] array
   int size=ArraySize(colorsBBB);
 
//--- Get the index to select a new color as the remainder of integer division
   int color_index1=number%size;
//--- Set the first color as the PLOT_LINE_COLOR property
   PlotIndexSetInteger(2,PLOT_LINE_COLOR,0,colorsBBB[color_index1]);
//--- Write the first color
   comm=comm+"\r\nColor1 "+(string)colorsBBB[color_index1];
 
//--- Get the index to select a new color as the remainder of integer division
   number=MathRand(); // Get a random number
   int color_index2=number%size;
//--- Set the second color as the PLOT_LINE_COLOR property
   PlotIndexSetInteger(2,PLOT_LINE_COLOR,1,colorsBBB[color_index2]);
//--- Write the second color
   comm=comm+"\r\nColor2 "+(string)colorsBBB[color_index2];
//--- Show the information on the chart using a comment
   Comment(comm);
  }
 
PlotIndexSetInteger(2,PLOT_LINE_COLOR,0,colorsBBB[color_index1]);
There is no plot index 2, you have 2 plots, index 0 and 1.