mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-07-27 20:47:44 +00:00
refactor(indicators): Refactored to use MovingAverage_Engine
This commit is contained in:
@@ -3,13 +3,13 @@
|
|||||||
//| Copyright 2025, xxxxxxxx|
|
//| Copyright 2025, xxxxxxxx|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2025, xxxxxxxx"
|
#property copyright "Copyright 2025, xxxxxxxx"
|
||||||
#property version "3.10" // Optimized for incremental calculation
|
#property version "4.00" // Refactored to use MovingAverage_Engine
|
||||||
#property description "Professional Gann HiLo Activator with selectable MA and"
|
#property description "Professional Gann HiLo Activator with selectable MA and"
|
||||||
#property description "candle source (Standard or Heikin Ashi)."
|
#property description "candle source (Standard or Heikin Ashi)."
|
||||||
|
|
||||||
//--- Indicator Window and Plot Properties ---
|
//--- Indicator Window and Plot Properties ---
|
||||||
#property indicator_chart_window
|
#property indicator_chart_window
|
||||||
#property indicator_buffers 2 // Main line and color buffer
|
#property indicator_buffers 2
|
||||||
#property indicator_plots 1
|
#property indicator_plots 1
|
||||||
|
|
||||||
//--- Plot 1: Gann HiLo line
|
//--- Plot 1: Gann HiLo line
|
||||||
@@ -19,81 +19,69 @@
|
|||||||
#property indicator_style1 STYLE_SOLID
|
#property indicator_style1 STYLE_SOLID
|
||||||
#property indicator_width1 1
|
#property indicator_width1 1
|
||||||
|
|
||||||
//--- Include the calculator engine ---
|
|
||||||
#include <MyIncludes\GannHiLo_Calculator.mqh>
|
#include <MyIncludes\GannHiLo_Calculator.mqh>
|
||||||
|
|
||||||
//--- Enum for selecting the candle source for calculation ---
|
|
||||||
enum ENUM_CANDLE_SOURCE
|
enum ENUM_CANDLE_SOURCE
|
||||||
{
|
{
|
||||||
CANDLE_STANDARD, // Use standard OHLC data
|
CANDLE_STANDARD,
|
||||||
CANDLE_HEIKIN_ASHI // Use Heikin Ashi smoothed data
|
CANDLE_HEIKIN_ASHI
|
||||||
};
|
};
|
||||||
|
|
||||||
//--- Input Parameters ---
|
//--- Input Parameters ---
|
||||||
input int InpPeriod = 10; // Period for High/Low averages
|
input int InpPeriod = 10; // Period for High/Low averages
|
||||||
input ENUM_MA_METHOD InpMAMethod = MODE_SMA; // Method for High/Low averages
|
// UPDATED: Use ENUM_MA_TYPE instead of ENUM_MA_METHOD
|
||||||
|
input ENUM_MA_TYPE InpMAMethod = SMA; // Method for High/Low averages
|
||||||
input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD; // Candle source
|
input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD; // Candle source
|
||||||
|
|
||||||
//--- Indicator Buffers ---
|
//--- Indicator Buffers ---
|
||||||
double BufferGannHiLo[];
|
double BufferGannHiLo[];
|
||||||
double BufferColor[];
|
double BufferColor[];
|
||||||
|
|
||||||
//--- Global calculator object (as a base class pointer) ---
|
//--- Global calculator object ---
|
||||||
CGannHiLoCalculator *g_calculator;
|
CGannHiLoCalculator *g_calculator;
|
||||||
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
//| Custom indicator initialization function. |
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
int OnInit()
|
int OnInit()
|
||||||
{
|
{
|
||||||
//--- Map the buffers and set as non-timeseries
|
|
||||||
SetIndexBuffer(0, BufferGannHiLo, INDICATOR_DATA);
|
SetIndexBuffer(0, BufferGannHiLo, INDICATOR_DATA);
|
||||||
SetIndexBuffer(1, BufferColor, INDICATOR_COLOR_INDEX);
|
SetIndexBuffer(1, BufferColor, INDICATOR_COLOR_INDEX);
|
||||||
ArraySetAsSeries(BufferGannHiLo, false);
|
ArraySetAsSeries(BufferGannHiLo, false);
|
||||||
ArraySetAsSeries(BufferColor, false);
|
ArraySetAsSeries(BufferColor, false);
|
||||||
|
|
||||||
//--- Dynamically create the appropriate calculator instance
|
|
||||||
switch(InpCandleSource)
|
switch(InpCandleSource)
|
||||||
{
|
{
|
||||||
case CANDLE_HEIKIN_ASHI:
|
case CANDLE_HEIKIN_ASHI:
|
||||||
g_calculator = new CGannHiLoCalculator_HA();
|
g_calculator = new CGannHiLoCalculator_HA();
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("GannHiLo HA(%d)", InpPeriod));
|
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("GannHiLo HA(%d)", InpPeriod));
|
||||||
break;
|
break;
|
||||||
default: // CANDLE_STANDARD
|
default:
|
||||||
g_calculator = new CGannHiLoCalculator();
|
g_calculator = new CGannHiLoCalculator();
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("GannHiLo(%d)", InpPeriod));
|
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("GannHiLo(%d)", InpPeriod));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--- Check if creation was successful and initialize
|
|
||||||
if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpPeriod, InpMAMethod))
|
if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpPeriod, InpMAMethod))
|
||||||
{
|
{
|
||||||
Print("Failed to create or initialize Gann HiLo Calculator object.");
|
Print("Failed to create or initialize Gann HiLo Calculator object.");
|
||||||
return(INIT_FAILED);
|
return(INIT_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--- Set indicator display properties
|
|
||||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
||||||
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, InpPeriod);
|
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, InpPeriod);
|
||||||
|
|
||||||
return(INIT_SUCCEEDED);
|
return(INIT_SUCCEEDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
//| Custom indicator deinitialization function. |
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
void OnDeinit(const int reason)
|
void OnDeinit(const int reason)
|
||||||
{
|
{
|
||||||
//--- Free the calculator object to prevent memory leaks
|
|
||||||
if(CheckPointer(g_calculator) != POINTER_INVALID)
|
if(CheckPointer(g_calculator) != POINTER_INVALID)
|
||||||
delete g_calculator;
|
delete g_calculator;
|
||||||
}
|
}
|
||||||
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
//| Custom indicator calculation function |
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
int OnCalculate(const int rates_total,
|
int OnCalculate(const int rates_total,
|
||||||
const int prev_calculated, // <--- Now used!
|
const int prev_calculated,
|
||||||
const datetime &time[],
|
const datetime &time[],
|
||||||
const double &open[],
|
const double &open[],
|
||||||
const double &high[],
|
const double &high[],
|
||||||
@@ -106,8 +94,6 @@ int OnCalculate(const int rates_total,
|
|||||||
if(CheckPointer(g_calculator) == POINTER_INVALID)
|
if(CheckPointer(g_calculator) == POINTER_INVALID)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
//--- Delegate calculation with prev_calculated optimization
|
|
||||||
// Note: We pass 'open' array even though base calc doesn't use it, but HA calc does.
|
|
||||||
g_calculator.Calculate(rates_total, prev_calculated, open, high, low, close, BufferGannHiLo, BufferColor);
|
g_calculator.Calculate(rates_total, prev_calculated, open, high, low, close, BufferGannHiLo, BufferColor);
|
||||||
|
|
||||||
return(rates_total);
|
return(rates_total);
|
||||||
|
|||||||
Reference in New Issue
Block a user