//+------------------------------------------------------------------+ //| SafeZoneV2.mq5 | //| Copyright © 2009, CoreWinTT | //| | //+------------------------------------------------------------------+ //---- author of the indicator #property copyright "Copyright © 2009, CoreWinTT" //---- author of the indicator #property link "" //---- indicator version number #property version "1.00" //---- drawing the indicator in the main window #property indicator_chart_window //---- two buffers are used for the indicator calculation and drawing #property indicator_buffers 2 //---- two plots are used #property indicator_plots 2 //+----------------------------------------------+ //| Indicator 1 drawing parameters | //+----------------------------------------------+ //---- drawing indicator 1 as a line #property indicator_type1 DRAW_LINE //---- red color is used as the color of the bullish line of the indicator #property indicator_color1 Red //---- line of the indicator 1 is a continuous curve #property indicator_style1 STYLE_SOLID //---- thickness of line of the indicator 1 is equal to 1 #property indicator_width1 1 //---- displaying of the bullish label of the indicator #property indicator_label1 "Upper SafeZoneV2" //+----------------------------------------------+ //| Indicator 2 drawing parameters | //+----------------------------------------------+ //---- drawing the indicator 2 as a line #property indicator_type2 DRAW_LINE //---- blue color is used for the indicator bearish line #property indicator_color2 Blue //---- the indicator 2 line is a continuous curve #property indicator_style2 STYLE_SOLID //---- indicator 2 line width is equal to 1 #property indicator_width2 1 //---- displaying of the bearish label of the indicator #property indicator_label2 "Lower SafeZoneV2" //+----------------------------------------------+ //| Indicator input parameters | //+----------------------------------------------+ input uint Median=10; input uint Max=52; input uint MASAFE=3; input int Shift=0; // horizontal shift of the indicator in bars //+----------------------------------------------+ //---- declaration of dynamic arrays that will further be // used as indicator buffers double DnBuffer[]; double UpBuffer[]; //---- Declaration of integer variables of data starting point int min_rates_total; //---- declaration of dynamic arrays that will further be // used as ring buffers int Count[]; double SRange[]; //+------------------------------------------------------------------+ // CMoving_Average class description | //+------------------------------------------------------------------+ #include //+------------------------------------------------------------------+ //| recalculation of position of a newest element in the array | //+------------------------------------------------------------------+ void Recount_ArrayZeroPos ( int &CoArr[]// Return the current value of the price series by the link ) // Recount_ArrayZeroPos(count, Length) //+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+ { //---- int numb,Max1,Max2; static int count=1; Max2=int(Max); Max1=Max2-1; count--; if(count<0) count=Max1; for(int iii=0; iiiMax1) numb-=Max2; CoArr[iii]=numb; } //---- } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization of variables of the start of data calculation min_rates_total=int(Median+Max+MASAFE); //---- memory distribution for variables' arrays ArrayResize(Count,Max); ArrayResize(SRange,Max); //---- indexing elements in the buffer as time series ArraySetAsSeries(SRange,true); //---- Initialization of arrays of variables ArrayInitialize(SRange,0.0); //---- set dynamic array as an indicator buffer SetIndexBuffer(0,DnBuffer,INDICATOR_DATA); //---- shifting indicator 1 horizontally by Shift PlotIndexSetInteger(0,PLOT_SHIFT,Shift); //---- shifting the starting point for drawing indicator 1 by min_rates_total PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); //---- set dynamic array as an indicator buffer SetIndexBuffer(1,UpBuffer,INDICATOR_DATA); //---- shifting the indicator 2 horizontally by Shift PlotIndexSetInteger(1,PLOT_SHIFT,Shift); //---- shifting the starting point for drawing indicator 2 by min_rates_total PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total); //---- initializations of variable for indicator short name string shortname; StringConcatenate(shortname,"SafeZoneV2(",Median,", ",Max,", ",MASAFE,", ",Shift,")"); //--- creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,shortname); //--- determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //---- } //+------------------------------------------------------------------+ //| 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[], // price array of maximums of price for the calculation of indicator const double& low[], // price array of price lows for the indicator calculation 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 { first=0; // starting number for calculation of all bars } else first=prev_calculated-min_rates_total; // стартовый номер для расчёта новых баров //---- declaration of the CMoving_Average class variables from the SmoothAlgorithms.mqh file static CMoving_Average SMA,SMAH,SMAL; //---- main indicator calculation loop for(bar=first; bar