//| weixin:imyingjia | //| http://www.waihui.ru | //+------------------------------------------------------------------+ #property copyright "QQ:29996044 weixin:imyingjia" #property link "http://www.yingjia.im" #property strict #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Lime #property indicator_color2 Red #property indicator_level1 75 #property indicator_level2 25 #property indicator_maximum 120 #property indicator_minimum -10 input ENUM_TIMEFRAMES timeframe=PERIOD_H4;//时间轴 input int Kperiod=8;//STOCHK周期 input int Dperiod=5;//STOCHD周期 input int slowing=3;//STOCH慢速 input ENUM_STO_PRICE method=STO_LOWHIGH;//STOCH价格字段 input ENUM_MA_METHOD price_field=MODE_SMA;//STOCH移动平均 int NumBars = 999; double ExtMapBuffer1[]; double ExtMapBuffer2[]; string TimeFrameStr; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit(void) { SetIndexBuffer(0,ExtMapBuffer1); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(1,ExtMapBuffer2); SetIndexStyle(1,DRAW_LINE,STYLE_DOT); switch(timeframe) { case 1 : TimeFrameStr="M1"; break; case 5 : TimeFrameStr="M5"; break; case 15 : TimeFrameStr="M15"; break; case 30 : TimeFrameStr="M30"; break; case 60 : TimeFrameStr="H1"; break; case 240 : TimeFrameStr="H4"; break; case 1440 : TimeFrameStr="D1"; break; case 10080 : TimeFrameStr="W1"; break; case 43200 : TimeFrameStr="MN1"; break; default : TimeFrameStr="Current"; } IndicatorShortName("Stochastic " + TimeFrameStr + " ("+(string)Kperiod+","+(string)Dperiod+","+(string)slowing+") "); return(INIT_SUCCEEDED); } 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 &tick_volume[], const long &volume[], const int &spread[]) { datetime TimeArray[]; ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),timeframe); int j=0; for(int i=0; i<=Bars; i++) { while(Time[i]ArraySize(TimeArray)) break; if(i>NumBars) break; ExtMapBuffer1[i]=iStochastic(NULL,timeframe,Kperiod,Dperiod,slowing,price_field,method,0,j); ExtMapBuffer2[i]=iStochastic(NULL,timeframe,Kperiod,Dperiod,slowing,price_field,method,1,j); } return(rates_total); }