This commit is contained in:
2025-09-17 19:39:52 +03:30
parent 94bc679290
commit b11e4f7f4b
11 changed files with 2945 additions and 58 deletions
+479
View File
@@ -0,0 +1,479 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class
// -------------------------------------------------
// Name: XCXBaseSignaller ...
// Description: Base Signaller Class ...
//
// - Create an Instance based on this ...
// - Attach Required Helpers for Indicator Usages ...
// - Override Virtual Methdos:
// - [] ProcessTick: Processing All Ticks
// - [] ProcessNewBar: Processing All New Bars
// - [] CheckForGuard: Check For Guards
// - [] CheckAdditionslSignallerValidations: Additional Class Validations
//
// - Dont Forget to Call OnSignal Event in Process Methods when
// a signal Appears ...
//
// - also Whenever you want you can call PrepareSignal Action to
// provide a Signal based on Current Market State ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm Base Signaller Class"
#property strict
//
// Imports ...
#include "../Classes/x-saherelm.base.class.mq5"
#include "../Libraries/x-saherelm.x-trade.lib.mq5"
//
// Definitions ...
//
// a Event Listener for Checking Can Analyse Market or not ...
// Usually for Time Based Session Handling ...
typedef bool (*TXCSignallerCanAnalyse)(
string _symbol,
ENUM_TIMEFRAMES _period,
datetime _time //
);
//
// a Event Listener for Notifying a Signal ...
// Usually for Time Based Session Handling ...
typedef bool (*TXCSignallerOnSignalEvent)(XSignal &signal);
//
// Implementations ...
class XCXBaseSignaller : public XCBase
{
//
// Public ...
public:
//
// Props ...
string name; // Name ...
string symbol; // Symbol ...
ENUM_TIMEFRAMES period; // Period ...
//
TXCSignallerCanAnalyse canAnalyseEventListener;
//
// Constructor ...
XCXBaseSignaller(
string _name, // Name ...
string _symbol, // Symbol ...
ENUM_TIMEFRAMES _period, // Period ...
bool _processAllTicks = false, // Process All Ticks ...
double _defaultSignalR2R = 1.5, // Default Signal Risk To Reward Ratio ...
double _defaultSignalRiskInPoint = 50, // Default Signal Risk In Point ...
double _defaultSignalVolume = 0.01 // Default Signal Volume ...
)
{
//
// Assign Properties ...
name = _name;
symbol = _symbol;
period = _period;
//
processAllTicks = _processAllTicks;
defaultSignalR2R = _defaultSignalR2R;
defaultSignalVolume = _defaultSignalVolume;
defaultSignalRiskInPoint = _defaultSignalRiskInPoint;
//
// Normalize ...
defaultSignalR2R = NormalizeDouble(defaultSignalR2R, 1, 10);
defaultSignalVolume = NormalizeDouble(defaultSignalVolume, 0.01);
defaultSignalVolume = NormalizeVolume(defaultSignalVolume, symbol, 2);
defaultSignalRiskInPoint = NormalizeDouble(defaultSignalRiskInPoint, 10);
//
// Set Dfault Values ...
mProcessedTicksCount = 0;
mLastCheckedBarTime = NULL;
}
//
// Deconstructor ...
~XCXBaseSignaller()
{
//
// Cleanup Event Listeners ...
SpecifiedClean(onSignalEventListeners);
}
//
// Event Listeners ...
/**
* Add On Signal Event Listener ...
*
* @param listener: TXCSignallerOnSignalEvent instance ...
*/
void AddOnSignalEventListener(TXCSignallerOnSignalEvent listener)
{
//
// Validate ...
if (listener == NULL)
{
return;
}
//
Add(
listener,
onSignalEventListeners //
);
}
//
// Actions ...
/**
* Check Signaller Validation ...
*
* @return ( bool )
*/
bool IsValid()
{
//
bool result = false;
//
result =
//
IsSpecifiedValid(name) &&
IsSpecifiedValid(symbol) &&
IsSpecifiedValid(period) &&
//
CheckAdditionslSignallerValidations()
//
;
//
return result;
}
/**
* Handling On Tick Event ...
*
* @param barIndex: int, Specified Bar Index ...
*/
void OnTick(int barIndex = 0)
{
//
// Normalize Bar Index ...
if (barIndex < 0)
{
barIndex = 0;
}
//
// Define Requirements ...
XOHCL iBar;
bool has = false;
bool isNewBar = false;
//
// Get Current Bar Time ...
datetime cBarTime = GetBarTime(
symbol,
period,
barIndex //
);
//
// Validate Bar Time ...
has = IsSpecifiedValid(cBarTime);
if (!has)
{
return;
}
//
// Check Process Permissions ...
has = CanAnalyseMarket(cBarTime);
if (!has)
{
return;
}
//
// Check if new Bar, Reset Processed Ticks Count ...
isNewBar = cBarTime > mLastCheckedBarTime;
if (isNewBar)
{
//
mProcessedTicksCount = 0;
ProcessNewBar(barIndex);
}
//
// Check Allow Process ...
// Process All Ticks ...
// Process New Bars ...
has = processAllTicks ||
(!processAllTicks && isNewBar);
if (!has)
{
return;
}
//
// Set Last Works ...
mProcessedTicksCount++;
mLastCheckedBarTime = cBarTime;
//
ProcessTick(barIndex);
}
//
// Virtuals ...
/**
* Processing Tick ...
*
* @param barIndex: int, Specified Bar Index ...
*/
virtual void ProcessTick(int barIndex = 0)
{
}
/**
* Processing New Bar ...
*
* @param barIndex: int, Specified Bar Index ...
*/
virtual void ProcessNewBar(int barIndex = 0)
{
}
/**
* Check Guards Based on MarketConditions ...
*
* @param guards: XGuard[]
* @param barIndex: int
*
* @return ( int )
*/
int virtual CheckForGuard(
XGuard &guards[],
int barIndex = 0 //
)
{
//
int result = 0;
//
SpecifiedClean(guards);
//
result = ArraySize(guards);
//
return result;
}
/**
* Check Additional Validations on Childs Instances ...
*
* @return ( bool virtual )
*/
bool virtual CheckAdditionslSignallerValidations()
{
return true;
}
//
// Protected ...
protected:
//
// Props ...
//
bool processAllTicks; // Specified Processing All Ticks or not ...
//
int mProcessedTicksCount; // Prcoessed Ticks Count ...
datetime mLastCheckedBarTime; // Last Checked Bar Time ...
//
double defaultSignalR2R; // Default Signal Risk To Reward Ratio ...
double defaultSignalVolume; // Default Signal Volume ...
double defaultSignalRiskInPoint; // Default Signal Risk In Point ...
//
// Event Notifiers ...
/**
* Notify OnSignal Event Listeners ...
*
* @param signal: XSignal, Specified Signal to Notify ...
*/
void NotifySignalEventListeners(XSignal &signal)
{
//
int count = ArraySize(onSignalEventListeners);
//
// Validate ...
if (!IsValidSize(count) || !signal.IsValid())
{
return;
}
//
// Do Notify ...
for (int i = 0; i < count; i++)
{
onSignalEventListeners[i](signal);
}
}
/**
* Calling Can Analyse Event Listeners ...
* Check Can Analayse Market or not ...
*
* @param time: datetime, Specified Time for Checking ...
*
* @return ( bool )
*/
bool CanAnalyseMarket(datetime time = NULL)
{
//
bool result = false;
//
// Normalize ...
time = NormalizeTime(time);
//
// Validation ...
result = IsValid();
if (!result)
{
return result;
}
//
result = canAnalyseEventListener == NULL;
if (result)
{
return result;
}
//
// Calling Can Analyse Event Listener ...
result = canAnalyseEventListener(
symbol,
period,
time //
);
//
return result;
}
/**
* Preparing Default Signal ...
*
* @param signal: XSignal, holding result Signal ...
* @param forDir: ENUM_X_DIRECTION
* @return ( bool )
*/
bool PrepareSignal(
XSignal &signal,
ENUM_X_DIRECTION forDir //
)
{
//
bool result = false;
//
// Prepare ...
signal.Clean();
//
// Normalize ...
//
// Validate ...
result = IsValid() &&
HasDirection(forDir);
if (!result)
{
return result;
}
//
bool isBullish = IsSpecifiedBullish(forDir);
//
double point = GetPoints(symbol);
double spread = GetSpread(symbol);
double volume = defaultSignalVolume;
double entry = GetEntry(symbol, forDir);
//
double risk = (defaultSignalRiskInPoint * point);
double reward = (risk * defaultSignalR2R) + spread;
//
double tp =
isBullish
? entry + reward
: entry - reward;
//
double sl =
isBullish
? entry - risk
: entry + risk;
//
// Filling Values ...
signal.tp = tp;
signal.sl = sl;
signal.entry = entry;
signal.provider = name;
signal.symbol = symbol;
signal.period = period;
signal.volume = volume;
signal.time = TimeCurrent();
//
// Validate Signal ...
result = signal.IsValid();
//
return result;
}
//
// Private ...
private:
//
// Props ...
//
// Event Listeners ...
TXCSignallerOnSignalEvent onSignalEventListeners[];
};
//
+8 -5
View File
@@ -16,6 +16,7 @@
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XBackTester"
#property icon "../Images/SaherElm_Logo_Color.ico"
#property strict
//
@@ -84,8 +85,9 @@ input ENUM_SERIESMODE lowerMode = MODE_LOW; // Vale Method
//
// Others ...
input ENUM_X_FIBO_LEVELS upperZoneLevel = X_FIBO_LEVEL_618; // Upper Zone Level
input ENUM_X_FIBO_LEVELS lowerZoneLevel = X_FIBO_LEVEL_382; // Lower Zone Level
input ENUM_X_FIBO_LEVELS fiboUpperZoneLevel = X_FIBO_LEVEL_382; // Upper Zone Level
input ENUM_X_FIBO_LEVELS fiboMiddleZoneLevel = X_FIBO_LEVEL_500; // Middle Zone Level
input ENUM_X_FIBO_LEVELS fiboLowerZoneLevel = X_FIBO_LEVEL_618; // Lower Zone Level
input double sarStep = 0.02; // SAR Step
input double sarMax = 0.2; // SAR Maximum
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
@@ -114,7 +116,7 @@ input bool showMAFast = true; // Show MA Fast
input bool showMASlow = true; // Show MA Slow
input bool showBarTime = true; // Show Bar Time
input bool showZigZag = true; // Show ZigZag
input bool showFiboZone = false; // Show Fibo Zone
input bool showFiboZone = true; // Show Fibo Zone
//
input int startCalculationForLastBars = 1500; // Calculate Last n Bars
@@ -249,8 +251,9 @@ int OnInit()
hcPeriod,
upperMode,
lowerMode,
upperZoneLevel,
lowerZoneLevel,
fiboUpperZoneLevel,
fiboMiddleZoneLevel,
fiboLowerZoneLevel,
sarStep,
sarMax,
maMethod,
File diff suppressed because it is too large Load Diff
+1
View File
@@ -33,6 +33,7 @@
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X121 XCATB Indicator"
#property icon "../Images/SaherElm_Logo_Color.ico"
#property strict
//
+1
View File
@@ -33,6 +33,7 @@
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X121 XCATB Indicator"
#property icon "../Images/SaherElm_Logo_Color.ico"
#property strict
//
+1
View File
@@ -17,6 +17,7 @@
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X121 XCC Indicator"
#property icon "../Images/SaherElm_Logo_Color.ico"
#property strict
//
+1
View File
@@ -17,6 +17,7 @@
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X121 XCT Indicator"
#property icon "../Images/SaherElm_Logo_Color.ico"
#property strict
//
+1
View File
@@ -18,6 +18,7 @@
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X121 XMA Indicator"
#property icon "../Images/SaherElm_Logo_Color.ico"
#property strict
//
+62 -25
View File
@@ -18,6 +18,7 @@
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XFIMA Indicator"
#property icon "../Images/SaherElm_Logo_Color.ico"
#property strict
//
@@ -73,8 +74,9 @@ input ENUM_SERIESMODE lowerMode = MODE_LOW; // Vale Method
//
// Others ...
input ENUM_X_FIBO_LEVELS upperZoneLevel = X_FIBO_LEVEL_618; // Upper Zone Level
input ENUM_X_FIBO_LEVELS lowerZoneLevel = X_FIBO_LEVEL_382; // Lower Zone Level
input ENUM_X_FIBO_LEVELS fiboUpperZoneLevel = X_FIBO_LEVEL_382; // Upper Zone Level
input ENUM_X_FIBO_LEVELS fiboMiddleZoneLevel = X_FIBO_LEVEL_500; // Upper Zone Level
input ENUM_X_FIBO_LEVELS fiboLowerZoneLevel = X_FIBO_LEVEL_618; // Lower Zone Level
input double sarStep = 0.02; // SAR Step
input double sarMax = 0.2; // SAR Maximum
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
@@ -129,8 +131,8 @@ input int valeArrowCode = 159; // Vales Arrow Code
#property indicator_chart_window
//
#property indicator_buffers 26
#property indicator_plots 8
#property indicator_buffers 27
#property indicator_plots 9
//
// Plot Buffers ...
@@ -150,8 +152,8 @@ double maFastColorBuffer[];
//
#property indicator_label1 "FastMA"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrYellow, clrOrangeRed, clrGray
#property indicator_width1 2
#property indicator_color1 CLR_NONE, clrAquamarine, clrAquamarine, clrAquamarine // clrYellow, clrOrangeRed, clrGray
#property indicator_width1 3
//
// Slow MA ...
@@ -168,8 +170,8 @@ double maSlowColorBuffer[];
//
#property indicator_label2 "SlowMA"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 CLR_NONE, clrLime, clrRed, clrGray
#property indicator_width2 2
#property indicator_color2 CLR_NONE, clrLightCoral, clrLightCoral, clrLightCoral // clrLime, clrRed, clrGray
#property indicator_width2 3
//
// SAR ...
@@ -231,39 +233,53 @@ double fiboUpperBuffer[];
#property indicator_color6 clrAqua
#property indicator_width6 2
//
// FIBO Middle ...
//
#define fiboMiddleBufferIndex 9
#define fiboMiddleBufferPlotIndex 6
double fiboMiddleBuffer[];
//
#property indicator_label7 "FIBMID"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrBrown
#property indicator_width7 2
//
// FIBO Lower ...
//
#define fiboLowerBufferIndex 9
#define fiboLowerBufferPlotIndex 6
#define fiboLowerBufferIndex 10
#define fiboLowerBufferPlotIndex 7
double fiboLowerBuffer[];
//
#property indicator_label7 "FIBLO"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrMagenta
#property indicator_width7 2
#property indicator_label8 "FIBLO"
#property indicator_type8 DRAW_LINE
#property indicator_color8 clrMagenta
#property indicator_width8 2
//
// ZigZag ...
//
#define zigzagBufferIndex 10
#define zigzagBufferPlotIndex 7
#define zigzagBufferIndex 11
#define zigzagBufferPlotIndex 8
double zigzagBuffer[];
//
#property indicator_label8 "XZG"
#property indicator_type8 DRAW_SECTION
#property indicator_color8 clrYellow
#property indicator_width8 2
#property indicator_label9 "XZG"
#property indicator_type9 DRAW_SECTION
#property indicator_color9 clrYellow
#property indicator_width9 2
//
// Data Buffers ...
//
#define mLastBufferIndex 10
#define mLastBufferIndex 11
//
// MA ...
@@ -825,6 +841,16 @@ void DefineBuffers()
PlotIndexSetInteger(fiboUpperBufferPlotIndex, PLOT_DRAW_TYPE, fiboZoneDrawType);
PlotIndexSetDouble(fiboUpperBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// Middle ...
ArraySetAsSeries(fiboMiddleBuffer, true);
SetIndexBuffer(fiboMiddleBufferIndex, fiboMiddleBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(fiboMiddleBufferPlotIndex, PLOT_SHOW_DATA, showFiboZone);
PlotIndexSetInteger(fiboMiddleBufferPlotIndex, PLOT_DRAW_TYPE, fiboZoneDrawType);
PlotIndexSetDouble(fiboMiddleBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// Lower ...
ArraySetAsSeries(fiboLowerBuffer, true);
@@ -1294,18 +1320,29 @@ void CalculateValues(
double iFiboUp = GetFibonacciLevel(
iPeak,
iVale,
upperZoneLevel,
X_DIRECTION_BULLISH);
fiboUpperZoneLevel,
X_DIRECTION_BULLISH //
);
//
double iFiboMid = GetFibonacciLevel(
iPeak,
iVale,
fiboMiddleZoneLevel,
X_DIRECTION_BULLISH //
);
//
double iFiboLo = GetFibonacciLevel(
iPeak,
iVale,
lowerZoneLevel,
X_DIRECTION_BULLISH);
fiboLowerZoneLevel,
X_DIRECTION_BULLISH //
);
//
fiboUpperBuffer[barIndex] = iFiboUp;
fiboMiddleBuffer[barIndex] = iFiboMid;
fiboLowerBuffer[barIndex] = iFiboLo;
}
+1
View File
@@ -18,6 +18,7 @@
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XOM1 Indicator"
#property icon "../Images/SaherElm_Logo_Color.ico"
#property strict
//
@@ -0,0 +1,24 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class
// -------------------------------------------------
// Name: XCXFIMASignaller ...
// Description: XFIMA Signaller Class ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm Base Signaller Class"
#property strict
//
// Imports ...