Files
mql5/Indicators/MyIndicators/Supertrend_Pro.mq5
T

91 lines
3.7 KiB
Plaintext
Raw Normal View History

2025-10-01 08:54:07 +02:00
//+------------------------------------------------------------------+
//| Supertrend_Pro.mq5|
//| Copyright 2025, xxxxxxxx|
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx"
#property link ""
2025-11-27 14:30:25 +01:00
#property version "3.20" // Adapted to new ATR Calculator
#property description "Professional Supertrend with selectable candle and ATR source."
2025-10-01 08:54:07 +02:00
//--- Indicator Window and Plot Properties ---
#property indicator_chart_window
2025-11-27 14:30:25 +01:00
#property indicator_buffers 4
2025-10-12 13:54:24 +02:00
#property indicator_plots 2
2025-10-01 08:54:07 +02:00
2025-10-12 13:54:24 +02:00
//--- Plot 1: Supertrend line (Odd Segments)
2025-10-01 08:54:07 +02:00
#property indicator_label1 "Supertrend"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrLimeGreen, clrTomato
#property indicator_style1 STYLE_SOLID
2025-10-05 17:58:59 +02:00
#property indicator_width1 1
2025-10-01 08:54:07 +02:00
2025-10-12 13:54:24 +02:00
//--- Plot 2: Supertrend line (Even Segments)
2025-11-27 14:30:25 +01:00
#property indicator_label2 ""
2025-10-12 13:54:24 +02:00
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 clrLimeGreen, clrTomato
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
2025-10-01 08:54:07 +02:00
#include <MyIncludes\Supertrend_Calculator.mqh>
//--- Input Parameters ---
2025-11-27 14:30:25 +01:00
input int InpAtrPeriod = 10;
input double InpFactor = 3.0;
2025-10-01 08:54:07 +02:00
input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD;
2025-11-27 14:30:25 +01:00
input ENUM_CANDLE_SOURCE InpAtrSource = CANDLE_STANDARD;
2025-10-01 08:54:07 +02:00
//--- Indicator Buffers ---
2025-11-27 14:30:25 +01:00
double BufferSupertrend_Odd[], BufferColor_Odd[], BufferSupertrend_Even[], BufferColor_Even[];
2025-10-01 08:54:07 +02:00
2025-11-27 14:30:25 +01:00
//--- Global calculator object ---
2025-10-01 08:54:07 +02:00
CSupertrendCalculator *g_calculator;
//+------------------------------------------------------------------+
int OnInit()
{
2025-10-12 13:54:24 +02:00
SetIndexBuffer(0, BufferSupertrend_Odd, INDICATOR_DATA);
SetIndexBuffer(1, BufferColor_Odd, INDICATOR_COLOR_INDEX);
SetIndexBuffer(2, BufferSupertrend_Even, INDICATOR_DATA);
SetIndexBuffer(3, BufferColor_Even, INDICATOR_COLOR_INDEX);
ArraySetAsSeries(BufferSupertrend_Odd, false);
ArraySetAsSeries(BufferColor_Odd, false);
ArraySetAsSeries(BufferSupertrend_Even, false);
ArraySetAsSeries(BufferColor_Even, false);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
2025-10-01 08:54:07 +02:00
if(InpCandleSource == CANDLE_HEIKIN_ASHI)
g_calculator = new CSupertrendCalculator_HA();
else
g_calculator = new CSupertrendCalculator();
if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpAtrPeriod, InpFactor, InpAtrSource))
{
Print("Failed to create or initialize Supertrend Calculator object.");
return(INIT_FAILED);
}
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, InpAtrPeriod);
2025-10-12 13:54:24 +02:00
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, InpAtrPeriod);
2025-10-01 08:54:07 +02:00
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
2025-11-27 14:30:25 +01:00
void OnDeinit(const int reason) { if(CheckPointer(g_calculator) != POINTER_INVALID) delete g_calculator; }
2025-10-01 08:54:07 +02:00
//+------------------------------------------------------------------+
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;
2025-10-12 13:54:24 +02:00
g_calculator.Calculate(rates_total, open, high, low, close, BufferSupertrend_Odd, BufferColor_Odd, BufferSupertrend_Even, BufferColor_Even);
2025-10-01 08:54:07 +02:00
return(rates_total);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+