Pon "Me gusta" y sigue las noticias
Deje un enlace a él, ¡qué los demás también lo valoren!
Evalúe su trabajo en el terminal MetaTrader 5
- Visualizaciones:
- 184
- Ranking:
- Publicado:
-
¿Necesita un robot o indicador basado en este código? Solicítelo en la bolsa freelance Pasar a la bolsa
He desarrollado este indicador para proporcionar una alternativa a los métodos estándar de media móvil en el indicador de MetaTrader 5 Bandas de Bollinger, que sólo ofrecen el método "simple". Con mi indicador, los usuarios tienen la opción de seleccionar entre métodos adicionales, incluyendo Exponencial, Suavizado, y LinearWeighted.
Para utilizar este indicador, es necesario colocarlo en un directorio (en Windows) parecido a la siguiente ruta:
C:\Usuarios\lucas\AppData\Roaming\MetaQuotes\Terminal\Indicadores\Examples
Características añadidas:

Se pone a cero por defecto:

Ejemplo de ejecución optando por la media de LinearWeighted:
CODE:
//+------------------------------------------------------------------+ //|BBPersonalizada.mq5 //|Lucas Vidal //|https://www.mql5.com //+------------------------------------------------------------------+ #property copyright "Lucas Vidal" #property link "https://www.mql5.com/es/users/lucasmoura00" #property description "Bollinger Bands Personalizada" #include <MovingAverages.mqh> //--- #property indicator_chart_window #property indicator_buffers 4 #property indicator_plots 3 #property indicator_type1 DRAW_LINE #property indicator_color1 LightSeaGreen #property indicator_type2 DRAW_LINE #property indicator_color2 LightSeaGreen #property indicator_type3 DRAW_LINE #property indicator_color3 LightSeaGreen #property indicator_label1 "Bands middle" #property indicator_label2 "Bands upper" #property indicator_label3 "Bands lower" //--- parámetros de entrada enum MovingAverageMethod { Simple, // 0 Exponential, // 1 Smoothed, // 2 LinearWeighted // 3 }; input MovingAverageMethod InpMaMethod = Simple; // Método da Média Móvel input int InpBandsPeriod=20; // Período input int InpBandsShift=0; // Turno input double InpBandsDeviations=2.0; // Desviación //--- variables globales int ExtBandsPeriod,ExtBandsShift; double ExtBandsDeviations; int ExtPlotBegin=0; //--- tampón indicador double ExtMLBuffer[]; double ExtTLBuffer[]; double ExtBLBuffer[]; double ExtStdDevBuffer[]; //+------------------------------------------------------------------+ //| Función de inicialización del indicador personalizada | //+------------------------------------------------------------------+ void OnInit() { //--- comprobar los valores de entrada if(InpBandsPeriod<2) { ExtBandsPeriod=20; PrintFormat("Incorrect value for input variable InpBandsPeriod=%d. Indicator will use value=%d for calculations.",InpBandsPeriod,ExtBandsPeriod); } else ExtBandsPeriod=InpBandsPeriod; if(InpBandsShift<0) { ExtBandsShift=0; PrintFormat("Incorrect value for input variable InpBandsShift=%d. Indicator will use value=%d for calculations.",InpBandsShift,ExtBandsShift); } else ExtBandsShift=InpBandsShift; if(InpBandsDeviations==0.0) { ExtBandsDeviations=2.0; PrintFormat("Incorrect value for input variable InpBandsDeviations=%f. Indicator will use value=%f for calculations.",InpBandsDeviations,ExtBandsDeviations); } else ExtBandsDeviations=InpBandsDeviations; //--- definir buffers SetIndexBuffer(0,ExtMLBuffer); SetIndexBuffer(1,ExtTLBuffer); SetIndexBuffer(2,ExtBLBuffer); SetIndexBuffer(3,ExtStdDevBuffer,INDICATOR_CALCULATIONS); //--- establecer etiquetas de índice PlotIndexSetString(0,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Middle"); PlotIndexSetString(1,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Upper"); PlotIndexSetString(2,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Lower"); //--- nombre del indicador IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands"); //--- indexes draw begin settings ExtPlotBegin=ExtBandsPeriod-1; PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod); //--- índices cambiar ajustes PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift); //--- número de dígitos del valor del indicador IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); } //+------------------------------------------------------------------+ //| Calcular Media Móvil| //+------------------------------------------------------------------+ double CalculateMovingAverage(int position, int period, const double &price[]) { switch(InpMaMethod) { case Simple: return SimpleMA(position, period, price); case Exponential: // Corrección de la función iMA con los parámetros correctos return iMA(NULL, 0, period, 0, MODE_EMA, PRICE_CLOSE); case Smoothed: // Implemente su función SMMA aquí break; case LinearWeighted: return LinearWeightedMA(position, period, price); } return 0; // Retorno padrón en caso de método indefinido } //+------------------------------------------------------------------+ //| Bandas de Bollinger| //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { if(rates_total<ExtPlotBegin) return(0); //--- los índices dibujan las configuraciones de inicio, cuando hemos recibido el inicio anterior if(ExtPlotBegin!=ExtBandsPeriod+begin) { ExtPlotBegin=ExtBandsPeriod+begin; PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPlotBegin); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtPlotBegin); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtPlotBegin); } //--- cálculo inicial int pos; if(prev_calculated>1) pos=prev_calculated-1; else pos=0; //--- ciclo principal for(int i=pos; i<rates_total && !IsStopped(); i++) { //--- línea media ExtMLBuffer[i]=CalculateMovingAverage(i, ExtBandsPeriod, price); //--- calcula y anota StdDev ExtStdDevBuffer[i]=StdDev_Func(i,price,ExtMLBuffer,ExtBandsPeriod); //--- línea superior ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i]; //--- línea inferior ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i]; } //--- OnCalculate hecho. Devuelve nuevo prev_calculado. return(rates_total); } //+------------------------------------------------------------------+ //| Calcular la desviación estándar| //+------------------------------------------------------------------+ double StdDev_Func(const int position,const double &price[],const double &ma_price[],const int period) { double std_dev=0.0; //--- calcualte StdDev if(position>=period) { for(int i=0; i<period; i++) std_dev+=MathPow(price[position-i]-ma_price[position],2.0); std_dev=MathSqrt(std_dev/period); } //--- devuelve el valor calculado return(std_dev); } //+------------------------------------------------------------------+
Traducción del inglés realizada por MetaQuotes Ltd.
Artículo original: https://www.mql5.com/en/code/49464
Geometric Moving Average
Versión MQL5 de la media móvil geométrica.
Get Nth Active Trade from the end in MT5
Este EA escaneará todas las operaciones abiertas y luego imprimirá la enésima operación desde el final
OHLC Candles with Ask and Bid
Un gráfico de velas que relaciona el precio de compra y el precio de venta con el máximo y el mínimo de las velas.
Simples_Tres_Interiores_EA
Un simple Asesor Experto que opera cuando el precio forma el patrón "Three From Within".

