Schau, wie man Roboter kostenlos herunterladen kann
Finden Sie uns auf Facebook!
und werden Sie Mitglied unserer Fangruppe
Interessantes Skript?
Veröffentliche einen Link auf das Skript, damit die anderen ihn auch nutzen können
Hat Ihnen das Skript gefallen?
Bewerten Sie es im Terminal MetaTrader 5
Ansichten:
133
Rating:
(6)
Veröffentlicht:
MQL5 Freelance Benötigen Sie einen Roboter oder Indikator, der auf diesem Code basiert? Bestellen Sie ihn im Freelance-Bereich Zum Freelance

Ich habe diesen Indikator entwickelt, um eine Alternative zu den Standardmethoden des gleitenden Durchschnitts im MetaTrader 5 Bollinger Bands Indikator zu bieten, die nur die "einfache" Methode anbieten. Mit meinem Indikator haben die Benutzer die Möglichkeit, aus zusätzlichen Methoden wie Exponential, Smoothed und LinearWeighted zu wählen.

Um diesen Indikator zu verwenden, müssen Sie ihn in einem Verzeichnis (unter Windows) ablegen, das dem folgenden Pfad entspricht:

C:\Benutzer\lucas\AppData\Roaming\MetaQuotes\Terminal\Indicators\Examples

Zusätzliche Funktionen:

eine


Er ist standardmäßig auf Null gesetzt:

zwei


Beispiel für eine Ausführung, die sich für den Durchschnitt von LinearWeighted entscheidet:


Baum vier


CODE:

//+------------------------------------------------------------------+
//|BBPersonalizada.mq5 |
//|Lucas Vidal |
//|https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "Lucas Vidal"
#property link        "https://www.mql5.com/de/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"
//--- Eingabe-Parameter
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;       // Zeitraum
input int     InpBandsShift=0;         // Verschiebung
input double  InpBandsDeviations=2.0;  // Abweichung
//--- globale Variablen
int           ExtBandsPeriod,ExtBandsShift;
double        ExtBandsDeviations;
int           ExtPlotBegin=0;
//--- Indikatorpuffer
double        ExtMLBuffer[];
double        ExtTLBuffer[];
double        ExtBLBuffer[];
double        ExtStdDevBuffer[];
//+------------------------------------------------------------------+
//| Benutzerdefinierte Initialisierungsfunktion für Indikatoren |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- Prüfung auf Eingabewerte
   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;
//--- Puffer definieren
   SetIndexBuffer(0,ExtMLBuffer);
   SetIndexBuffer(1,ExtTLBuffer);
   SetIndexBuffer(2,ExtBLBuffer);
   SetIndexBuffer(3,ExtStdDevBuffer,INDICATOR_CALCULATIONS);
//--- Indexbezeichnungen festlegen
   PlotIndexSetString(0,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Middle");
   PlotIndexSetString(1,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Upper");
   PlotIndexSetString(2,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Lower");
//--- Name des Indikators
   IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands");
//--- Indizes zeichnen beginnen Einstellungen
   ExtPlotBegin=ExtBandsPeriod-1;
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod);
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod);
//--- Indizes verschieben Einstellungen
   PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift);
   PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift);
   PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift);
//--- Anzahl der Ziffern des Indikatorwerts
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
  }
//+------------------------------------------------------------------+
//| Gleitender Durchschnitt berechnen|
//+------------------------------------------------------------------+
double CalculateMovingAverage(int position, int period, const double &price[]) {
    switch(InpMaMethod) {
        case Simple:
            return SimpleMA(position, period, price);
        case Exponential:
            // Korrigieren eines Kamas der Funktion iMA mit den richtigen Parametern
            return iMA(NULL, 0, period, 0, MODE_EMA, PRICE_CLOSE);
        case Smoothed:
            // Implemente sua função SMMA aqui
            break;
        case LinearWeighted:
            return LinearWeightedMA(position, period, price);
    }
    return 0; // Retorno padrão em caso de método indefinido
}

//+------------------------------------------------------------------+
//| Bollinger-Bänder|
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   if(rates_total<ExtPlotBegin)
      return(0);
//--- Indizes zeichnen Anfangseinstellungen, wenn wir vorherige Anfangseinstellungen erhalten haben
   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);
     }
//--- Beginn der Berechnung
   int pos;
   if(prev_calculated>1)
      pos=prev_calculated-1;
   else
      pos=0;
//--- Hauptzyklus
   for(int i=pos; i<rates_total && !IsStopped(); i++)
     {
      //--- mittlere Zeile
      ExtMLBuffer[i]=CalculateMovingAverage(i, ExtBandsPeriod, price);
      //--- StdDev berechnen und aufschreiben
      ExtStdDevBuffer[i]=StdDev_Func(i,price,ExtMLBuffer,ExtBandsPeriod);
      //--- obere Zeile
      ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i];
      //--- untere Zeile
      ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i];
     }
//--- OnCalculate erledigt. Rückgabe neu prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Standardabweichung berechnen|
//+------------------------------------------------------------------+
double StdDev_Func(const int position,const double &price[],const double &ma_price[],const int period)
  {
   double std_dev=0.0;
//--- berechneter 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);
     }
//--- Rückgabe des berechneten Wertes
   return(std_dev);
  }
//+------------------------------------------------------------------+




Übersetzt aus dem Englischen von MetaQuotes Ltd.
Originalpublikation: https://www.mql5.com/en/code/49464

Geometric Moving Average Geometric Moving Average

MQL5-Version des geometrischen gleitenden Durchschnitts.

Get Nth Active Trade from the end in MT5 Get Nth Active Trade from the end in MT5

Dieser EA scannt alle offenen Trades und druckt dann den n-ten Trade vom Ende aus

OHLC Candles with Ask and Bid OHLC Candles with Ask and Bid

Ein Kerzendiagramm, das den Geld- und Briefkurs mit dem Höchst- und Tiefstwert der Kerze verbindet

Einfach_drei_Innenmuster_EA Einfach_drei_Innenmuster_EA

Ein einfacher Expert Advisor, der handelt, wenn der Kurs das "Three From Within"-Muster bildet.