773 lines
17 KiB
Plaintext
773 lines
17 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"
|
|
#include "../Classes/x-saherelm.xfima.x-poi.detector.class.mq5"
|
|
|
|
//
|
|
// Implementation ...
|
|
|
|
//
|
|
// Base XFIMA base Signaller ...
|
|
class XCXFIMABaseSignaller : public XCBaseSignaller
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
XFIMAInputs fimaInputs; // XFIMA Inputs ...
|
|
XCXFIMAHelper *fimaHelper; // XFIMA Indicator Helper ...
|
|
XCXFIMAPOIDetector *fimaPOIDetector; // XFIMA POI Detector ...
|
|
|
|
//
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
//
|
|
fimaPOIDetector = new XCXFIMAPOIDetector();
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
~XCXFIMABaseSignaller()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
//
|
|
// Overrides ...
|
|
|
|
//
|
|
// Actions ...
|
|
|
|
/**
|
|
* Destroy ...
|
|
*/
|
|
void Destroy()
|
|
{
|
|
//
|
|
BeforeDestroy();
|
|
|
|
//
|
|
fimaInputs.Clean();
|
|
|
|
//
|
|
delete fimaHelper;
|
|
ZeroMemory(fimaHelper);
|
|
|
|
//
|
|
delete fimaPOIDetector;
|
|
ZeroMemory(fimaPOIDetector);
|
|
}
|
|
|
|
//
|
|
// 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 &&
|
|
fimaPOIDetector != NULL;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Normalizing Signal by Signaller Custom Props ...
|
|
*
|
|
* @param signal: XSignal ...
|
|
*/
|
|
void virtual NormalizeSignal(XSignal &signal)
|
|
{
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
};
|
|
|
|
//
|
|
// XFIMA Strategy 1 Signaller Class ...
|
|
class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Props ...
|
|
int fvgLookupLenght; // Maximum Lenght for Looking up FVG before Crosses
|
|
|
|
//
|
|
// 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 //
|
|
)
|
|
{
|
|
//
|
|
fvgLookupLenght = 5;
|
|
}
|
|
|
|
//
|
|
// 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 ...
|
|
|
|
//
|
|
// Validate MA Positions ...
|
|
double iFastMa = fimaConditions.maFastBuffer[cIdx];
|
|
double iSlowMa = fimaConditions.maSlowBuffer[cIdx];
|
|
double iFiboUpper = fimaConditions.fiboUpperBuffer[cIdx];
|
|
double iFiboLower = fimaConditions.fiboLowerBuffer[cIdx];
|
|
|
|
//
|
|
// Checking Has FVG ...
|
|
XBoxZone fvg;
|
|
ENUM_X_DIRECTION fvgDir;
|
|
bool hasFVG = patternDetector.HasFVG(
|
|
bar,
|
|
fvgDir,
|
|
fvg,
|
|
fvgLookupLenght //
|
|
);
|
|
|
|
//
|
|
// Checking Crossed On Shadow ...
|
|
|
|
//
|
|
bool isCrossedOverHappensOnShadow =
|
|
isFastCrossedOverSlow &&
|
|
iFastMa <= bar.GetDown() &&
|
|
iFastMa >= bar.low;
|
|
|
|
//
|
|
bool isCrossedUnderHappensOnShadow =
|
|
isFastCrossedUnderSlow &&
|
|
iFastMa <= bar.high &&
|
|
iFastMa >= bar.GetUp();
|
|
|
|
//
|
|
// Bullish Validation ...
|
|
bool isBullish =
|
|
//
|
|
// Has Cross ...
|
|
isFastCrossedOverSlow
|
|
//
|
|
&&
|
|
//
|
|
// Cross Places Based on Fibo ...
|
|
MathMax(iFastMa, iSlowMa) < iFiboLower
|
|
//
|
|
&&
|
|
//
|
|
(
|
|
//
|
|
// Checking FVG ...
|
|
(hasFVG &&
|
|
fvg.IsBullish())
|
|
//
|
|
||
|
|
//
|
|
// Checking Crossed Place ...
|
|
isCrossedOverHappensOnShadow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bearish Validation ...
|
|
bool isBearish =
|
|
//
|
|
// Has Cross ...
|
|
isFastCrossedUnderSlow
|
|
//
|
|
&&
|
|
//
|
|
// Cross Places Based on Fibo ...
|
|
MathMin(iFastMa, iSlowMa) > iFiboUpper
|
|
//
|
|
&&
|
|
//
|
|
(
|
|
//
|
|
// Checking FVG ...
|
|
(hasFVG &&
|
|
fvg.IsBearish())
|
|
//
|
|
||
|
|
//
|
|
// Checking Crossed Place ...
|
|
isCrossedUnderHappensOnShadow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
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 ...
|
|
XTarget targets[];
|
|
has = PrepareSignal(
|
|
signal,
|
|
signalDir,
|
|
targets //
|
|
);
|
|
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;
|
|
}
|
|
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Lookup FVG ...
|
|
bool LookupFVG(
|
|
XOHCL &bar,
|
|
ENUM_X_DIRECTION &dir,
|
|
XBoxZone &fvgBox //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// XFIMA Strategy 2 Signaller Class ...
|
|
class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Constructor ...
|
|
XCXFIMAStrategy2Signaller(
|
|
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("XFIMA2",
|
|
_symbol,
|
|
_period,
|
|
_fimaInputs,
|
|
_processAllTicks,
|
|
_defaultSignalR2R,
|
|
_defaultSignalRiskInPoint,
|
|
_defaultSignalVolume //
|
|
)
|
|
{
|
|
}
|
|
|
|
//
|
|
// Reading ZigZag ...
|
|
|
|
//
|
|
bool GetZigZagPoint()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// 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 ...
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
// Chekc Bullish or Bearish Starter Conditions ...
|
|
has =
|
|
isBullish ||
|
|
isBearish;
|
|
if (has)
|
|
{
|
|
//
|
|
// Do Conditions Validating ...
|
|
|
|
//
|
|
// Bullish Validation ...
|
|
isBullish =
|
|
//
|
|
isBullish
|
|
//
|
|
&&
|
|
//
|
|
// Validations ...
|
|
(
|
|
//
|
|
false
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bearish Validation ...
|
|
isBearish =
|
|
//
|
|
isBearish
|
|
//
|
|
&&
|
|
//
|
|
// Validations ...
|
|
(
|
|
//
|
|
false
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
has =
|
|
(isBullish && !isBearish) ||
|
|
(isBearish && !isBullish);
|
|
if (has)
|
|
{
|
|
//
|
|
// Specified Signal Directions ...
|
|
signalDir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Check Signal Founded ...
|
|
has = HasDirection(signalDir);
|
|
if (has)
|
|
{
|
|
//
|
|
// TODO: Provided SL ...
|
|
|
|
//
|
|
// Prepare Founded Signal ...
|
|
XTarget targets[];
|
|
has = PrepareSignal(
|
|
signal,
|
|
signalDir,
|
|
targets //
|
|
);
|
|
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;
|
|
}
|
|
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
};
|
|
|
|
// |