Files
MQL5Data/XFIMA/Classes/x-saherelm.xfima.signaller.class.mq5
T
2025-09-17 23:40:07 +03:30

411 lines
9.0 KiB
Plaintext

///////////////////////////////////////////////////////
//
// 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 XFIMA Signaller Class"
#property strict
//
// Imports ...
#include "../../Classes/x-saherelm.x-signaller.class.mq5"
#include "../../Helpers/x-saherelm.xfima.helper.mq5"
//
// Implementation ...
//
// Base XFIMA base Signaller ...
class XCXFIMABaseSignaller : public XCBaseSignaller
{
//
// Public ...
public:
//
// Props ...
//
XFIMAInputs fimaInputs; // XFIMA Inputs ...
XCXFIMAHelper *fimaHelper; // XFIMA Indicator Helper ...
//
// Constructor ...
XCXFIMABaseSignaller(
string _name, // Name ...
string _symbol, // Symbol ...
ENUM_TIMEFRAMES _period, // Period ...
XFIMAInputs &_fimaInputs, // XFIMAInputs ...
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 ...
) : XCBaseSignaller(_name,
_symbol,
_period,
_processAllTicks,
_defaultSignalR2R,
_defaultSignalRiskInPoint,
_defaultSignalVolume //
)
{
//
// Instantiating XFIMA Indicator Helper Class ...
if (_fimaInputs.IsValid())
{
//
fimaHelper = new XCXFIMAHelper();
bool isInited = fimaHelper.Init(
_symbol,
_period,
_fimaInputs //
);
if (isInited)
{
fimaInputs = _fimaInputs;
}
else
{
//
delete fimaHelper;
ZeroMemory(fimaHelper);
}
}
}
//
// Deconstructor ...
~XCXFIMABaseSignaller()
{
Destroy();
}
//
// Overrides ...
//
// Actions ...
/**
* Destroy ...
*/
void Destroy()
{
//
BeforeDestroy();
//
fimaInputs.Clean();
//
delete fimaHelper;
ZeroMemory(fimaHelper);
}
//
// Virtuals ...
/**
* Before Destroy ...
*/
void virtual BeforeDestroy()
{
}
/**
* 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()
{
//
bool result = false;
//
// Validate Fima Helper Requirements ...
result = fimaInputs.IsValid() &&
fimaHelper != NULL;
//
return result;
}
//
// Protected ...
protected:
//
//
// Private ...
private:
//
};
//
// XFIMA Strategy 1 Signaller Class ...
class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
{
//
// Public ...
public:
//
// Props ...
//
// Constructor ...
XCXFIMAStrategy1Signaller(
string _symbol, // Symbol ...
ENUM_TIMEFRAMES _period, // Period ...
XFIMAInputs &_fimaInputs, // XFIMAInputs ...
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 ...
) : XCXFIMABaseSignaller("XFIMA1",
_symbol,
_period,
_fimaInputs,
_processAllTicks,
_defaultSignalR2R,
_defaultSignalRiskInPoint,
_defaultSignalVolume //
)
{
}
//
// Overrides ...
/**
* 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)
{
//
// Normalize ...
barIndex = NormalizeInt(barIndex, 0);
//
// Update Helper ...
fimaHelper.Update(barIndex);
//
XOHCL bar;
XSignal signal;
bool has = false;
int cIdx = barIndex + 1;
int pIdx = cIdx + 1;
ENUM_X_DIRECTION signalDir = X_DIRECTION_NONE;
//
// Initialize Bar as CBar ...
has = bar.Init(
symbol,
period,
cIdx //
);
if (!has)
{
//
bar.Clean();
return;
}
//
// Retrieve Conditions ...
XFIMAConditions fimaConditions;
has = fimaHelper.GetConditions(
fimaConditions,
barIndex,
10 // Loopback ...
);
if (!has)
{
//
bar.Clean();
fimaConditions.Clean();
//
return;
}
//
// Analyse Conditions for Finding Signal ...
//
// TODO: Remove this ...
//
bool isFastCrossedOverSlow =
fimaConditions.maFastBuffer[cIdx] > fimaConditions.maSlowBuffer[cIdx] &&
fimaConditions.maFastBuffer[pIdx] < fimaConditions.maSlowBuffer[pIdx];
//
bool isFastCrossedUnderSlow =
fimaConditions.maFastBuffer[cIdx] < fimaConditions.maSlowBuffer[cIdx] &&
fimaConditions.maFastBuffer[pIdx] > fimaConditions.maSlowBuffer[pIdx];
//
has =
isFastCrossedOverSlow ||
isFastCrossedUnderSlow;
if (has)
{
//
// Do Conditions Validating ...
//
// Bullish Validation ...
bool isBullish =
//
isFastCrossedOverSlow
//
;
//
// Bearish Validation ...
bool isBearish =
//
isFastCrossedUnderSlow
//
;
//
has =
(isBullish && !isBearish) ||
(isBearish && !isBullish);
if (has)
{
//
signalDir =
isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
}
}
//
// Check Signal Founded ...
has = HasDirection(signalDir);
if (has)
{
//
// Prepare Founded Signal ...
has = PrepareSignal(
signal,
signalDir //
);
if (has)
{
//
// Notify On Signal Event ...
NotifySignalEventListeners(signal);
}
}
//
// Cleanup Resources ...
bar.Clean();
signal.Clean();
fimaConditions.Clean();
}
/**
* 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;
}
//
};
//