Deze indicator heb ik ontwikkeld als een alternatief voor de standaard bewegende gemiddelde methoden in de Bollinger Bands indicator van MetaTrader 5, die alleen de 'simpele' methode aanbiedt. Met mijn indicator hebben gebruikers de mogelijkheid om te kiezen uit extra methoden, waaronder Exponential, Smoothed en LinearWeighted.
Om deze indicator te gebruiken, moet je deze in een map plaatsen (op Windows) die eruit ziet als volgt:
C:\Users\jouw_gebruikersnaam\AppData\Roaming\MetaQuotes\Terminal\Indicators\Examples
Toegevoegde functies:

Standaard is de waarde ingesteld op nul:

Hier een voorbeeld van de uitvoering met de gemiddelde waarde van LinearWeighted:

CODE:
//+------------------------------------------------------------------+ //| BBPersonalizada.mq5 | //| Lucas Vidal | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Lucas Vidal" #property link "https://www.mql5.com/en/users/lucasmoura00" #property description "Aangepaste Bollinger Bands" #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 "Banden midden" #property indicator_label2 "Banden boven" #property indicator_label3 "Banden onder" //--- invoerparameters enum MovingAverageMethod { Simple, // 0 Exponential, // 1 Smoothed, // 2 LinearWeighted // 3 }; input MovingAverageMethod InpMaMethod = Simple; // Methode van het Bewegend Gemiddelde input int InpBandsPeriod=20; // Periode input int InpBandsShift=0; // Shift input double InpBandsDeviations=2.0 // Deviatie //--- globale variabelen int ExtBandsPeriod,ExtBandsShift; double ExtBandsDeviations; int ExtPlotBegin=0; //--- indicator buffer double ExtMLBuffer[]; double ExtTLBuffer[]; double ExtBLBuffer[]; double ExtStdDevBuffer[]; //+------------------------------------------------------------------+ //| Initialisatie functie van de aangepaste indicator | //+------------------------------------------------------------------+ void OnInit() { //--- controleer invoerwaarden if(InpBandsPeriod<2) { ExtBandsPeriod=20; PrintFormat("Onjuiste waarde voor invoervariabele InpBandsPeriod=%d. De indicator zal waarde=%d gebruiken voor berekeningen.",InpBandsPeriod,ExtBandsPeriod); } else ExtBandsPeriod=InpBandsPeriod; if(InpBandsShift<0) { ExtBandsShift=0; PrintFormat("Onjuiste waarde voor invoervariabele InpBandsShift=%d. De indicator zal waarde=%d gebruiken voor berekeningen.",InpBandsShift,ExtBandsShift); } else ExtBandsShift=InpBandsShift; if(InpBandsDeviations==0.0) { ExtBandsDeviations=2.0; PrintFormat("Onjuiste waarde voor invoervariabele InpBandsDeviations=%f. De indicator zal waarde=%f gebruiken voor berekeningen.",InpBandsDeviations,ExtBandsDeviations); } else ExtBandsDeviations=InpBandsDeviations; //--- buffers definiëren SetIndexBuffer(0,ExtMLBuffer); SetIndexBuffer(1,ExtTLBuffer); SetIndexBuffer(2,ExtBLBuffer); SetIndexBuffer(3,ExtStdDevBuffer,INDICATOR_CALCULATIONS); //--- index labels instellen PlotIndexSetString(0,PLOT_LABEL,"Banden("+string(ExtBandsPeriod)+") Midden"); PlotIndexSetString(1,PLOT_LABEL,"Banden("+string(ExtBandsPeriod)+") Boven"); PlotIndexSetString(2,PLOT_LABEL,"Banden("+string(ExtBandsPeriod)+") Onder"); //--- naam van de indicator IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands"); //--- instellingen voor de beginindex van het tekenen ExtPlotBegin=ExtBandsPeriod-1; PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod); //--- instellingen voor de verschuiving van de indexen PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift); //--- aantal decimalen van de indicatorwaarde IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); } //+------------------------------------------------------------------+ //| Bereken het Bewegend Gemiddelde | //+------------------------------------------------------------------+ double CalculateMovingAverage(int positie, int periode, const double &prijs[]) { switch(InpMaMethod) { case Simple: return SimpleMA(positie, periode, prijs); case Exponential: // Corrigeer de aanroep van de functie iMA met de juiste parameters return iMA(NULL, 0, periode, 0, MODE_EMA, PRICE_CLOSE); case Smoothed: // Implementeer hier je SMMA functie break; case LinearWeighted: return LinearWeightedMA(positie, periode, prijs); } return 0; // Standaard retour in geval van een ongedefinieerde methode } //+------------------------------------------------------------------+ //| Bollinger Bands | //+------------------------------------------------------------------+ int OnCalculate(const int rates_totaal, const int prev_berekend, const int begin, const double &prijs[]) { if(rates_totaal<ExtPlotBegin) return(0); //--- instellingen voor de beginindex van het tekenen, wanneer we de vorige begin hebben ontvangen 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); } //--- start berekening int pos; if(prev_berekend>1) pos=prev_berekend-1; else pos=0; //--- hoofdcyclus for(int i=pos; i<rates_totaal && !IsStopped(); i++) { //--- middenlijn ExtMLBuffer[i]=CalculateMovingAverage(i, ExtBandsPeriod, prijs); //--- bereken en schrijf de StdDev ExtStdDevBuffer[i]=StdDev_Func(i,prijs,ExtMLBuffer,ExtBandsPeriod); //--- bovenlijn ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i]; //--- onderlijn ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i]; } //--- OnCalculate voltooid. Retourneer nieuwe prev_berekend. return(rates_totaal); } //+------------------------------------------------------------------+ //| Bereken de Standaard Deviatie | //+------------------------------------------------------------------+ double StdDev_Func(const int positie,const double &prijs[],const double &ma_prijs[],const int periode) { double std_dev=0.0; //--- bereken StdDev if(positie>=periode) { for(int i=0; i<periode; i++) std_dev+=MathPow(prijs[positie-i]-ma_prijs[positie],2.0); std_dev=MathSqrt(std_dev/periode); } //--- retourneer berekende waarde return(std_dev); } //+------------------------------------------------------------------+
Gerelateerde berichten
- BykovTrend_HTF_Signal: Dé Indicator voor MetaTrader 5 voor Trendanalyse
- Rate_AOModPips: Dé Indicator voor MetaTrader 5 voor Traders
- Prijs in het Poolse Coördinatensysteem - Indicator voor MetaTrader 5
- Open Range Breakout Indicator voor MetaTrader 5: Ontdek de Kracht van deze Tool
- X Bar Clear Close Trend: Dé Indicator voor Trendomkeringen in MetaTrader 5