//+------------------------------------------------------------------+ //| StepMA_Stoch_KV1.mq5 | //| Copyright © 2005, TrendLaboratory Ltd. | //| E-mail: igorad2004@list.ru | //| modified by Kalenzo -> simone@konto.pl | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005, TrendLaboratory Ltd." #property link "E-mail: igorad2004@list.ru" //---- Indicator version number #property version "1.02" //---- drawing indicator in a separate window #property indicator_separate_window //---- number of indicator buffers 2 #property indicator_buffers 2 //---- only one plot is used #property indicator_plots 1 //+-----------------------------------+ //| Parameters of indicator drawing | //+-----------------------------------+ //---- drawing the indicator as a seven-color histogram #property indicator_type1 DRAW_COLOR_HISTOGRAM //---- colors of the seven-color histogram are as follows #property indicator_color1 clrMagenta,clrMediumVioletRed,clrPlum,clrGray,clrLightSkyBlue,clrTeal,clrDodgerBlue //---- Indicator line is a solid one #property indicator_style1 STYLE_SOLID //---- indicator line width is 2 #property indicator_width1 2 //---- displaying the indicator label #property indicator_label1 "StepMA_Stoch_KV1" //+-----------------------------------+ //| INDICATOR INPUT PARAMETERS | //+-----------------------------------+ input uint PeriodWATR=10; input double Kwatr=1.0000; input bool HighLow=false; //+-----------------------------------+ //---- declaration of dynamic arrays that // will be used as indicator buffers double IndBuffer[],ColorIndBuffer[]; //---- Declaration of integer variables of data starting point int min_rates_total; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization of variables of the start of data calculation min_rates_total=int(PeriodWATR+1); //---- Set IndBuffer dynamic array as an indicator buffer SetIndexBuffer(0,IndBuffer,INDICATOR_DATA); //---- Indexing elements in the buffer as in timeseries ArraySetAsSeries(IndBuffer,true); //---- Setting a dynamic array as a color index buffer SetIndexBuffer(1,ColorIndBuffer,INDICATOR_COLOR_INDEX); //---- Indexing elements in the buffer as in timeseries ArraySetAsSeries(ColorIndBuffer,true); //---- Performing the shift of beginning of indicator drawing PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); //---- Setting the indicator values that won't be visible on a chart PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); //--- creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,"StepMA_Stoch_KV1"); //--- determining the accuracy of the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //---- initialization end } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate( const int rates_total, // amount of history in bars at the current tick const int prev_calculated,// amount of history in bars at the previous tick 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[] ) { //---- checking the number of bars to be enough for calculation if(rates_totalrates_total || prev_calculated<=0)// checking for the first start of calculation of an indicator { limit=rates_total-min_rates_total-1; // starting index for the calculation of all bars bar=limit; SumRange=0; for(int iii=0; iii=0 && !IsStopped(); bar--) { SumRange=0; for(int iii=0; iiiSmaxMin1) TrendMin=+1; if(close[bar]SmaxMax1) TrendMax=+1; if(close[bar]SmaxMid1) TrendMid=+1; if(close[bar]SmaxMin1) TrendMin=+1; if(close[bar]SmaxMax1) TrendMax=+1; if(close[bar]SmaxMid1) TrendMid=+1; if(close[bar]0 && SminMin0SmaxMin1) SmaxMin0=SmaxMin1; if(TrendMax>0 && SminMax0SmaxMax1) SmaxMax0=SmaxMax1; if(TrendMid>0 && SminMid0SmaxMid1) SmaxMid0=SmaxMid1; if(TrendMin>0) linemin=SminMin0+StepSizeMin*_Point; if(TrendMin<0) linemin=SmaxMin0-StepSizeMin*_Point; if(TrendMax>0) linemax=SminMax0+StepSizeMax*_Point; if(TrendMax<0) linemax=SmaxMax0-StepSizeMax*_Point; if(TrendMid>0) linemid=SminMid0+StepSizeMid*_Point; if(TrendMid<0) linemid=SmaxMid0-StepSizeMid*_Point; //---- bsmin=linemax-StepSizeMax*_Point; bsmax=linemin+StepSizeMax*_Point; double res=bsmax-bsmin; if(!res) res=0.00000001; Stoch1=NormalizeDouble((linemin-bsmin)/res,6); Stoch2=NormalizeDouble((linemid-bsmin)/res,6); IndBuffer[bar]=Stoch1-Stoch2; //---- if(bar) { SminMin1=SminMin0; SmaxMin1=SmaxMin0; SminMax1=SminMax0; SmaxMax1=SmaxMax0; SminMid1=SminMid0; SmaxMid1=SmaxMid0; WATRmax_=WATRmax; WATRmin_=WATRmin; TrendMin1=TrendMin; TrendMax1=TrendMax; TrendMid1=TrendMid; } } if(prev_calculated>rates_total || prev_calculated<=0) limit--; //---- Main indicator coloring loop for(bar=limit; bar>=0 && !IsStopped(); bar--) { int clr=3; if(IndBuffer[bar]>0) { if(IndBuffer[bar]>IndBuffer[bar+1]) clr=6; if(IndBuffer[bar]==IndBuffer[bar+1]) clr=5; if(IndBuffer[bar]IndBuffer[bar+1]) clr=2; } ColorIndBuffer[bar]=clr; } //---- return(rates_total); } //+------------------------------------------------------------------+