mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-19 07:18:07 +00:00
refactor: Added optional Noise Elimination Technology (NET)
This commit is contained in:
@@ -4,18 +4,27 @@
|
|||||||
//| |
|
//| |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2025, xxxxxxxx"
|
#property copyright "Copyright 2025, xxxxxxxx"
|
||||||
#property version "1.00"
|
#property version "2.00" // Added optional Noise Elimination Technology (NET)
|
||||||
#property description "John Ehlers' Improved RSI with Hann Windowing (RSIH)."
|
#property description "John Ehlers' Improved RSI with Hann Windowing (RSIH) and optional NET filter."
|
||||||
|
|
||||||
#property indicator_separate_window
|
#property indicator_separate_window
|
||||||
#property indicator_buffers 1
|
#property indicator_buffers 2
|
||||||
#property indicator_plots 1
|
#property indicator_plots 2
|
||||||
|
|
||||||
|
//--- Plot 1: Base RSIH
|
||||||
#property indicator_label1 "RSIH"
|
#property indicator_label1 "RSIH"
|
||||||
#property indicator_type1 DRAW_LINE
|
#property indicator_type1 DRAW_LINE
|
||||||
#property indicator_color1 clrGray
|
#property indicator_color1 clrGray
|
||||||
#property indicator_style1 STYLE_SOLID
|
#property indicator_style1 STYLE_DOT
|
||||||
#property indicator_width1 1
|
#property indicator_width1 1
|
||||||
|
|
||||||
|
//--- Plot 2: NET-filtered RSIH
|
||||||
|
#property indicator_label2 "NET(RSIH)"
|
||||||
|
#property indicator_type2 DRAW_LINE
|
||||||
|
#property indicator_color2 clrDodgerBlue
|
||||||
|
#property indicator_style2 STYLE_SOLID
|
||||||
|
#property indicator_width2 1
|
||||||
|
|
||||||
#property indicator_minimum -1.1
|
#property indicator_minimum -1.1
|
||||||
#property indicator_maximum 1.1
|
#property indicator_maximum 1.1
|
||||||
#property indicator_level1 0.5
|
#property indicator_level1 0.5
|
||||||
@@ -26,33 +35,25 @@
|
|||||||
|
|
||||||
#include <MyIncludes\RSIH_Calculator.mqh>
|
#include <MyIncludes\RSIH_Calculator.mqh>
|
||||||
|
|
||||||
//--- Custom Enum for Price Source, including Heikin Ashi
|
|
||||||
enum ENUM_APPLIED_PRICE_HA_ALL
|
enum ENUM_APPLIED_PRICE_HA_ALL
|
||||||
{
|
{
|
||||||
//--- Heikin Ashi Prices
|
PRICE_HA_CLOSE = -1, PRICE_HA_OPEN = -2, PRICE_HA_HIGH = -3, PRICE_HA_LOW = -4,
|
||||||
PRICE_HA_CLOSE = -1,
|
PRICE_HA_MEDIAN = -5, PRICE_HA_TYPICAL = -6, PRICE_HA_WEIGHTED = -7,
|
||||||
PRICE_HA_OPEN = -2,
|
PRICE_CLOSE_STD = PRICE_CLOSE, PRICE_OPEN_STD = PRICE_OPEN, PRICE_HIGH_STD = PRICE_HIGH,
|
||||||
PRICE_HA_HIGH = -3,
|
PRICE_LOW_STD = PRICE_LOW, PRICE_MEDIAN_STD = PRICE_MEDIAN, PRICE_TYPICAL_STD = PRICE_TYPICAL,
|
||||||
PRICE_HA_LOW = -4,
|
PRICE_WEIGHTED_STD= PRICE_WEIGHTED
|
||||||
PRICE_HA_MEDIAN = -5,
|
|
||||||
PRICE_HA_TYPICAL = -6,
|
|
||||||
PRICE_HA_WEIGHTED = -7,
|
|
||||||
//--- Standard Prices
|
|
||||||
PRICE_CLOSE_STD = PRICE_CLOSE,
|
|
||||||
PRICE_OPEN_STD = PRICE_OPEN,
|
|
||||||
PRICE_HIGH_STD = PRICE_HIGH,
|
|
||||||
PRICE_LOW_STD = PRICE_LOW,
|
|
||||||
PRICE_MEDIAN_STD = PRICE_MEDIAN,
|
|
||||||
PRICE_TYPICAL_STD = PRICE_TYPICAL,
|
|
||||||
PRICE_WEIGHTED_STD = PRICE_WEIGHTED
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//--- Input Parameters ---
|
//--- Input Parameters ---
|
||||||
input int InpPeriodRSI = 14;
|
input int InpPeriodRSI = 14;
|
||||||
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
|
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
|
||||||
|
input group "Noise Elimination Technology (NET)"
|
||||||
|
input bool InpApplyNET = true;
|
||||||
|
input int InpPeriodNET = 14;
|
||||||
|
|
||||||
//--- Indicator Buffers ---
|
//--- Indicator Buffers ---
|
||||||
double BufferRSIH[];
|
double BufferRSIH[];
|
||||||
|
double BufferNET[];
|
||||||
|
|
||||||
//--- Global calculator object ---
|
//--- Global calculator object ---
|
||||||
CRSIHCalculator *g_calculator;
|
CRSIHCalculator *g_calculator;
|
||||||
@@ -61,26 +62,29 @@ CRSIHCalculator *g_calculator;
|
|||||||
int OnInit()
|
int OnInit()
|
||||||
{
|
{
|
||||||
SetIndexBuffer(0, BufferRSIH, INDICATOR_DATA);
|
SetIndexBuffer(0, BufferRSIH, INDICATOR_DATA);
|
||||||
|
SetIndexBuffer(1, BufferNET, INDICATOR_DATA);
|
||||||
ArraySetAsSeries(BufferRSIH, false);
|
ArraySetAsSeries(BufferRSIH, false);
|
||||||
|
ArraySetAsSeries(BufferNET, false);
|
||||||
|
|
||||||
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
||||||
{
|
{
|
||||||
g_calculator = new CRSIHCalculator_HA();
|
g_calculator = new CRSIHCalculator_HA();
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("RSIH HA(%d)", InpPeriodRSI));
|
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("RSIH HA(%d,%d)", InpPeriodRSI, InpPeriodNET));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_calculator = new CRSIHCalculator();
|
g_calculator = new CRSIHCalculator();
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("RSIH(%d)", InpPeriodRSI));
|
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("RSIH(%d,%d)", InpPeriodRSI, InpPeriodNET));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpPeriodRSI))
|
if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpPeriodRSI, InpPeriodNET))
|
||||||
{
|
{
|
||||||
Print("Failed to create or initialize RSIH Calculator object.");
|
Print("Failed to create or initialize RSIH Calculator object.");
|
||||||
return(INIT_FAILED);
|
return(INIT_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, InpPeriodRSI + 1);
|
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, InpPeriodRSI + 1);
|
||||||
|
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, InpPeriodRSI + InpPeriodNET + 1);
|
||||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||||
|
|
||||||
return(INIT_SUCCEEDED);
|
return(INIT_SUCCEEDED);
|
||||||
@@ -105,7 +109,25 @@ int OnCalculate(const int rates_total, const int, const datetime&[], const doubl
|
|||||||
else
|
else
|
||||||
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
|
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
|
||||||
|
|
||||||
g_calculator.Calculate(rates_total, price_type, open, high, low, close, BufferRSIH);
|
g_calculator.Calculate(rates_total, price_type, open, high, low, close, BufferRSIH, BufferNET);
|
||||||
|
|
||||||
|
// Hide buffers if not enabled by the user
|
||||||
|
if(!InpApplyNET)
|
||||||
|
{
|
||||||
|
for(int i=0; i<rates_total; i++)
|
||||||
|
{
|
||||||
|
BufferNET[i] = EMPTY_VALUE;
|
||||||
|
// If NET is off, make the base RSIH the main line
|
||||||
|
PlotIndexSetInteger(0, PLOT_LINE_STYLE, STYLE_SOLID);
|
||||||
|
PlotIndexSetInteger(0, PLOT_LINE_COLOR, clrDodgerBlue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Restore default styles if NET is on
|
||||||
|
PlotIndexSetInteger(0, PLOT_LINE_STYLE, STYLE_DOT);
|
||||||
|
PlotIndexSetInteger(0, PLOT_LINE_COLOR, clrGray);
|
||||||
|
}
|
||||||
|
|
||||||
return(rates_total);
|
return(rates_total);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user