Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Customized Bollinger Bands - MetaTrader 5 Script | Trading Script Download - MT4/MT5 Resources - MetaTrader 5 Resources

author EAcpu | 2 reads | 0 comments |

Custom Bollinger Bands - indicator for MetaTrader 5

Custom Bollinger Bands - indicator for MetaTrader 5

Custom Bollinger Bands - indicator for MetaTrader 5

Custom Bollinger Bands - indicator for MetaTrader 5

Custom Bollinger Bands - indicator for MetaTrader 5

I developed this indicator to provide an alternative to the standard Moving Average method in the MetaTrader 5 Bollinger Bands indicator, which only offers the "simple" method. Using my indicator, users can choose from other methods including exponential, smoothing and linear weighting.

To use this indicator, you need to place it in a directory similar to the following path (on Windows):

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

New features:

Custom Bollinger Bands - indicator for MetaTrader 5

By default it is set to zero:

Custom Bollinger Bands - indicator for MetaTrader 5

Execution example for selecting LinearWeighted average:

Custom Bollinger Bands - indicator for MetaTrader 5 Custom Bollinger Bands - indicator for MetaTrader 5

//+------------------------------------------------------------------+
//| BBP personalization.mq5 |
//| Lucas Vidal|
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#Property Copyright "Lucas Vidal"
#Property association "https://www.mql5.com/en/users/lucasmoura00"
# Property Description "Bollinger Bands Personalization"
#Include <moving average.mqh> //---
# Property indicator chart window
#Property indicator buffer 4
#Property Indicator Chart 3
#Property indicator type 1 draw line
#Property Indicator Color 1 Light Sea Green #Property Indicator Type 2 Draw Line
#Property Indicator Color 2 Light Sea Green #Property Indicator Type 3 Draw Line
# property indicator color 3 light sea green # property indicator tag 1 "In the band"
#property- indicator tag 2 "Band Upper"
#property- indicator tag 3 “band lower”
//--- input parameters
enum moving average method {
    Simple, // 0 Exponential, // 1 Smooth, // 2 Linear weighted // 3 }; Input moving average method InpMaMethod = Simple; // Media movement method
Input integer InpBandsPeriod= 20 ; // period
Input integer InpBandsShift= 0 ; // Shift
Enter double the InpBands bias = 2.0 ; // bias
//--- global variables
Integer ExtBandsPeriod, ExtBandsShift; double ExtBands deviation; integer External drawing start = 0 ; //--- indicator buffer
Double ExtMLBuffer[]; Double ExtTLBuffer[]; Double ExtBLBuffer[]; Double ExtStdDevBuffer[]; //+----------------------------------------------------------------------------------+
//|Custom indicator initialization function |
//+------------------------------------------------------------------+
Blank initialization ()
  { //--- Check input value if (InpBandsPeriod< 2 )
    {
      Extended band period = 20 ;
Print format ( "The value of the input variable InpBandsPeriod=%d is incorrect. The indicator will be calculated using the value =%d." ,InpBandsPeriod,ExtBandsPeriod);
    }
Others ExtBandsPeriod=InpBandsPeriod;
if (InpBandsShift< 0 )
    {
      Extended band offset = 0 ;
Print format ( "The value of the input variable InpBandsShift=%d is incorrect. The indicator will be calculated using the value =%d." ,InpBandsShift,ExtBandsShift);
    }
Else ExtBandsShift=InpBandsShift; if (InpBandsDeviations == 0.0 ) { ExtBandsDeviations = 2.0 ; print format ( "The value of the input variable InpBandsDeviations=%f is incorrect. The indicator will be calculated using the value = %f." ,InpBandsDeviations,ExtBandsDeviations); } else ExtBandsDeviations=InpBandsDeviations; //--- Define the buffer to set the index buffer ( 0 ,ExtMLBuffer); Set the index buffer ( 1 ,ExtTLBuffer); Set the index buffer ( 2 ,ExtBLBuffer); Set the index buffer ( 3 ,ExtStdDevBuffer, Indicator calculation ); //---Set the index label drawing index setting string ( 0 , Drawing label , " Band (" + String (ExtBandsPeriod)+ ") Middle" ); Drawing index setting string ( 1 , Drawing label , "Band(" + String (ExtBandsPeriod)+ ") Upper" ); Drawing index setting string ( 2 , Drawing label , "Band(" + String(ExtBandsPeriod)+ ") Lower" ); //--- Indicator name indicator set string ( INDICATOR_SHORTNAME , "Bollinger Bands" ); //--- Index drawing start setting ExtPlotBegin=ExtBandsPeriod- 1 ; drawing index set integer ( 0 , drawing_drawing_start , ExtBandsPeriod); drawing index set integer ( 1 , drawing_drawing_start , ExtBandsPeriod); drawing index set integer ( 2 , drawing_drawing_start , ExtBandsPeriod); //--- index shift setting drawing index set integer ( 0 , drawing_move , ExtBandsShift); drawing index set integer ( 1 , drawing_move , ExtBandsShift); drawing index set integer ( 2 , drawing_move , ExtBandsShift); //--- the number of digits of the indicator value indicator set integer ( INDICATOR_DIGITS , _number + 1 ); } //+--------------------------------------------------------------------------------+ //|Calculate moving average | //+------------------------------------------------------------------+ Calculation of double moving average ( integer position, integer period, const double &price[]) { Transform (InpMa method) { case simple: return SimpleMA(position, period, price); case index: // Function to change iMA related parameters return IMA ( void , 0 , period, 0 , mode_EMA , PRICE_CLOSE ); case smoothing: // implement SMMA aqui Function rest ; case linear weighting: return LinearWeightedMA(position, period, price); } returns 0 ; //restore indeterminate method } //+------------------------------------------------------------------+ //| Bollinger Bands | //+------------------------------------------------------------------+ when calculating integers ( constanteyword">Integer rates_total, const integer previously calculated, const integer start, const double &price[]) { if (rates_total return ( 0 ); //--- the index plot start set when we received the previous start if (ExtPlotBegin!=ExtBandsPeriod+begin) { ExtPlotBegin=ExtBandsPeriod+begin; plot index set integer ( 0 , plot_plot_begin ,ExtPlotBegin); plot index set integer ( 1 , plot_plot_start , ExtPlotBegin); plot index set integer ( 2 , plot_plot_start , ExtPlotBegin); } //--- Start calculating the integer position; if (previous calculation > 1 ) pos=prev_calculated- 1 ; other positions = 0 ; //--- the main loop is for ( integer i = position; i  Stopped(); i++) { //--- Centerline ExtMLBuffer[i]=CalculateMovingAverage(i, ExtBandsPeriod, price); //--- Calculate and write StdDev ExtStdDevBuffer[i]=StdDev_Func(i, price, ExtMLBuffer, ExtBandsPeriod); //--- Online ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i]; //--- Offline ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i]; } //--- OnCalculate completed. Return the new prev_calculated. return (rate_total); } //+--------------------------------------------------------------------------------+ //|Calculate Standard Deviation | //+----------------------------------------------------------------------------------+ DoubleStdDev_function ( const integer position, const double &ma_price[], const integer period) { doubleStdDev = 0.0 ; //---Calculate StdDev if ( integer i = period) { ;i< period ;i ++ ) std_dev+= mathpack (price[position - i]-ma_price[position], 2.0 ); std_dev= math-square-root (std_dev/period); } //--- Return the calculated value return (std_dev); } //+--------------------------------------------------------------------------------+



Attachment download

📎bb_personalizada.mq5 (13.42 KB)

Source: MQL5 #49464

Verification code Refresh