//+------------------------------------------------------------------+ //| KST.mt4 | //| Copyright © 2011, Robert Hill | //| | //| Based on formulas from Martin Pring | //| | //| DAILY KST SIMPLE MOVING AVERAGE | //| (Mov(Roc(C,10,%),10,S)*1) + (Mov(Roc(C,15,%),10,S)*2) + | //| (Mov(Roc (C,20,%),10,S)*3) + (Mov(Roc(C,30,%),15,S)*4) | //| | //| DAYLY Only Version Modifyed by © 2011, PDSoftware Corp. | //+------------------------------------------------------------------+ #property copyright "Copyright © 2011, Robert Hill " //---- indicator settings #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Red #property indicator_width1 2 extern string k0 = "--- DAYLY KST Type ---"; /*extern string k0 = "---Enter KST Type---"; extern string k1 = "1. DAILY SMA"; extern string k2 = "2. LONG-TERM MONTHLY SMA"; extern string k3 = "3. INTERMEDIATE SMA"; extern string k4 = "4. INTERMEDIATE EMA"; extern string k5 = "5. LONG-TERM EMA"; extern string k6 = "6. SHORT-TERM WEEKLY EMA"; extern int KST_Type = 1;*/ //extern int BarsBack = 10000; //---- Variable setting for DAYLY KST - change this value for having a different Types int ROC_Period1=10; int ROC_Period2=15; int ROC_Period3=20; int ROC_Period4=30; int MA_Period1=10; int MA_Period2=10; int MA_Period3=10; int MA_Period4=10; int MA_Type= MODE_SMA; //---- buffers double KST[]; double Buffer1[]; double ROC1[]; double ROC2[]; double ROC3[]; double ROC4[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- drawing settings SetIndexDrawBegin(0,0); IndicatorBuffers(6); SetIndexStyle(0,DRAW_LINE); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2); //IndicatorDigits(Digits+2); //---- indicator buffers mapping if(!SetIndexBuffer(0,KST) && !SetIndexBuffer(1,Buffer1) && !SetIndexBuffer(2,ROC1)&& !SetIndexBuffer(3,ROC2) && !SetIndexBuffer(4,ROC3) && !SetIndexBuffer(5,ROC4)) Print("cannot set indicator buffers!"); //---- name for DataWindow and indicator subwindow label IndicatorShortName("KST"); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i, limit; int counted_bars=IndicatorCounted(); double price, prevPrice; if(counted_bars>0) counted_bars--; //limit - 100 bars (for eliminating Zero Divide Error) limit=Bars-counted_bars-100; //if(counted_bars==0) limit=Bars-counted_bars; //limit = 1000; for(i=0; i<=limit; i++) { price = Close[i]; prevPrice = Close[i+ROC_Period1]; Buffer1[i]= (price-prevPrice)/prevPrice; } for(i=0; i<=limit; i++) ROC1[i] = iMAOnArray(Buffer1,0,MA_Period1,0,MA_Type,i); for(i=0; i<=limit; i++) { price = Close[i]; prevPrice = Close[i+ROC_Period2]; Buffer1[i]= (price-prevPrice)/prevPrice; } for(i=0; i<=limit; i++) ROC2[i] = iMAOnArray(Buffer1,0,MA_Period2,0,MA_Type,i); for(i=0; i<=limit; i++) { price = Close[i]; prevPrice = Close[i+ROC_Period3]; Buffer1[i]= (price-prevPrice)/prevPrice; } for(i=0; i<=limit; i++) ROC3[i] = iMAOnArray(Buffer1,0,MA_Period3,0,MA_Type,i); for(i=0; i<=limit; i++) { price = Close[i]; prevPrice = Close[i+ROC_Period4]; Buffer1[i]= (price-prevPrice)/prevPrice; } for(i=0; i<=limit; i++) ROC4[i] = iMAOnArray(Buffer1,0,MA_Period4,0,MA_Type,i); //========== COLOR CODING =========================================== for(i=0; i<=limit; i++) { KST[i] = ROC1[i] + ROC2[i]*2.0 + ROC3[i]*3.0 + ROC4[i]*4.0; //if (KST_Type == 2) KST[i] /= 4.0; } return(0); } //+------------------------------------------------------------------+