//+------------------------------------------------------------------+ //| Satl.mq5 | //| Copyright 2002, Finware.ru Ltd. | //| http://www.finware.ru/ | //+------------------------------------------------------------------+ //---- author of the indicator #property copyright "Copyright 2002, Finware.ru Ltd." //---- link to the website of the author #property link "http://www.finware.ru/" //---- indicator version #property version "1.00" //---- drawing the indicator in the main window #property indicator_chart_window //---- one buffer is used for calculation and drawing of the indicator #property indicator_buffers 1 //---- only one plot is used #property indicator_plots 1 //---- drawing the indicator as a line #property indicator_type1 DRAW_LINE //---- red color is used as the color of the indicator line #property indicator_color1 Red //---- the indicator line is a continuous curve #property indicator_style1 STYLE_SOLID //---- indicator line width is equal to 2 #property indicator_width1 2 //---- displaying the indicator label #property indicator_label1 "SATL" //---- indicator input parameters input int SATLShift=0; //Horizontal shift of the average in bars //---- declaration and initialization of a variable for storing the number of calculated bars int SATLPeriod=65; //---- declaration of a dynamic array that //will be used as an indicator buffer double ExtLineBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //----+ //---- set ExtLineBuffer dynamic array as indicator buffer SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA); //---- shifting the indicator horizontally by SATLShift PlotIndexSetInteger(0,PLOT_SHIFT,SATLShift); //---- set the position, from which the indicator drawing starts PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,SATLPeriod); //---- initializations of a variable for the indicator short name string shortname; StringConcatenate(shortname,"SATL(",SATLShift,")"); //---- create label to display in Data Window PlotIndexSetString(0,PLOT_LABEL,shortname); //---- creating a name for displaying in a separate sub-window and in a tooltip IndicatorSetString(INDICATOR_SHORTNAME,shortname); //---- determination of accuracy of displaying of the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //---- restriction to draw empty values for the indicator PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); //----+ } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // number of bars in history at the current tick const int prev_calculated, // number of bars calculated at previous call const int begin, // bars reliable counting beginning index const double &price[] // price array for calculation of the indicator ) { //----+ //---- checking the number of bars to be enough for the calculation if(rates_totalrates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator { first=SATLPeriod-1+begin; // starting index for calculation of all bars //---- increase the position of the beginning of data by 'begin' bars as a result of calculation using data of another indicator if(begin>0) PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,begin+SATLPeriod); } else first=prev_calculated-1; // starting index for calculation of new bars //---- main indicator calculation loop for(bar=first; bar