Halo, trader! Kali ini kita akan membahas tentang indikator Bollinger Bands kustom yang saya kembangkan untuk MetaTrader 5. Indikator ini memberikan alternatif dari metode rata-rata bergerak standar yang hanya tersedia dalam metode 'simple'. Dengan indikator ini, kamu bisa memilih dari beberapa metode tambahan seperti Exponential, Smoothed, dan Linear Weighted.
Untuk menggunakan indikator ini, kamu perlu menempatkannya di direktori berikut (di Windows):
C:\Users\namapengguna\AppData\Roaming\MetaQuotes\Terminal\Indicators\Examples
Fitur tambahan:

Indikator ini diatur ke nol secara default:

Berikut adalah contoh penggunaan dengan metode Linear Weighted:

KODE:
//+------------------------------------------------------------------+ //| BBPersonalizada.mq5 | //| Lucas Vidal | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Lucas Vidal" #property link "https://www.mql5.com/en/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" //--- input parameters enum MovingAverageMethod { Simple, // 0 Exponential, // 1 Smoothed, // 2 LinearWeighted // 3 }; input MovingAverageMethod InpMaMethod = Simple; // Metode Rata-rata Bergerak input int InpBandsPeriod=20; // Periode input int InpBandsShift=0 // Pergeseran input double InpBandsDeviations=2.0 // Deviasi //--- variabel global int ExtBandsPeriod,ExtBandsShift; double ExtBandsDeviations; int ExtPlotBegin=0; //--- buffer indikator double ExtMLBuffer[]; double ExtTLBuffer[]; double ExtBLBuffer[]; double ExtStdDevBuffer[]; //+------------------------------------------------------------------+ //| Inisialisasi indikator kustom | //+------------------------------------------------------------------+ void OnInit() { //--- memeriksa nilai input if(InpBandsPeriod<2) { ExtBandsPeriod=20; PrintFormat("Nilai input InpBandsPeriod tidak benar=%d. Indikator akan menggunakan nilai=%d untuk perhitungan.",InpBandsPeriod,ExtBandsPeriod); } else ExtBandsPeriod=InpBandsPeriod; if(InpBandsShift<0) { ExtBandsShift=0; PrintFormat("Nilai input InpBandsShift tidak benar=%d. Indikator akan menggunakan nilai=%d untuk perhitungan.",InpBandsShift,ExtBandsShift); } else ExtBandsShift=InpBandsShift; if(InpBandsDeviations==0.0) { ExtBandsDeviations=2.0; PrintFormat("Nilai input InpBandsDeviations tidak benar=%f. Indikator akan menggunakan nilai=%f untuk perhitungan.",InpBandsDeviations,ExtBandsDeviations); } else ExtBandsDeviations=InpBandsDeviations; //--- mendefinisikan buffer SetIndexBuffer(0,ExtMLBuffer); SetIndexBuffer(1,ExtTLBuffer); SetIndexBuffer(2,ExtBLBuffer); SetIndexBuffer(3,ExtStdDevBuffer,INDICATOR_CALCULATIONS); //--- set label indeks PlotIndexSetString(0,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Middle"); PlotIndexSetString(1,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Upper"); PlotIndexSetString(2,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Lower"); //--- nama indikator IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands"); //--- pengaturan awal untuk menggambar indeks ExtPlotBegin=ExtBandsPeriod-1; PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod); //--- pengaturan pergeseran indeks PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift); //--- jumlah digit dari nilai indikator IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); } //+------------------------------------------------------------------+ //| Hitung Rata-rata Bergerak | //+------------------------------------------------------------------+ double CalculateMovingAverage(int position, int period, const double &price[]) { switch(InpMaMethod) { case Simple: return SimpleMA(position, period, price); case Exponential: // Memperbaiki pemanggilan fungsi iMA dengan parameter yang benar return iMA(NULL, 0, period, 0, MODE_EMA, PRICE_CLOSE); case Smoothed: // Implementasikan fungsi SMMA di sini break; case LinearWeighted: return LinearWeightedMA(position, period, price); } return 0; // Retur default jika metode tidak terdefinisi } //+------------------------------------------------------------------+ //| Bollinger Bands | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { if(rates_total<ExtPlotBegin) return(0); //--- pengaturan awal untuk menggambar indeks, ketika kita menerima awal sebelumnya 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); } //--- mulai perhitungan int pos; if(prev_calculated>1) pos=prev_calculated-1; else pos=0; //--- siklus utama for(int i=pos; i<rates_total && !IsStopped(); i++) { //--- garis tengah ExtMLBuffer[i]=CalculateMovingAverage(i, ExtBandsPeriod, price); //--- hitung dan tulis StdDev ExtStdDevBuffer[i]=StdDev_Func(i,price,ExtMLBuffer,ExtBandsPeriod); //--- garis atas ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i]; //--- garis bawah ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i]; } //--- OnCalculate selesai. Kembalikan prev_calculated yang baru. return(rates_total); } //+------------------------------------------------------------------+ //| Hitung Deviasi Standar | //+------------------------------------------------------------------+ double StdDev_Func(const int position,const double &price[],const double &ma_price[],const int period) { double std_dev=0.0; //--- hitung 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); } //--- kembalikan nilai yang dihitung return(std_dev); } //+------------------------------------------------------------------+
Postingan terkait
- Panduan Lengkap MetaCOT 2 CFTC ToolBox untuk Analisis COT di MT4
- Indikator Open Range Breakout untuk MetaTrader 5: Strategi Trading yang Efektif
- Master Tools: Alat Indikator untuk MetaTrader 4 yang Harus Dimiliki
- Volume Profile + Range v6.0: Indikator Penting untuk MetaTrader 5
- Memprediksi Harga Selanjutnya dengan Jaringan Saraf: Panduan Lengkap untuk Trader