refactor: Adapted to new ATR Calculator

This commit is contained in:
Toh4iem9
2025-11-27 14:30:25 +01:00
parent ad6826c259
commit c0bfc61bb2
+10 -38
View File
@@ -5,13 +5,12 @@
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx"
#property link ""
#property version "3.10" // Implemented gapped line drawing
#property description "Professional Supertrend with selectable candle and ATR source"
#property description "(Standard or Heikin Ashi)."
#property version "3.20" // Adapted to new ATR Calculator
#property description "Professional Supertrend with selectable candle and ATR source."
//--- Indicator Window and Plot Properties ---
#property indicator_chart_window
#property indicator_buffers 4 // 2 for Supertrend lines, 2 for colors
#property indicator_buffers 4
#property indicator_plots 2
//--- Plot 1: Supertrend line (Odd Segments)
@@ -22,39 +21,26 @@
#property indicator_width1 1
//--- Plot 2: Supertrend line (Even Segments)
#property indicator_label2 "" // No label for the second part
#property indicator_label2 ""
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 clrLimeGreen, clrTomato
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- Include the calculator engine ---
#include <MyIncludes\Supertrend_Calculator.mqh>
//--- Enum for Candle Source ---
enum ENUM_CANDLE_SOURCE
{
CANDLE_STANDARD, // Use standard OHLC data
CANDLE_HEIKIN_ASHI // Use Heikin Ashi smoothed data
};
//--- Input Parameters ---
input int InpAtrPeriod = 10;
input double InpFactor = 3.0;
input int InpAtrPeriod = 10;
input double InpFactor = 3.0;
input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD;
input ENUM_ATR_SOURCE InpAtrSource = ATR_SOURCE_STANDARD;
input ENUM_CANDLE_SOURCE InpAtrSource = CANDLE_STANDARD;
//--- Indicator Buffers ---
double BufferSupertrend_Odd[];
double BufferColor_Odd[];
double BufferSupertrend_Even[];
double BufferColor_Even[];
double BufferSupertrend_Odd[], BufferColor_Odd[], BufferSupertrend_Even[], BufferColor_Even[];
//--- Global calculator object (as a base class pointer) ---
//--- Global calculator object ---
CSupertrendCalculator *g_calculator;
//+------------------------------------------------------------------+
//| Custom indicator initialization function. |
//+------------------------------------------------------------------+
int OnInit()
{
@@ -72,15 +58,9 @@ int OnInit()
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
if(InpCandleSource == CANDLE_HEIKIN_ASHI)
{
g_calculator = new CSupertrendCalculator_HA();
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Supertrend HA(%d,%.1f)", InpAtrPeriod, InpFactor));
}
else
{
g_calculator = new CSupertrendCalculator();
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Supertrend(%d,%.1f)", InpAtrPeriod, InpFactor));
}
if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpAtrPeriod, InpFactor, InpAtrSource))
{
@@ -96,16 +76,8 @@ int OnInit()
}
//+------------------------------------------------------------------+
//| 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&[])
{