Hello guys.
I made an indicator from KST Indicator, which consists on the sustraction of KST minus its 9 period EMA.
The code is very simple, but as I have 0 idea of programming, I had to make from looking at other indicators code.
I finally made the indicator as I wished but there is one problem with the realtime/forward plotting, as you will see inthe following screenshots.
If chart is updated, the indicator works correctly>
Ive checked the code a ton of times but I have no idea of what it could be. Can anyone give me a help on this??? Thank you very much
Here is the code;
I made an indicator from KST Indicator, which consists on the sustraction of KST minus its 9 period EMA.
The code is very simple, but as I have 0 idea of programming, I had to make from looking at other indicators code.
I finally made the indicator as I wished but there is one problem with the realtime/forward plotting, as you will see inthe following screenshots.
If chart is updated, the indicator works correctly>
Ive checked the code a ton of times but I have no idea of what it could be. Can anyone give me a help on this??? Thank you very much
Here is the code;
Inserted Code
define vers "1.0" #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 FireBrick #property indicator_color2 Green //#property indicator_width1 3 //#property indicator_width2 3 //---- //extern color color1 = FireBrick; //extern color color2 = White; extern int X1 = 10; extern int X2 = 15; extern int X3 = 20; extern int X4 = 30; extern int AVG1 = 5; extern int AVG2 = 10; extern int AVG3 = 15; extern int AVG4 = 20; extern double W1 = -1; extern double W2 = -2; extern double W3 = -3; extern double W4 = -4; extern int period = 15; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ double KSTXBufUp[]; double KSTXBufDown[]; double ROC1Buf[]; double ROC2Buf[]; double ROC3Buf[]; double ROC4Buf[]; double ROC1MABuf[]; double ROC2MABuf[]; double ROC3MABuf[]; double ROC4MABuf[]; double KSTCBuf[]; double KSTAvgBuf[]; double KSTXBuf[]; string short_name; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void init() { IndicatorBuffers(3); //SetIndexDrawBegin(0,1); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2); SetIndexBuffer(0, KSTXBufUp); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2); SetIndexBuffer(1, KSTXBufDown); //SetIndexStyle(2,DRAW_LINE); //SetIndexBuffer(2, KSTCBuf); //SetIndexBuffer(3, KSTAvgBuf); //SetIndexBuffer(4, KSTBuf); //SetIndexLabel(0, "KST"); //SetIndexDrawBegin(0, MathMax(MathMax(X1, X2), MathMax(X3, X4))); ArraySetAsSeries(KSTCBuf, true); ArraySetAsSeries(KSTAvgBuf, true); ArraySetAsSeries(KSTXBuf, true); ArraySetAsSeries(ROC1Buf, true); ArraySetAsSeries(ROC2Buf, true); ArraySetAsSeries(ROC3Buf, true); ArraySetAsSeries(ROC4Buf, true); ArraySetAsSeries(ROC1MABuf, true); ArraySetAsSeries(ROC2MABuf, true); ArraySetAsSeries(ROC3MABuf, true); ArraySetAsSeries(ROC4MABuf, true); short_name = "KSTX"; IndicatorShortName(short_name); } void deinit() { } void start() { int size = ArraySize(ROC1Buf); if (size < Bars) { size = Bars; ArrayResize(ROC1Buf, size); ArrayResize(ROC2Buf, size); ArrayResize(ROC3Buf, size); ArrayResize(ROC4Buf, size); ArrayResize(ROC1MABuf, size); ArrayResize(ROC2MABuf, size); ArrayResize(ROC3MABuf, size); ArrayResize(ROC4MABuf, size); ArrayResize(KSTXBuf, size); ArrayResize(KSTAvgBuf, size); ArrayResize(KSTCBuf, size); } int counted_bars = IndicatorCounted(); int limit = Bars - counted_bars; if (counted_bars > 0) limit++; for(int i=0; i<limit; i++) { if (i+X1 >= Bars) continue; if (i+X2 >= Bars) continue; if (i+X3 >= Bars) continue; if (i+X4 >= Bars) continue; ROC1Buf[i] = (1.0 - Close[i]/Close[i+X1]) * 100.0; ROC2Buf[i] = (1.0 - Close[i]/Close[i+X2]) * 100.0; ROC3Buf[i] = (1.0 - Close[i]/Close[i+X3]) * 100.0; ROC4Buf[i] = (1.0 - Close[i]/Close[i+X4]) * 100.0; } for(i=0; i<limit; i++) { ROC1MABuf[i] = iMAOnArray(ROC1Buf, 0, AVG1, 0, MODE_EMA, i); ROC2MABuf[i] = iMAOnArray(ROC2Buf, 0, AVG2, 0, MODE_EMA, i); ROC3MABuf[i] = iMAOnArray(ROC3Buf, 0, AVG3, 0, MODE_EMA, i); ROC4MABuf[i] = iMAOnArray(ROC4Buf, 0, AVG4, 0, MODE_EMA, i); } for(i=0; i<limit; i++) { KSTCBuf[i] = ROC1MABuf[i] * W1 + ROC2MABuf[i] * W2 + ROC3MABuf[i] * W3 + ROC4MABuf[i] * W4; } for(i=0; i<limit; i++) { KSTAvgBuf[i] = iMAOnArray(KSTCBuf, 0, period, 0, MODE_EMA, i); } for(i=0; i<limit; i++) { KSTXBuf[i] = KSTCBuf[i] - KSTAvgBuf[i]; //KSTXBuf[i] = KSTAvgBuf[i]; if (KSTXBuf[i]>KSTXBuf[i-1]) { KSTXBufUp[i] = KSTXBuf[i]; KSTXBufDown[i] = EMPTY_VALUE; if (KSTXBuf[i-1]<KSTXBuf[i-2]) KSTXBufUp[i-1]=KSTXBuf[i-1]; } if (KSTXBuf[i]<KSTXBuf[i-1]) { KSTXBufDown[i] = KSTXBuf[i]; KSTXBufUp[i] = EMPTY_VALUE; if (KSTXBuf[i-1]>KSTXBuf[i-2]) KSTXBufDown[i-1]=KSTXBuf[i-1]; } } }