mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-20 15:58:07 +00:00
refactor: Added optional signal line
This commit is contained in:
@@ -5,22 +5,31 @@
|
|||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2025, xxxxxxxx"
|
#property copyright "Copyright 2025, xxxxxxxx"
|
||||||
#property link ""
|
#property link ""
|
||||||
#property version "1.10" // Added value clamping for strict 0-100 range
|
#property version "1.21" // Changed to Display Mode enum
|
||||||
#property description "John Ehlers' Laguerre RSI with selectable price source (Standard/Heikin Ashi)."
|
#property description "John Ehlers' Laguerre RSI with an optional signal line."
|
||||||
|
|
||||||
//--- Indicator Window and Plot Properties ---
|
//--- Indicator Window and Plot Properties ---
|
||||||
#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: Laguerre RSI Line
|
||||||
|
#property indicator_label1 "Laguerre RSI"
|
||||||
#property indicator_type1 DRAW_LINE
|
#property indicator_type1 DRAW_LINE
|
||||||
#property indicator_color1 clrDodgerBlue
|
#property indicator_color1 clrDodgerBlue
|
||||||
#property indicator_style1 STYLE_SOLID
|
#property indicator_style1 STYLE_SOLID
|
||||||
#property indicator_width1 1
|
#property indicator_width1 1
|
||||||
#property indicator_label1 "Laguerre RSI"
|
|
||||||
|
|
||||||
//--- Scale and Level Properties (scaled to 0-100) ---
|
//--- Plot 2: Signal Line
|
||||||
#property indicator_minimum 0 // CORRECTED: Back to standard 0
|
#property indicator_label2 "Signal"
|
||||||
#property indicator_maximum 100 // CORRECTED: Back to standard 100
|
#property indicator_type2 DRAW_LINE
|
||||||
|
#property indicator_color2 clrOrangeRed
|
||||||
|
#property indicator_style2 STYLE_DOT
|
||||||
|
#property indicator_width2 1
|
||||||
|
|
||||||
|
//--- Scale and Level Properties ---
|
||||||
|
#property indicator_minimum 0
|
||||||
|
#property indicator_maximum 100
|
||||||
#property indicator_level1 10.0
|
#property indicator_level1 10.0
|
||||||
#property indicator_level2 20.0
|
#property indicator_level2 20.0
|
||||||
#property indicator_level3 50.0
|
#property indicator_level3 50.0
|
||||||
@@ -29,76 +38,78 @@
|
|||||||
#property indicator_levelcolor clrGray
|
#property indicator_levelcolor clrGray
|
||||||
#property indicator_levelstyle STYLE_DOT
|
#property indicator_levelstyle STYLE_DOT
|
||||||
|
|
||||||
//--- Include the calculator engine ---
|
|
||||||
#include <MyIncludes\Laguerre_RSI_Calculator.mqh>
|
#include <MyIncludes\Laguerre_RSI_Calculator.mqh>
|
||||||
|
|
||||||
|
//--- NEW: Enum for Display Mode ---
|
||||||
|
enum ENUM_LRSI_DISPLAY_MODE
|
||||||
|
{
|
||||||
|
DISPLAY_LRSI_ONLY,
|
||||||
|
DISPLAY_LRSI_AND_SIGNAL
|
||||||
|
};
|
||||||
|
|
||||||
//--- Input Parameters ---
|
//--- Input Parameters ---
|
||||||
input double InpGamma = 0.2; // Laguerre filter coefficient (0 to 1)
|
input group "Laguerre RSI Settings"
|
||||||
|
input double InpGamma = 0.5;
|
||||||
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
|
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
|
||||||
|
|
||||||
//--- Indicator Buffers ---
|
input group "Signal Line Settings"
|
||||||
double BufferLRSI[];
|
input ENUM_LRSI_DISPLAY_MODE InpDisplayMode = DISPLAY_LRSI_AND_SIGNAL;
|
||||||
|
input int InpSignalPeriod = 3;
|
||||||
|
input ENUM_MA_TYPE InpSignalMAType = EMA;
|
||||||
|
|
||||||
//--- Global calculator object (as a base class pointer) ---
|
//--- Indicator Buffers ---
|
||||||
|
double BufferLRSI[], BufferSignal[];
|
||||||
|
|
||||||
|
//--- Global calculator object ---
|
||||||
CLaguerreRSICalculator *g_calculator;
|
CLaguerreRSICalculator *g_calculator;
|
||||||
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
//| Custom indicator initialization function. |
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
int OnInit()
|
int OnInit()
|
||||||
{
|
{
|
||||||
SetIndexBuffer(0, BufferLRSI, INDICATOR_DATA);
|
SetIndexBuffer(0, BufferLRSI, INDICATOR_DATA);
|
||||||
ArraySetAsSeries(BufferLRSI, false);
|
SetIndexBuffer(1, BufferSignal, INDICATOR_DATA);
|
||||||
|
ArraySetAsSeries(BufferLRSI, false);
|
||||||
|
ArraySetAsSeries(BufferSignal, false);
|
||||||
|
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||||
|
|
||||||
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
||||||
{
|
|
||||||
g_calculator = new CLaguerreRSICalculator_HA();
|
g_calculator = new CLaguerreRSICalculator_HA();
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Laguerre RSI HA(%.2f)", InpGamma));
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
g_calculator = new CLaguerreRSICalculator();
|
g_calculator = new CLaguerreRSICalculator();
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Laguerre RSI(%.2f)", InpGamma));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpGamma))
|
if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpGamma, InpSignalPeriod, InpSignalMAType))
|
||||||
{
|
{
|
||||||
Print("Failed to create or initialize Laguerre RSI Calculator object.");
|
Print("Failed to create or initialize Laguerre RSI Calculator object.");
|
||||||
return(INIT_FAILED);
|
return(INIT_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Laguerre RSI%s(%.2f)", (InpSourcePrice <= PRICE_HA_CLOSE ? " HA" : ""), InpGamma));
|
||||||
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 2);
|
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 2);
|
||||||
|
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, 2 + InpSignalPeriod - 1);
|
||||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||||
|
|
||||||
return(INIT_SUCCEEDED);
|
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&[])
|
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)
|
if(CheckPointer(g_calculator) == POINTER_INVALID)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ENUM_APPLIED_PRICE price_type;
|
ENUM_APPLIED_PRICE price_type = (InpSourcePrice <= PRICE_HA_CLOSE) ? (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice) : (ENUM_APPLIED_PRICE)InpSourcePrice;
|
||||||
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
g_calculator.Calculate(rates_total, price_type, open, high, low, close, BufferLRSI, BufferSignal);
|
||||||
price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice);
|
|
||||||
else
|
|
||||||
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
|
|
||||||
|
|
||||||
g_calculator.Calculate(rates_total, price_type, open, high, low, close, BufferLRSI);
|
//--- UPDATED: Use the new display mode logic ---
|
||||||
|
if(InpDisplayMode == DISPLAY_LRSI_ONLY)
|
||||||
|
{
|
||||||
|
for(int i=0; i<rates_total; i++)
|
||||||
|
BufferSignal[i] = EMPTY_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
return(rates_total);
|
return(rates_total);
|
||||||
}
|
}
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
|
|||||||
Reference in New Issue
Block a user