//------------------------------------------------------------------ #property copyright "Copyright 2018, mladen" #property link "mladenfx@gmail.com" #property description "Schaff trend cycle CD - non lag MA" #property version "1.00" //------------------------------------------------------------------ #property indicator_separate_window #property indicator_buffers 6 #property indicator_plots 1 #property indicator_label1 "Schaff trend cycle CD - NLMA" #property indicator_type1 DRAW_COLOR_LINE #property indicator_color1 clrSilver,clrLimeGreen,clrOrange #property indicator_width1 2 // input parameters input int SchaffPeriod = 32; // Schaff period input int FastNlma = 23; // Fast nonlag ma period input int SlowNlma = 50; // Slow nonlag ma period input int SignalNlma = 25; // Signal nonlag ma period input double SmoothPeriod = 3; // Smoothing period input ENUM_APPLIED_PRICE Price = PRICE_CLOSE; // Price double val[],valc[],macd[],fastk1[],fastd1[],fastk2[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { SetIndexBuffer(0,val,INDICATOR_DATA); SetIndexBuffer(1,valc,INDICATOR_COLOR_INDEX); SetIndexBuffer(2,macd,INDICATOR_CALCULATIONS); SetIndexBuffer(3,fastk1,INDICATOR_CALCULATIONS); SetIndexBuffer(4,fastk2,INDICATOR_CALCULATIONS); SetIndexBuffer(5,fastd1,INDICATOR_CALCULATIONS); IndicatorSetString(INDICATOR_SHORTNAME,"Schaff trend cycle CD NLMA ("+(string)SchaffPeriod+","+(string)FastNlma+","+(string)SlowNlma+","+(string)SignalNlma+","+(string)SmoothPeriod+")"); 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 &tickVolume[], const long &volume[], const int &spread[]) { if (Bars(_Symbol,_Period) 0) ? 100*((macd[i]-lowMacd)/highMacd) : (i>0) ? fastk1[i-1] : 0; fastd1[i] = (i>0) ? fastd1[i-1]+alpha*(fastk1[i]-fastd1[i-1]) : fastk1[i]; double lowStoch = fastd1[ArrayMinimum(fastd1,start,SchaffPeriod)]; double highStoch = fastd1[ArrayMaximum(fastd1,start,SchaffPeriod)]-lowStoch; fastk2[i] = (highStoch > 0) ? 100*((fastd1[i]-lowStoch)/highStoch) : (i>0) ? fastk2[i-1] : 0; val[i] = (i>0) ? val[i-1]+alpha*(fastk2[i]-val[i-1]) : fastk2[i]; valc[i] = (i>0) ? (val[i]>val[i-1]) ? 1 : (val[i]0) { double sum = 0; for (int k=0; k < (int)nlmvalues[instanceNo][_len] && (r-k)>=0; k++) sum += nlmalphas[k][instanceNo]*nlmprices[r-k][instanceNo]; return( sum / nlmvalues[instanceNo][_weight]); } else return(0); } // //--- // double getPrice(ENUM_APPLIED_PRICE tprice,const double &open[],const double &close[],const double &high[],const double &low[],int i,int _bars) { switch(tprice) { case PRICE_CLOSE: return(close[i]); case PRICE_OPEN: return(open[i]); case PRICE_HIGH: return(high[i]); case PRICE_LOW: return(low[i]); case PRICE_MEDIAN: return((high[i]+low[i])/2.0); case PRICE_TYPICAL: return((high[i]+low[i]+close[i])/3.0); case PRICE_WEIGHTED: return((high[i]+low[i]+close[i]+close[i])/4.0); } return(0); }