Rejoignez notre page de fans
- Vues:
- 107
- Note:
- Publié:
-
Besoin d'un robot ou d'un indicateur basé sur ce code ? Commandez-le sur Freelance Aller sur Freelance
J'ai développé cet indicateur pour fournir une alternative aux méthodes de moyenne mobile standard de l'indicateur Bollinger Bands de MetaTrader 5, qui n'offrent que la méthode "simple". Avec mon indicateur, les utilisateurs ont la possibilité de sélectionner des méthodes supplémentaires, notamment Exponentielle, Lissée et Linéaire pondérée.
Pour utiliser cet indicateur, vous devez le placer dans un répertoire (sous Windows) qui ressemble au chemin suivant :
C:\NUsers\NLucas\NAppData\NRoaming\NMetaQuotes\NTerminal\NIndicateurs\NExemples
Fonctionnalités ajoutées :

Il est fixé à zéro par défaut :

Exemple d'exécution optant pour la moyenne de LinearWeighted :
CODE :
//+------------------------------------------------------------------+ //|BBPersonalizada.mq5 | //|Lucas Vidal //|https ://www.mql5.com //+------------------------------------------------------------------+ #property copyright "Lucas Vidal" #property link "https://www.mql5.com/fr/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" //--- paramètres d'entrée enum MovingAverageMethod { Simple, // 0 Exponential, // 1 Smoothed, // 2 LinearWeighted // 3 }; input MovingAverageMethod InpMaMethod = Simple; // Méthode d'évaluation des médias input int InpBandsPeriod=20; // Période input int InpBandsShift=0; // Shift input double InpBandsDeviations=2.0; // Écart //--- variables globales int ExtBandsPeriod,ExtBandsShift; double ExtBandsDeviations; int ExtPlotBegin=0; //--- tampon de l'indicateur double ExtMLBuffer[]; double ExtTLBuffer[]; double ExtBLBuffer[]; double ExtStdDevBuffer[]; //+------------------------------------------------------------------+ //| Fonction d'initialisation de l'indicateur personnalisé //+------------------------------------------------------------------+ void OnInit() { //--- vérification des valeurs d'entrée 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; //--- définir les tampons SetIndexBuffer(0,ExtMLBuffer); SetIndexBuffer(1,ExtTLBuffer); SetIndexBuffer(2,ExtBLBuffer); SetIndexBuffer(3,ExtStdDevBuffer,INDICATOR_CALCULATIONS); //--- définir les étiquettes d'index PlotIndexSetString(0,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Middle"); PlotIndexSetString(1,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Upper"); PlotIndexSetString(2,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Lower"); //--- nom de l'indicateur IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands"); //--- index draw begin settings ExtPlotBegin=ExtBandsPeriod-1; PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod); //--- indexe les paramètres de changement PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift); //--- nombre de chiffres de la valeur de l'indicateur IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); } //+------------------------------------------------------------------+ //| Calculer la moyenne mobile| //+------------------------------------------------------------------+ double CalculateMovingAverage(int position, int period, const double &price[]) { switch(InpMaMethod) { case Simple: return SimpleMA(position, period, price); case Exponential: // Corriger le champ de la fonction iMA avec les paramètres corrigés return iMA(NULL, 0, period, 0, MODE_EMA, PRICE_CLOSE); case Smoothed: // Implémentez votre fonction SMMA ici break; case LinearWeighted: return LinearWeightedMA(position, period, price); } return 0; // Retorno padrão em caso de método indefinido } //+------------------------------------------------------------------+ //| Bandes de Bollinger| //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { if(rates_total<ExtPlotBegin) return(0); //--- les index tirent les paramètres de début, lorsque nous avons reçu les paramètres de début précédents 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); } //--- calcul de départ int pos; if(prev_calculated>1) pos=prev_calculated-1; else pos=0; //--- cycle principal for(int i=pos; i<rates_total && !IsStopped(); i++) { //--- ligne du milieu ExtMLBuffer[i]=CalculateMovingAverage(i, ExtBandsPeriod, price); //--- calculer et noter StdDev ExtStdDevBuffer[i]=StdDev_Func(i,price,ExtMLBuffer,ExtBandsPeriod); //--- ligne supérieure ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i]; //--- ligne inférieure ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i]; } //--- OnCalcul fait. Retourne le nouveau prev_calculated. return(rates_total); } //+------------------------------------------------------------------+ //| Calculer l'écart type| //+------------------------------------------------------------------+ double StdDev_Func(const int position,const double &price[],const double &ma_price[],const int period) { double std_dev=0.0; //--- calcule 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); } //--- renvoie la valeur calculée return(std_dev); } //+------------------------------------------------------------------+
Traduit de l’anglais par MetaQuotes Ltd.
Code original : https://www.mql5.com/en/code/49464
Geometric Moving Average
Version MQL5 de la moyenne mobile géométrique.
X2MA_KLx3_Cloud
Le canal de Keltner, représenté par un fond coloré.
FisherTransform_HTF_Signal
L'indicateur FisherTransform_HTF_Signal affiche la direction de la tendance sous la forme d'un objet graphique avec une indication de tendance en couleur et émet des alertes ou des signaux sonores lorsque la tendance change.
^X_NonLinearRegression
Canal de régression non linéaire avec interpolation des valeurs futures du graphique des prix.

