mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-07-27 20:47:44 +00:00
refactor: VIDYA_Calculator
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
#property description "Professional Variable Index Dynamic Average (VIDYA) with selectable"
|
||||
#property description "price source (Standard and Heikin Ashi)."
|
||||
|
||||
//--- Indicator Window and Plot Properties ---
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
@@ -19,22 +18,17 @@
|
||||
#property indicator_width1 1
|
||||
#property indicator_label1 "VIDYA"
|
||||
|
||||
//--- Include the calculator engine ---
|
||||
#include <MyIncludes\VIDYA_Calculator.mqh>
|
||||
|
||||
//--- Input Parameters ---
|
||||
input int InpPeriodCMO = 9;
|
||||
input int InpPeriodEMA = 12;
|
||||
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
|
||||
|
||||
//--- Indicator Buffers ---
|
||||
double BufferVIDYA[];
|
||||
|
||||
//--- Global calculator object (as a base class pointer) ---
|
||||
CVIDYACalculator *g_calculator;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function. |
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
@@ -42,15 +36,9 @@ int OnInit()
|
||||
ArraySetAsSeries(BufferVIDYA, false);
|
||||
|
||||
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
||||
{
|
||||
g_calculator = new CVIDYACalculator_HA();
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("VIDYA HA(%d,%d)", InpPeriodCMO, InpPeriodEMA));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_calculator = new CVIDYACalculator();
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("VIDYA(%d,%d)", InpPeriodCMO, InpPeriodEMA));
|
||||
}
|
||||
|
||||
if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpPeriodCMO, InpPeriodEMA))
|
||||
{
|
||||
@@ -58,37 +46,25 @@ int OnInit()
|
||||
return(INIT_FAILED);
|
||||
}
|
||||
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("VIDYA%s(%d,%d)", (InpSourcePrice <= PRICE_HA_CLOSE ? " HA" : ""), InpPeriodCMO, InpPeriodEMA));
|
||||
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, InpPeriodCMO + InpPeriodEMA);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator deinitialization function. |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
if(CheckPointer(g_calculator) != POINTER_INVALID)
|
||||
delete g_calculator;
|
||||
}
|
||||
void OnDeinit(const int reason) { if(CheckPointer(g_calculator) != POINTER_INVALID) delete g_calculator; }
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator calculation function. |
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total, const int, const datetime&[], const double &open[], const double &high[], const double &low[], const double &close[], const long&[], const long&[], const int&[])
|
||||
{
|
||||
if(CheckPointer(g_calculator) == POINTER_INVALID)
|
||||
return 0;
|
||||
ENUM_APPLIED_PRICE price_type = (InpSourcePrice <= PRICE_HA_CLOSE) ? (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice) : (ENUM_APPLIED_PRICE)InpSourcePrice;
|
||||
|
||||
ENUM_APPLIED_PRICE price_type;
|
||||
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
||||
price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice);
|
||||
else
|
||||
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
|
||||
|
||||
//--- This call automatically resolves to the single-buffer version ---
|
||||
g_calculator.Calculate(rates_total, price_type, open, high, low, close, BufferVIDYA);
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
Reference in New Issue
Block a user