Hi guys,
i want to draw an indicator like SMA but the color should be variable. For example if the SMA is rising than it's color should be green. If the SMA is falling then it's color should be red.
I can't find a solution for that.
Can anyone explain me, why there are empty spaces in the indicator line in the bottom window?
//+------------------------------------------------------------------+ //| Volumen.mq4 | //| | //| | //+------------------------------------------------------------------+ #property copyright "" #property link "" #property indicator_separate_window #property indicator_buffers 3 // Number of buffers #property indicator_color1 Yellow // Color of the 1st line #property indicator_color2 Red // Color of the 1st line #property indicator_color3 Blue // Color of the 1st line //#property indicator_color4 Blue // Color of the 1st line extern int Period_MA = 20; // Calculated MA period //--- intern variables double Volumen0[]; // Wert Steigung double Volumen1[]; // Wert Steigung //double Volumen2[]; // Wert Steigung double SMA[]; // SMA //-------------------------------------------------------------------- int init() // Special function init() { string short_name = "Volumen"; IndicatorBuffers(3); SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);// Line style SetIndexBuffer(0,Volumen0); // Assigning an array to a buffer SetIndexStyle (1,DRAW_LINE,STYLE_SOLID,2);// Line style SetIndexBuffer(1,Volumen1); // Assigning an array to a buffer SetIndexStyle (2,DRAW_LINE,STYLE_SOLID,2);// Line style SetIndexBuffer(2,SMA); // Assigning an array to a buffer //SetIndexStyle (3,DRAW_LINE,STYLE_SOLID,2);// Line style //SetIndexBuffer(3,Volumen2); // Assigning an array to a buffer SetIndexEmptyValue(0,0.0); SetIndexEmptyValue(1,0.0); SetIndexEmptyValue(2,0.0); //SetIndexEmptyValue(3,0); IndicatorShortName(short_name); // Indicator name SetIndexLabel(0,short_name); // Label im DataWindows return; // Exit the special funct. init() } //-------------------------------------------------------------------- int start() // Special function start() { int counted_bars; // Number of counted bars int i; // Bar index double Pip = 10*Point; //ArrayInitialize(StMA,0.0); //---- initial zero counted_bars=IndicatorCounted(); // Number of counted bars if(counted_bars<1) for(i=1;i<=Period_MA;i++) { Volumen0[Bars-i]=0.0; Volumen1[Bars-i]=0.0; //Volumen2[Bars-i]=0.0; SMA[Bars-i]=0.0; } i=Bars-counted_bars-1; // Index of the first uncounted while(i>=0) // Loop for uncounted bars { Volumen0[i]=Volume[i]; // Value of 0 buffer on i bar i--; // Calculating index of the next bar } i=Bars-counted_bars-1; // Index of the first uncounted while(i>=0) // Loop for uncounted bars { SMA[i]=iMAOnArray(Volumen0,Bars,Period_MA,0,MODE_SMA,i); // Value of 0 buffer on i bar i--; // Calculating index of the next bar } // Calculating index of the next bar i=Bars-counted_bars-1; // Index of the first uncounted while(i>=0) // Loop for uncounted bars { if(Volumen0[i]>=SMA[i]) { Volumen0[i]=Volumen0[i]; Volumen1[i]=0.0; } else { Volumen1[i]=Volumen0[i]; Volumen0[i]=0.0; } i--; // Calculating index of the next bar } // Calculating index of the next bar } //--------------------------------------------------------------------+
have u found solution to line gap problems as mention above by Raptor?
Ok u r rite..but what shld b the code?..if now is red and previous is yellow,then yellow equals red??..whereas previous is a gap~..what will b the line color at the gaps?
guyz..it is also noticed in the above chart that there are gaps even when line doesnt changes color? ..what is happening here..
i m also trying to code threecolor indicator and found this post partially helpful bt i suspect somethin is still missing
guyz..it is also noticed in the above chart that there are gaps even when line doesnt changes color?
Ok u r rite..but what shld b the code?..if now is red and previous is yellow,then yellow equals red??..whereas previous is a gap~..what will b the line color at the gaps?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys,
i want to draw an indicator like SMA but the color should be variable. For example if the SMA is rising than it's color should be green. If the SMA is falling then it's color should be red.
I can't find a solution for that.