//+------------------------------------------------------------------+ //| Any Pair Stochastic.mq5 | //+------------------------------------------------------------------+ #property copyright "chandra100" #property link "bala100gain@gmail.com" #property version "1.00" #property indicator_separate_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ #property indicator_buffers 4 #property indicator_plots 2 #property indicator_type1 DRAW_LINE #property indicator_type2 DRAW_LINE #property indicator_color1 LightSeaGreen #property indicator_color2 Red #property indicator_style2 STYLE_DOT //--- input parameters input int InpKPeriod=5; // K period input int InpDPeriod=3; // D period input int InpSlowing=3; // Slowing //--- indicator buffers double ExtMainBuffer[]; double ExtSignalBuffer[]; double ExtHighesBuffer[]; double ExtLowesBuffer[]; input string Pair="EURUSD"; int rsi_handle; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { rsi_handle=iStochastic(Pair,Period(),InpKPeriod,InpDPeriod,InpSlowing,MODE_SMA,STO_LOWHIGH); if(rsi_handle==INVALID_HANDLE) { Print(" Error in creating of iStochastic"); return(INIT_FAILED); } //--- indicator buffers mapping SetIndexBuffer(0,ExtMainBuffer,INDICATOR_DATA); SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA); SetIndexBuffer(2,ExtHighesBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(3,ExtLowesBuffer,INDICATOR_CALCULATIONS); //--- set accuracy IndicatorSetInteger(INDICATOR_DIGITS,2); //--- set levels IndicatorSetInteger(INDICATOR_LEVELS,2); IndicatorSetDouble(INDICATOR_LEVELVALUE,0,20); IndicatorSetDouble(INDICATOR_LEVELVALUE,1,80); //--- set maximum and minimum for subwindow IndicatorSetDouble(INDICATOR_MINIMUM,0); IndicatorSetDouble(INDICATOR_MAXIMUM,100); //--- name for DataWindow and indicator subwindow label IndicatorSetString(INDICATOR_SHORTNAME,Pair+" : "+"Stoch("+(string)InpKPeriod+","+(string)InpDPeriod+","+(string)InpSlowing+")"); PlotIndexSetString(0,PLOT_LABEL,"Main"); PlotIndexSetString(1,PLOT_LABEL,"Signal"); //--- sets first bar from what index will be drawn PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpKPeriod+InpSlowing-2); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpKPeriod+InpDPeriod); //--- 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 &tick_volume[], const long &volume[], const int &spread[]) { //--- CopyBuffer(rsi_handle,0,0,1000,ExtMainBuffer); CopyBuffer(rsi_handle,1,0,1000,ExtSignalBuffer); //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+