502 lines
9.8 KiB
Plaintext
502 lines
9.8 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 X121 SMC Signal Class
|
|
// -------------------------------------------------
|
|
// Name: XWZ
|
|
// Description: provide all Signalling functions ...
|
|
//
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////
|
|
//
|
|
// Global Properties ...
|
|
#property library
|
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
#property link "https://www.saherelm.ir"
|
|
#property version "1.00"
|
|
#property strict
|
|
|
|
//
|
|
// Imports ...
|
|
// #include "../../Libraries/x-trade.lib"
|
|
#include "../Classes/x-121.smc.market.cycle.helper.class.mq5"
|
|
#include "../Libraries/x-121.smc.guard.lib.mq5"
|
|
#include "../Libraries/x-121.smc.lib.mq5"
|
|
|
|
//
|
|
enum ENUM_X121SMC_XWZ_PRIORITY
|
|
{
|
|
X121SMC_XWZ_PRIORITY_NONE,
|
|
X121SMC_XWZ_PRIORITY_WEAK,
|
|
X121SMC_XWZ_PRIORITY_LOW,
|
|
X121SMC_XWZ_PRIORITY_REGULAR,
|
|
X121SMC_XWZ_PRIORITY_HIGH,
|
|
X121SMC_XWZ_PRIORITY_STRONG_HIGH,
|
|
};
|
|
|
|
//
|
|
// Definitions ...
|
|
struct X121SMCStrategyXWZSignalConditions
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
|
|
//
|
|
double sl;
|
|
double target;
|
|
double reward;
|
|
double amountPercent;
|
|
ENUM_X_DIRECTION dir;
|
|
ENUM_X_POSITION_TYPES type;
|
|
|
|
//
|
|
// Setup Props ...
|
|
|
|
//
|
|
datetime setupTime;
|
|
datetime triggerTime;
|
|
|
|
//
|
|
double pivot;
|
|
double point;
|
|
|
|
//
|
|
ENUM_X121SMC_XWZ_PRIORITY priority;
|
|
|
|
//
|
|
XOBFVG orderFlow[];
|
|
|
|
//
|
|
// Constructor ...
|
|
X121SMCStrategyXWZSignalConditions()
|
|
{
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
/**
|
|
* Cleaning Up ...
|
|
*/
|
|
void Clean()
|
|
{
|
|
//
|
|
sl = 0;
|
|
target = 0;
|
|
|
|
//
|
|
dir = X_DIRECTION_NONE;
|
|
type = X_POSITION_TYPE_NONE;
|
|
|
|
//
|
|
symbol = NULL;
|
|
period = NULL;
|
|
setupTime = NULL;
|
|
triggerTime = NULL;
|
|
|
|
//
|
|
ExtensionClean();
|
|
|
|
//
|
|
ZeroMemory(this);
|
|
}
|
|
|
|
/**
|
|
* Check Condition is Setting Up ...
|
|
*
|
|
* @param dir: ENUM_X_DIRECTION member, Setting Up Direction ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool IsSetuped()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = IsValid(setupTime) &&
|
|
HasDirection(dir);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Calculate Setup Age ...
|
|
*
|
|
* @return ( int )
|
|
*/
|
|
int GetSetupAge()
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
if (!IsSetuped())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Detect How we Can Trigger Signal ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool CanTrigger()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
sl > 0 &&
|
|
IsValid(symbol) &&
|
|
IsValid(period) &&
|
|
IsValid(triggerTime) &&
|
|
type != X_POSITION_TYPE_ALL &&
|
|
type != X_POSITION_TYPE_NONE
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Extensions ...
|
|
|
|
/**
|
|
* Clean Additional Properties ...
|
|
*/
|
|
void ExtensionClean()
|
|
{
|
|
//
|
|
pivot = 0;
|
|
point = 0;
|
|
|
|
//
|
|
target = 0;
|
|
reward = 0;
|
|
amountPercent = 0;
|
|
|
|
//
|
|
// startZone.Clean();
|
|
Clean(orderFlow);
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
bool HasOrderFlow()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = HasChild(orderFlow);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool HasOrderFlow(
|
|
ENUM_X_DIRECTION &orderFlowDir //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = HasChild(orderFlow);
|
|
if (result)
|
|
{
|
|
orderFlowDir = orderFlow[0].GetDirection();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int CountOrderFlow()
|
|
{
|
|
return ArraySize(orderFlow);
|
|
}
|
|
|
|
//
|
|
int GetSwings(
|
|
XOBFVGPivot &pivots[] //
|
|
)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
Clean(pivots);
|
|
|
|
//
|
|
int count = 0;
|
|
bool has = false;
|
|
|
|
//
|
|
has = HasOrderFlow();
|
|
if (!has)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
count = CountOrderFlow();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XOBFVGPivot iPivots[];
|
|
int iPivotsCount = orderFlow[i]
|
|
.GetSwings(iPivots);
|
|
bool hasPivots = IsValidSize(iPivotsCount);
|
|
if (hasPivots)
|
|
{
|
|
//
|
|
Copy(
|
|
iPivots,
|
|
pivots,
|
|
false //
|
|
);
|
|
}
|
|
|
|
//
|
|
Clean(iPivots);
|
|
}
|
|
|
|
//
|
|
result = ArraySize(pivots);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
void UpdateTo(datetime value = NULL)
|
|
{
|
|
//
|
|
value = NormalizeTime(value);
|
|
|
|
//
|
|
int count = 0;
|
|
bool has = false;
|
|
|
|
//
|
|
// Order Flow ...
|
|
ENUM_X_DIRECTION orderFlowDir;
|
|
has = HasOrderFlow(orderFlowDir);
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountOrderFlow();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
orderFlow[i].UpdateTo(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
int DetectOrderFlow(
|
|
ENUM_X_DIRECTION &orderFlowDir,
|
|
XPOIState &htfState,
|
|
XPOIState &mtfState,
|
|
XPOIState &stfState //
|
|
)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
Clean(orderFlow);
|
|
orderFlowDir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
bool isValid =
|
|
//
|
|
IsValid(symbol) &&
|
|
IsValid(period) &&
|
|
htfState.HasChild() &&
|
|
mtfState.HasChild() &&
|
|
stfState.HasChild()
|
|
//
|
|
;
|
|
if (!isValid)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Bullish OBFVGs ...
|
|
XOBFVG bullOBFVGs[];
|
|
int bullOBFVGsCount = ExtractOBFVGZones(
|
|
htfState,
|
|
mtfState,
|
|
stfState,
|
|
bullOBFVGs,
|
|
X_DIRECTION_BULLISH,
|
|
NULL, // For Period ...
|
|
//
|
|
// Start ...
|
|
XZONE_STATE_PASSED,
|
|
true, // Force Body Out ...
|
|
//
|
|
// Activation ...
|
|
XZONE_STATE_PASSED,
|
|
true, // Force Body In ...
|
|
//
|
|
// Breaktion ...
|
|
XZONE_STATE_FAILED,
|
|
false, // Force Body In ...
|
|
//
|
|
// Works ...
|
|
XZONE_STATE_PASSED,
|
|
true, // Force Body Out ...
|
|
//
|
|
true, // Apply Sort ...
|
|
true, // From Filter ...
|
|
true, // Place Filter ...
|
|
//
|
|
true, // Ignore Inside in Place Filter ...
|
|
//
|
|
true, // Detect Inside OB POI(s) ...
|
|
true, // Detect Inside FVG POI(s) ...
|
|
true // Apply From Filter to Selected POI(s) ...
|
|
);
|
|
bool hasBullOBFVGs = IsValidSize(bullOBFVGsCount);
|
|
|
|
//
|
|
// Bearish OBFVGs ...
|
|
XOBFVG bearOBFVGs[];
|
|
int bearOBFVGsCount = ExtractOBFVGZones(
|
|
htfState,
|
|
mtfState,
|
|
stfState,
|
|
bearOBFVGs,
|
|
X_DIRECTION_BEARISH,
|
|
NULL, // For Period ...
|
|
//
|
|
// Start ...
|
|
XZONE_STATE_PASSED,
|
|
true, // Force Body Out ...
|
|
//
|
|
// Activation ...
|
|
XZONE_STATE_PASSED,
|
|
true, // Force Body In ...
|
|
//
|
|
// Breaktion ...
|
|
XZONE_STATE_FAILED,
|
|
false, // Force Body In ...
|
|
//
|
|
// Works ...
|
|
XZONE_STATE_PASSED,
|
|
true, // Force Body Out ...
|
|
//
|
|
true, // Apply Sort ...
|
|
true, // From Filter ...
|
|
true, // Place Filter ...
|
|
//
|
|
true, // Ignore Inside in Place Filter ...
|
|
//
|
|
true, // Detect Inside OB POI(s) ...
|
|
true, // Detect Inside FVG POI(s) ...
|
|
true // Apply From Filter to Selected POI(s) ...
|
|
);
|
|
bool hasBearOBFVGs = IsValidSize(bearOBFVGsCount);
|
|
|
|
//
|
|
bool hasOrderBlow = hasBearOBFVGs ||
|
|
hasBullOBFVGs;
|
|
if (hasOrderBlow)
|
|
{
|
|
//
|
|
// Vlidate ...
|
|
bool isValid =
|
|
//
|
|
(hasBullOBFVGs &&
|
|
!hasBearOBFVGs &&
|
|
bullOBFVGsCount > 1)
|
|
//
|
|
||
|
|
//
|
|
(hasBearOBFVGs &&
|
|
!hasBullOBFVGs &&
|
|
bearOBFVGsCount > 1)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (isValid)
|
|
{
|
|
//
|
|
if (hasBullOBFVGs)
|
|
{
|
|
//
|
|
Copy(
|
|
bullOBFVGs,
|
|
orderFlow //
|
|
);
|
|
}
|
|
else if (hasBearOBFVGs)
|
|
{
|
|
//
|
|
Copy(
|
|
bearOBFVGs,
|
|
orderFlow //
|
|
);
|
|
}
|
|
|
|
//
|
|
orderFlowDir =
|
|
hasBullOBFVGs
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
result = ArraySize(orderFlow);
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(bullOBFVGs);
|
|
Clean(bearOBFVGs);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
// |