mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-07-27 20:47:44 +00:00
refactor: Upgraded with dynamic Signal Line options, volume translation and chronological sorting safeguards
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Fisher_Transform_Pro.mq5 |
|
||||
//| Copyright 2025, xxxxxxxx|
|
||||
//| Copyright 2026, xxxxxxxx|
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2025, xxxxxxxx"
|
||||
#property version "2.00" // Optimized for incremental calculation
|
||||
#property copyright "Copyright 2026, xxxxxxxx"
|
||||
#property version "2.10" // Upgraded with dynamic Signal Line options, volume translation and chronological sorting safeguards
|
||||
#property description "John Ehlers' Fisher Transform for identifying sharp turning points."
|
||||
|
||||
#property indicator_separate_window
|
||||
@@ -32,9 +32,15 @@
|
||||
enum ENUM_PRICE_SOURCE { SOURCE_STANDARD, SOURCE_HEIKIN_ASHI };
|
||||
|
||||
//--- Input Parameters ---
|
||||
input int InpPeriod = 10; // Period for price normalization
|
||||
input double InpAlpha = 0.33; // Smoothing factor for normalized price
|
||||
input ENUM_PRICE_SOURCE InpSource = SOURCE_STANDARD;
|
||||
input group "Fisher Settings"
|
||||
input int InpPeriod = 10; // Period for price normalization
|
||||
input double InpAlpha = 0.33; // Smoothing factor for normalized price
|
||||
input ENUM_PRICE_SOURCE InpSource = SOURCE_STANDARD; // Price Source
|
||||
|
||||
input group "Signal Line Settings"
|
||||
input ENUM_FISHER_SIGNAL_TYPE InpSignalType = SIGNAL_DELAY_1BAR; // Signal Type
|
||||
input int InpSignalPeriod = 5; // Period (if MA)
|
||||
input ENUM_MA_TYPE InpSignalMethod = SMA; // Method (if MA / VWMA)
|
||||
|
||||
//--- Indicator Buffers ---
|
||||
double BufferFisher[];
|
||||
@@ -62,14 +68,18 @@ int OnInit()
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Fisher(%d,%.2f)", InpPeriod, InpAlpha));
|
||||
}
|
||||
|
||||
if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpPeriod, InpAlpha))
|
||||
if(CheckPointer(g_calculator) == POINTER_INVALID ||
|
||||
!g_calculator.Init(InpPeriod, InpAlpha, InpSignalType, InpSignalPeriod, InpSignalMethod))
|
||||
{
|
||||
Print("Failed to initialize Fisher Transform Calculator.");
|
||||
return(INIT_FAILED);
|
||||
}
|
||||
|
||||
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, InpPeriod);
|
||||
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, InpPeriod);
|
||||
int draw_begin = InpPeriod;
|
||||
int sig_begin = (InpSignalType == SIGNAL_DELAY_1BAR) ? InpPeriod + 1 : InpPeriod + InpSignalPeriod;
|
||||
|
||||
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, draw_begin);
|
||||
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, sig_begin);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
@@ -83,13 +93,43 @@ void OnDeinit(const int reason)
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
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 &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total < InpPeriod)
|
||||
return 0;
|
||||
|
||||
if(CheckPointer(g_calculator) == POINTER_INVALID)
|
||||
return 0;
|
||||
|
||||
g_calculator.Calculate(rates_total, prev_calculated, open, high, low, close, BufferFisher, BufferSignal);
|
||||
//--- Force strict chronological indexing for state-safety on input price arrays
|
||||
ArraySetAsSeries(time, false);
|
||||
ArraySetAsSeries(open, false);
|
||||
ArraySetAsSeries(high, false);
|
||||
ArraySetAsSeries(low, false);
|
||||
ArraySetAsSeries(close, false);
|
||||
|
||||
//--- Determine best volume array (Use Real Volume if available, otherwise fallback to Tick Volume)
|
||||
long volume_limit = (long)SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_LIMIT);
|
||||
|
||||
//--- Delegate calculations dynamically to support volume-weighted types (VWMA) on the Signal Line
|
||||
if(volume_limit > 0)
|
||||
{
|
||||
g_calculator.Calculate(rates_total, prev_calculated, open, high, low, close, volume, BufferFisher, BufferSignal);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_calculator.Calculate(rates_total, prev_calculated, open, high, low, close, tick_volume, BufferFisher, BufferSignal);
|
||||
}
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
Reference in New Issue
Block a user