//+------------------------------------------------------------------+ //| SMA_1_en.mq5 | //| Copyright 2009, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ //---- Indicator's author #property copyright "2010, MetaQuotes Software Corp." //---- Author's web-site link #property link "http://www.mql5.com" //---- Indicator version number #property version "1.00" //---- Drawing the indicator in the main window #property indicator_chart_window //---- One buffer is used for calculating and drawing the indicator #property indicator_buffers 1 //---- Only one graphical plotting is used #property indicator_plots 1 //---- Drawing the indicator as line #property indicator_type1 DRAW_LINE //---- Red is used as indicator's line color #property indicator_color1 Red //---- Indicator line is continuous curve #property indicator_style1 STYLE_SOLID //---- Indicator line thickness is equal to 1 #property indicator_width1 1 //---- Displaying indicator's label #property indicator_label1 "SMA" //---- Input parameters of indicator input int MAPeriod=13; // Moving Average period input int MAShift=0; // Moving Average horizontal shift in bars //---- Declaration of dynamic array, which will be // used later as indicator buffer double ExtLineBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //----+ //---- Transformation of ExtLineBuffer dynamic array into indicator buffer SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA); //---- Horizontal shift of Moving Average by MAShift PlotIndexSetInteger(0,PLOT_SHIFT,MAShift); //---- Setting the position from which the drawing of indicator will start PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,MAPeriod); //---- Variable initialization for indicator's short name string shortname; StringConcatenate(shortname,"SMA(",MAPeriod,",",MAShift,")"); //--- Creating labels to display in Data Window PlotIndexSetString(0,PLOT_LABEL,shortname); //--- Creating name to display in a separate window and in tool-tip IndicatorSetString(INDICATOR_SHORTNAME,shortname); //--- Defining accuracy of displaying indicator's values IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //----+ } //+------------------------------------------------------------------+ //| 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 int begin, // beginning number of reliable count of bars const double &price[] // price array for indicator calculation ) { //----+ //---- Check if the number of bars is sufficient for calculation if(rates_total0) PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,begin+MAPeriod); } else first=prev_calculated-1; // Starting number for calculation of new bars //---- Main loop of indicator calculation for(bar=first; bar