//+------------------------------------------------------------------+ //| SR-RateIndicator.mq5 | ///| Copyright © 2007, Tinytjan | //| tinytjan@mail.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, Tinytjan" #property link "tinytjan@mail.ru" //---- indicator version number #property version "1.00" //---- 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 //+-----------------------------------+ //| Indicator drawing parameters | //+-----------------------------------+ //---- drawing the indicator as a four-color histogram #property indicator_type1 DRAW_COLOR_HISTOGRAM //---- colors of the four-color histogram are as follows #property indicator_color1 clrMagenta,clrPurple,clrGray,clrTeal,clrChartreuse //---- indicator line is a solid one #property indicator_style1 STYLE_SOLID //---- Indicator line width is equal to 2 #property indicator_width1 2 //---- displaying the indicator label #property indicator_label1 "SR-Rate" //+-----------------------------------+ //| INDICATOR INPUT PARAMETERS | //+-----------------------------------+ input uint WindowSize=20; //window width input int inHighLevel=+20; input int inLowLevel=-20; //+-----------------------------------+ //---- Declaration of integer variables of data starting point int min_rates_total; //---- declaration of dynamic arrays that will further be // used as indicator buffers double IndBuffer[],ColorIndBuffer[]; //+------------------------------------------------------------------+ //| Gauss algorithm description | //+------------------------------------------------------------------+ #include //+------------------------------------------------------------------+ //| Solar Winds indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization of variables of the start of data calculation min_rates_total=int(WindowSize); BuffersInit(); //---- set IndBuffer dynamic array as an indicator buffer SetIndexBuffer(0,IndBuffer,INDICATOR_DATA); //---- performing the shift of beginning of indicator drawing PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total+1); //---- setting the indicator values that won't be visible on a chart PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); //---- indexing elements in the buffer as time series ArraySetAsSeries(IndBuffer,true); //---- setting dynamic array as a color index buffer SetIndexBuffer(1,ColorIndBuffer,INDICATOR_COLOR_INDEX); //---- indexing elements in the buffer as time series ArraySetAsSeries(ColorIndBuffer,true); //--- creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,"SR-Rate Indicator"); //--- determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,0); //---- the number of the indicator 2 horizontal levels IndicatorSetInteger(INDICATOR_LEVELS,2); //---- values of the indicator horizontal levels IndicatorSetDouble(INDICATOR_LEVELVALUE,0,inHighLevel); IndicatorSetDouble(INDICATOR_LEVELVALUE,1,inLowLevel); //---- magenta and blue colors are used for horizontal levels lines IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,clrMagenta); IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,clrBlue); //---- short dot-dash is used for the horizontal level line IndicatorSetInteger(INDICATOR_LEVELSTYLE,0,STYLE_DASHDOTDOT); IndicatorSetInteger(INDICATOR_LEVELSTYLE,1,STYLE_DASHDOTDOT); //---- end of initialization } //+------------------------------------------------------------------+ //| Solar Winds iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // number of bars in history 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[], // price array of price maximums for the indicator calculation const double& low[], // price array of minimums of price for the indicator calculation const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //---- Checking if the number of bars is sufficient for the calculation if(rates_totalrates_total || prev_calculated<=0)// checking for the first start of the indicator calculation { limit=rates_total-min_rates_total; // starting index for calculation of all bars IndBuffer[limit+1]=0.0; } else limit=rates_total-prev_calculated; // starting index for calculation of new bars //---- indexing elements in arrays as time series ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(open,true); ArraySetAsSeries(close,true); //---- main loop of the indicator calculation for(bar=limit; bar>=0 && !IsStopped(); bar--) { Max=0; Min=999999999; for(int kkk=bar; kkkMax) Max=shigh; } Range=Max-Min; if(Range) res=200*(Smooth_5(rates_total,PRICE_WEIGHTED,bar,open,low,high,close)-Min)/Range-100.0; else res=0.0; IndBuffer[bar]=res; clr=2; if(res>0) { if(res>inHighLevel) clr=4; else clr=3; } if(res<0) { if(res