//+------------------------------------------------------------------+ //| ColorStochastic_HTF.mq5 | //| Copyright © 2012, Nikolay Kositsin | //| Khabarovsk, farria@mail.redcom.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2012, Nikolay Kositsin" #property link "farria@mail.redcom.ru" #property description "Stochastic oscillator with a choice of a fixed timeframe" //--- indicator version number #property version "1.00" //--- drawing indicator in a separate window #property indicator_separate_window //--- number of indicator buffers 4 #property indicator_buffers 4 //--- only two plots are used #property indicator_plots 2 //+----------------------------------------------+ //| Parameters of displaying horizontal levels | //+----------------------------------------------+ #property indicator_level1 70.0 #property indicator_level2 50.0 #property indicator_level3 30.0 #property indicator_levelcolor Violet #property indicator_levelstyle STYLE_DASHDOTDOT //+-----------------------------------+ //| Indicator 1 drawing parameters | //+-----------------------------------+ //--- drawing the indicator 1 as a cloud #property indicator_type1 DRAW_FILLING //--- the following colors are used in the histogram #property indicator_color1 Teal,MediumVioletRed //--- displaying the indicator label #property indicator_label1 "Stochastic HTF" //+-----------------------------------+ //| Indicator 2 drawing parameters | //+-----------------------------------+ //--- drawing indicator as a three-colored line #property indicator_type2 DRAW_COLOR_LINE //--- the following colors are used for the indicator line #property indicator_color2 Gray,Lime,Magenta //--- the indicator line is a stroke #property indicator_style2 STYLE_SOLID //--- indicator line width is equal to 5 #property indicator_width2 5 //--- displaying the indicator label #property indicator_label2 "Signal line" //+-----------------------------------+ //| Declaration of constants | //+-----------------------------------+ #define RESET 0 // the constant for getting the command for the indicator recalculation back to the terminal //+-----------------------------------+ //| Indicator input parameters | //+-----------------------------------+ input ENUM_TIMEFRAMES TimeFrame=PERIOD_H4; // Chart period input int InpKPeriod=5; // K period input int InpDPeriod=3; // D period input int InpSlowing=3; // Slowing input ENUM_MA_METHOD ma_method=MODE_SMA; // Smoothing type input ENUM_STO_PRICE price_field=STO_LOWHIGH; // Stochastic calculation method //+-----------------------------------+ //--- declaration of dynamic arrays that further //--- will be used as indicator buffers double UpStochastic[],DnStochastic[]; double StochSignal[],ColorStochSignal[]; //--- declaration of a variable for storing the indicator initialization result bool Init; //--- declaration of the integer variables for the start of data calculation int min_rates_total; //--- declaration of integer variables for the indicators handles int Stochastic_Handle; //+------------------------------------------------------------------+ //| Getting string timeframe | //+------------------------------------------------------------------+ string GetStringTimeframe(ENUM_TIMEFRAMES timeframe) { //--- return(StringSubstr(EnumToString(timeframe),7,-1)); //--- } //+------------------------------------------------------------------+ //| Stochastic indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- initialization of variables of the start of data calculation min_rates_total=3; 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-1; // starting index for calculation of all bars LastCountBar=rates_total; } else limit=int(LastCountBar)+rates_total-prev_calculated; // starting index for calculation of new bars //--- indexing elements in arrays as timeseries ArraySetAsSeries(time,true); //--- Main cycle of calculation of the indicator for(bar=limit; bar>=0 && !IsStopped(); bar--) { //--- zero out the contents of the indicator buffers for calculation UpStochastic[bar]=EMPTY_VALUE; DnStochastic[bar]=EMPTY_VALUE; StochSignal[bar]=EMPTY_VALUE; ColorStochSignal[bar]=0; //--- copy newly appeared data in the array if(CopyTime(Symbol(),TimeFrame,time[bar],1,StochasticTime)<=0) return(RESET); if(time[bar]>=StochasticTime[0] && time[bar+1]50) UpStochastic[bar]=Stoch[1]; if(Stoch[1]<50) UpStochastic[bar]=Stoch[1]; //--- if(Stoch[1]>StochSignal[bar]) ColorStochSignal[bar]=1; if(Stoch[1]