//+------------------------------------------------------------------+ //| Stochastic_HTF.mq5 | //| Copyright © 2007, Christof Risch (Iya) | //| http://www.forexfactory.com/showthread.php?t=30109 | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, Christof Risch (iya)" #property link "http://www.forexfactory.com/showthread.php?t=30109" #property description "Stochastic indicator from any timeframe" //--- Indicator version number #property version "1.00" //--- The indicator is drawn in a separate window #property indicator_separate_window //--- 2 buffers are used for the indicator calculation and drawing #property indicator_buffers 2 //--- 2 graphical constructions are used #property indicator_plots 2 //+----------------------------------------------+ //| Parameters for the bearish indicator | //+----------------------------------------------+ //--- Indicator 1 is drawn as a line #property indicator_type1 DRAW_SECTION //--- Red is used for the indicator color #property indicator_color1 clrRed //--- The width of the indicator 1 is 1 #property indicator_width1 1 //--- The indicator label #property indicator_label1 "Main Stochastic" //+----------------------------------------------+ //| Parameters for the bullish indicator | //+----------------------------------------------+ //--- Indicator 2 is drawn as a line #property indicator_type2 DRAW_SECTION //--- Blue is used for the indicator color #property indicator_color2 clrBlue //--- The width of the indicator 2 is 1 #property indicator_width2 1 //--- The indicator label #property indicator_label2 "Signal Stochastic" //+----------------------------------------------+ //| Parameters of horizontal lines | //+----------------------------------------------+ #property indicator_level1 +75 #property indicator_level2 +50 #property indicator_level3 +25 #property indicator_levelcolor clrGray #property indicator_levelstyle STYLE_DASHDOTDOT //+----------------------------------------------+ //| Limit on the height of the indicator window | //+----------------------------------------------+ #property indicator_minimum 0 #property indicator_maximum 100 //+----------------------------------------------+ //| Declaring constants | //+----------------------------------------------+ #define RESET 0 // A constant for returning an indicator recalculation command to the terminal //+----------------------------------------------+ //| Indicator input parameters | //+----------------------------------------------+ input ENUM_TIMEFRAMES TimeFrame=PERIOD_H6; // Chart period for the iSAR indicator input int KPeriod=5; input int DPeriod=3; input int Slowing=3; input ENUM_MA_METHOD MA_Method=MODE_SMA; input ENUM_STO_PRICE Price_field=STO_LOWHIGH; //+----------------------------------------------+ //--- declaring dynamic arrays that will further be used as indicator buffers double Line1Buffer[]; double Line2Buffer[]; //--- declaring a variable for storing the indicator initialization result bool Init; string Symbol_; //--- declaring integer variables for the indicator handles int STO_Handle; //--- declaring integer variables of the start of data calculation int min_rates_total; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { Init=true; //--- checking correctness of the chart periods if(TimeFramerates_total || prev_calculated<=0)// checking for the first start of calculation of an indicator { limit=rates_total-min_rates_total-2; // starting index for the calculation of all bars LastCountBar=limit; } else limit=int(LastCountBar)+rates_total-prev_calculated; // starting index for the calculation of new bars //--- indexing elements in arrays as in timeseries ArraySetAsSeries(time,true); //--- main cycle of calculation of the indicator for(bar=limit; bar>=0 && !IsStopped(); bar--) { //--- ÿero out the contents of the indicator buffers for the calculation Line1Buffer[bar]=EMPTY_VALUE; Line2Buffer[bar]=EMPTY_VALUE; //--- ñopy new data to the iTime array if(CopyTime(Symbol_,TimeFrame,time[bar],1,iTime)<=0) return(RESET); //--- if(time[bar]>=iTime[0] && time[bar+1]