Change
#property indicator_buffers 2
To
#property indicator_buffers 5
And no need to
IndicatorBuffers(8);
Thanks codersguru, unfortunately it didn't solve the problem, in the meantime I've got already the solution from someone else but anyway thanks! The solution is as follows:
#property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_buffers 4 #property indicator_color2 LightSeaGreen #property indicator_color3 Red #property indicator_color4 Orange #property indicator_color5 Blue #property indicator_color6 Yellow //---- input parameters extern int KPeriod=5; extern int DPeriod=3; extern int Slowing1=3; extern int Slowing2=3; //---- buffers double buffer0[]; double buffer1[]; double buffer2[]; double buffer3[]; double buffer4[]; double buffer5[]; //---- int draw_begin1=0; int draw_begin2=0; int draw_begin3=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string short_name; IndicatorBuffers(8); SetIndexStyle(4,DRAW_NONE); SetIndexBuffer(4, buffer0); SetIndexLabel(4,"buffer0"); SetIndexStyle(5,DRAW_NONE); SetIndexBuffer(5, buffer1); SetIndexLabel(5,"buffer1"); SetIndexBuffer(0, buffer2); SetIndexStyle(0,DRAW_LINE); SetIndexLabel(0,"%K"); SetIndexBuffer(1, buffer3); SetIndexStyle(1,DRAW_LINE); SetIndexLabel(1,"%D"); SetIndexBuffer(2, buffer4); SetIndexStyle(2,DRAW_LINE); SetIndexLabel(2,"%DS"); SetIndexBuffer(3, buffer5); SetIndexStyle(3,DRAW_LINE); SetIndexLabel(3,"%DSS"); //---- name for DataWindow and indicator subwindow label short_name="Sto("+KPeriod+","+DPeriod+","+Slowing1+","+Slowing2+")"; IndicatorShortName(short_name); //---- draw_begin1=KPeriod+DPeriod; draw_begin2=draw_begin1+Slowing1; draw_begin3=draw_begin2+Slowing2; SetIndexDrawBegin(0,draw_begin3); SetIndexDrawBegin(1,draw_begin3); //LightSeaGreen SetIndexDrawBegin(2,draw_begin3); //red SetIndexDrawBegin(3,draw_begin3); //orange SetIndexDrawBegin(4,draw_begin3); //blue SetIndexDrawBegin(5,draw_begin3); return(0); } //+------------------------------------------------------------------+ //| Stochastic oscillator | //+------------------------------------------------------------------+ int start() { int i,k; int counted_bars=IndicatorCounted(); double price; //---- if(Bars<=draw_begin3) return(0); //---- initial zero if(counted_bars<1) { for(i=1;i<=draw_begin1;i++) buffer2[Bars-i]=0; for(i=1;i<=draw_begin2;i++) buffer3[Bars-i]=0; } //---- minimums counting i=Bars-KPeriod; if(counted_bars>KPeriod) i=Bars-counted_bars-1; while(i>=0) { double min=1000000; k=i+KPeriod-1; while(k>=i) { price=Low[k]; if(min>price) min=price; k--; } buffer1[i]=min; i--; } //---- maximums counting i=Bars-KPeriod; if(counted_bars>KPeriod) i=Bars-counted_bars-1; while(i>=0) { double max=-1000000; k=i+KPeriod-1; while(k>=i) { price=High[k]; if(max<price) max=price; k--; } buffer0[i]=max; i--; } //---- %K line i=Bars-draw_begin1; if(counted_bars>draw_begin1) i=Bars-counted_bars-1; while(i>=0) { double sumlow=0.0; double sumhigh=0.0; for(k=(i+Slowing1-1);k>=i;k--) { sumlow+=Close[k]-buffer1[k]; sumhigh+=buffer0[k]-buffer1[k]; } if(sumhigh==0.0) buffer2[i]=100.0; else buffer2[i]=sumlow/sumhigh*100; i--; } //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; int limit=Bars-counted_bars; //---- signal line is simple moving average for(i=0; i<limit; i++) buffer3[i]=iMAOnArray(buffer2,0,DPeriod ,0,MODE_SMA,i); for(i=0; i<limit; i++) buffer4[i]=iMAOnArray(buffer3,0,Slowing1,0,MODE_SMA,i); for(i=0; i<limit; i++) buffer5[i]=iMAOnArray(buffer4,0,Slowing2,0,MODE_SMA,i); return(0); } //+------------------------------------------------------------------+

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 hope anyone can help me. I try to add an additional Moving Average to the usual Stochastics but the last two MA's (buffer 4 & 5) do not show up in my graph. Probably I do something wrong with the buffers. Could anyone tell me what I am doing wrong? Thanks in advance.