You have 2 times the same plot properties with index "1".
Alain Verleyen #:
You have 2 times the same plot properties with index "1".
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.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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.