mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-20 15:58:07 +00:00
refactor(indicators): Updated to use new Calculator with ENUM_MA_TYPE
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| Bollinger_Band_Width_Pro.mq5 |
|
//| Bollinger_Band_Width_Pro.mq5 |
|
||||||
//| Copyright 2025, xxxxxxxx|
|
//| Copyright 2026, xxxxxxxx|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2025, xxxxxxxx"
|
#property copyright "Copyright 2026, xxxxxxxx"
|
||||||
#property version "2.20" // Optimized for incremental calculation
|
#property version "3.00" // Updated to use new Calculator with ENUM_MA_TYPE
|
||||||
#property description "Professional Bollinger Band Width oscillator with selectable analysis modes."
|
#property description "Professional Bollinger Band Width oscillator with selectable analysis modes."
|
||||||
|
|
||||||
#property indicator_separate_window
|
#property indicator_separate_window
|
||||||
@@ -50,9 +50,9 @@ enum ENUM_BBW_MODE
|
|||||||
|
|
||||||
//--- Input Parameters ---
|
//--- Input Parameters ---
|
||||||
input group "Base Bollinger Bands Settings"
|
input group "Base Bollinger Bands Settings"
|
||||||
input int InpPeriod = 20;
|
input int InpPeriod = 20;
|
||||||
input double InpDeviation = 2.0;
|
input double InpDeviation = 2.0;
|
||||||
input ENUM_MA_METHOD InpMethodMA = MODE_SMA;
|
input ENUM_MA_TYPE InpMAType = SMA; // Updated type
|
||||||
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
|
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
|
||||||
|
|
||||||
input group "Analysis Mode"
|
input group "Analysis Mode"
|
||||||
@@ -79,6 +79,8 @@ double BufferMA_Internal[];
|
|||||||
//--- Global calculator object ---
|
//--- Global calculator object ---
|
||||||
CBollingerBandsCalculator *g_calculator;
|
CBollingerBandsCalculator *g_calculator;
|
||||||
|
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| OnInit |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
int OnInit()
|
int OnInit()
|
||||||
{
|
{
|
||||||
@@ -92,6 +94,7 @@ int OnInit()
|
|||||||
ArraySetAsSeries(BufferLowerChannel, false);
|
ArraySetAsSeries(BufferLowerChannel, false);
|
||||||
ArraySetAsSeries(BufferCenterline, false);
|
ArraySetAsSeries(BufferCenterline, false);
|
||||||
|
|
||||||
|
//--- Factory Logic
|
||||||
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
||||||
{
|
{
|
||||||
g_calculator = new CBollingerBandsCalculator_HA();
|
g_calculator = new CBollingerBandsCalculator_HA();
|
||||||
@@ -103,8 +106,9 @@ int OnInit()
|
|||||||
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("BBW Pro(%d)", InpPeriod));
|
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("BBW Pro(%d)", InpPeriod));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--- Initialize with new Enum
|
||||||
if(CheckPointer(g_calculator) == POINTER_INVALID ||
|
if(CheckPointer(g_calculator) == POINTER_INVALID ||
|
||||||
!g_calculator.Init(InpPeriod, InpDeviation, InpMethodMA))
|
!g_calculator.Init(InpPeriod, InpDeviation, InpMAType))
|
||||||
{
|
{
|
||||||
Print("Failed to initialize Bollinger Bands Calculator.");
|
Print("Failed to initialize Bollinger Bands Calculator.");
|
||||||
return(INIT_FAILED);
|
return(INIT_FAILED);
|
||||||
@@ -116,12 +120,13 @@ int OnInit()
|
|||||||
PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, draw_begin);
|
PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, draw_begin);
|
||||||
PlotIndexSetInteger(3, PLOT_DRAW_BEGIN, draw_begin + InpBandsOnWidth_Period);
|
PlotIndexSetInteger(3, PLOT_DRAW_BEGIN, draw_begin + InpBandsOnWidth_Period);
|
||||||
|
|
||||||
//--- UPDATED: Use 4 digits for precision (like ATR Percent)
|
|
||||||
IndicatorSetInteger(INDICATOR_DIGITS, 4);
|
IndicatorSetInteger(INDICATOR_DIGITS, 4);
|
||||||
|
|
||||||
return(INIT_SUCCEEDED);
|
return(INIT_SUCCEEDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| OnDeinit |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
void OnDeinit(const int reason)
|
void OnDeinit(const int reason)
|
||||||
{
|
{
|
||||||
@@ -133,6 +138,8 @@ void OnDeinit(const int reason)
|
|||||||
ArrayFree(BufferMA_Internal);
|
ArrayFree(BufferMA_Internal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| OnCalculate |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
int OnCalculate(const int rates_total, const int prev_calculated, const datetime&[], const double &open[], const double &high[], const double &low[], const double &close[], const long&[], const long&[], const int&[])
|
int OnCalculate(const int rates_total, const int prev_calculated, const datetime&[], const double &open[], const double &high[], const double &low[], const double &close[], const long&[], const long&[], const int&[])
|
||||||
{
|
{
|
||||||
@@ -147,11 +154,9 @@ int OnCalculate(const int rates_total, const int prev_calculated, const datetime
|
|||||||
ArrayResize(BufferMA_Internal, rates_total);
|
ArrayResize(BufferMA_Internal, rates_total);
|
||||||
}
|
}
|
||||||
|
|
||||||
ENUM_APPLIED_PRICE price_type;
|
ENUM_APPLIED_PRICE price_type = (InpSourcePrice <= PRICE_HA_CLOSE) ?
|
||||||
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
(ENUM_APPLIED_PRICE)(-(int)InpSourcePrice) :
|
||||||
price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice);
|
(ENUM_APPLIED_PRICE)InpSourcePrice;
|
||||||
else
|
|
||||||
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
|
|
||||||
|
|
||||||
//--- Step 1: Run the main calculation (Incremental)
|
//--- Step 1: Run the main calculation (Incremental)
|
||||||
g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close,
|
g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close,
|
||||||
@@ -170,7 +175,6 @@ int OnCalculate(const int rates_total, const int prev_calculated, const datetime
|
|||||||
}
|
}
|
||||||
|
|
||||||
//--- Step 3: Calculate Overlays (Optimized Loop)
|
//--- Step 3: Calculate Overlays (Optimized Loop)
|
||||||
// Initialize unused buffers on full recalc
|
|
||||||
if(prev_calculated == 0)
|
if(prev_calculated == 0)
|
||||||
{
|
{
|
||||||
ArrayInitialize(BufferUpperChannel, EMPTY_VALUE);
|
ArrayInitialize(BufferUpperChannel, EMPTY_VALUE);
|
||||||
|
|||||||
Reference in New Issue
Block a user