Exibir indicador personalizado

 

Boa tarde eu personalizei um indicador existente, porém ao adicionar ao MT5 o indicador nao é exibido na janela.


//+------------------------------------------------------------------+

//|                                                           MR.mq5 |

//|                                                 Alexandre Jùnior |

//|                                              http://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright   "Alexandre Júnior"

#property link        "http://www.mql5.com"

#property version     "1.00"

#property description "Média Rápida"

#include <MovingAverages.mqh>


#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   1

//--- plot ExtMRBuffer

#property indicator_label1  "MR"

#property indicator_type1   DRAW_LINE

#property indicator_color1  Yellow

#property indicator_style1  STYLE_SOLID

#property indicator_width1  2

//--- default applied price

#property indicator_applied_price PRICE_CLOSE

//--- input parameters

input int InpPeriodMR=8;      // MR period

input int InpShiftMR=0;        // MR shift

//--- indicator buffer

double    ExtMRBuffer[];

double    ExtMRBuffer2[];



double    ExtFastSC;

int       ExtPeriodMR;

int       InpMRPeriod;

int       ExtMRPeriod;

//+------------------------------------------------------------------+

//| MR initialization function                                      |

//+------------------------------------------------------------------+

void OnInit()

  {

//--- check for input values

   if(InpPeriodMR<=0)

     {

      ExtPeriodMR=17;

      PrintFormat("Input parameter InpPeriodMR has incorrect value (%d). Indicator will use value %d for calculations.",

                  InpPeriodMR,ExtPeriodMR);

     }

   else

      ExtPeriodMR=InpPeriodMR;

      

//--- indicator buffers mapping

   SetIndexBuffer(0,ExtMRBuffer,INDICATOR_DATA);

//--- set accuracy

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);

//--- sets first bar from what index will be drawn

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodMR);

//--- set index shift

   PlotIndexSetInteger(0,PLOT_SHIFT,InpShiftMR);

//--- set shortname and change label

   string short_name=StringFormat("MR(%d)",ExtPeriodMR);

   IndicatorSetString(INDICATOR_SHORTNAME,short_name);

   PlotIndexSetString(0,PLOT_LABEL,short_name);


  }

//+------------------------------------------------------------------+

//| AMA iteration function                                           |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const int begin,

                const double &price[])

  {

   int i;

//--- check for rates count

   if(rates_total<ExtPeriodMR+begin)

      return(0);

//--- draw begin may be corrected

   if(begin!=0)

      PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodMR+begin);

//--- detect position

   int pos=prev_calculated-1;

//--- first calculations

   if(pos<ExtPeriodMR+begin)

     {

      pos=ExtPeriodMR+begin;

      for(i=0; i<pos-1; i++)

         ExtMRBuffer[i]=0.0;

      ExtMRBuffer[pos-1]=price[pos-1];

     }

//--- main cycle

   for(i=pos; i<rates_total && !IsStopped(); i++)

     { 

      //--- calculate MR

      if(i==InpMRPeriod-1)

               ExtMRBuffer[i]=SimpleMA(i,InpMRPeriod,price);

            else

               ExtMRBuffer[i]=ExponentialMA(i,InpMRPeriod,ExtMRBuffer[i-1],price);

            //--- Calculate StdDev

            ExtMRBuffer2[i]=StdDevFunc(price,ExtMRBuffer,i);

           }

     

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

//| Calculate DESV value                                               |

//+------------------------------------------------------------------+

double StdDevFunc(const double &price[],const double &ma_price[],const int position)

  {

   double dev=0.0;

   for(int i=0; i<ExtMRPeriod; i++)

      dev+=MathPow(price[position-i]-ma_price[position],2.0);

   dev=MathSqrt(dev/ExtMRPeriod);

   return(dev);

  }

//+------------------------------------------------------------------+


Descubra novos recursos para o MetaTrader 5 com a comunidade e os serviços MQL5
Descubra novos recursos para o MetaTrader 5 com a comunidade e os serviços MQL5
  • www.mql5.com
One Click Close The script allows users to easily close positions if their profit/loss reaches or exceeds a value specified in pips. Please set slippage value first. Sometimes some positions do not close due to high volatility of the market. Please set larger slippage or restart the script. The free demo version is: ...
Razão: