6565 lines
141 KiB
Plaintext
6565 lines
141 KiB
Plaintext
////////////////////////////////////////////
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 X121 SMC Signal Class
|
|
// -------------------------------------------------
|
|
// Name:
|
|
// 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 "../Classes/x-121.smc.market.cycle.helper.class.mq5"
|
|
#include "../Libraries/x-121.smc.lib.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
struct X121SMCStrategyXVWPBSignalConditions
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
|
|
//
|
|
double sl;
|
|
double target;
|
|
ENUM_X_DIRECTION dir;
|
|
ENUM_X_POSITION_TYPES type;
|
|
|
|
//
|
|
// Setup Props ...
|
|
|
|
//
|
|
datetime setupTime;
|
|
datetime triggerTime;
|
|
|
|
//
|
|
// Constructor ...
|
|
X121SMCStrategyXVWPBSignalConditions()
|
|
{
|
|
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();
|
|
}
|
|
|
|
/**
|
|
* 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()
|
|
{
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Extension Functions ...
|
|
|
|
//
|
|
// Detect Setup Conditions ...
|
|
bool DetectX121SMCXVWPBSiganlSetup(
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
X121SMCStrategyXVWPBSignalConditions &conditions,
|
|
//
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
string symbol = _symbol;
|
|
ENUM_TIMEFRAMES period = _period;
|
|
|
|
//
|
|
conditions.symbol = symbol;
|
|
conditions.period = period;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL pBar;
|
|
result = pBar.Init(
|
|
symbol,
|
|
period,
|
|
pIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
double ll = cBar.FindLowest(9, MODE_LOW);
|
|
double hh = cBar.FindHighest(9, MODE_HIGH);
|
|
|
|
//
|
|
int zoneValidationDivider = 10;
|
|
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
|
.GetDonChainLength();
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
|
X121SMCCycleConditions triggerConditions;
|
|
result = triggerCycleHelper.GetConditions(
|
|
triggerCycleEvents,
|
|
triggerPoiEvents,
|
|
triggerConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
|
X121SMCCycleConditions verificationConditions;
|
|
result = verificationCycleHelper.GetConditions(
|
|
verificationCycleEvents,
|
|
verificationPoiEvents,
|
|
verificationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState triggerState = triggerConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState verificationState = verificationConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Setup Conditions ...
|
|
|
|
//
|
|
// Detect Market Trend ...
|
|
// ENUM_X_DIRECTION trend;
|
|
// bool hasTrend = consolidationCycleHelper
|
|
// .DetectTrend(trend);
|
|
// bool hasBullishTrend = hasTrend &&
|
|
// IsBullish(trend);
|
|
// bool hasBearishTrend = hasTrend &&
|
|
// IsBearish(trend);
|
|
// result = hasBullishTrend ||
|
|
// hasBearishTrend;
|
|
// if (!result)
|
|
// {
|
|
// return result;
|
|
// }
|
|
|
|
//
|
|
// Detect VWAP Bearish ...
|
|
|
|
//
|
|
double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1];
|
|
double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1];
|
|
double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1];
|
|
|
|
//
|
|
double vwaps[3] = {
|
|
vwapFast,
|
|
vwapMid,
|
|
vwapSlow,
|
|
};
|
|
double vwapMax = GetMax(vwaps);
|
|
double vwapMin = GetMin(vwaps);
|
|
|
|
//
|
|
bool isCloseOverVwapMax =
|
|
//
|
|
ask > vwapMax &&
|
|
bid > vwapMax &&
|
|
(cBar.low > vwapMax ||
|
|
cBar.close > vwapMax)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCloseUnderVwapMin =
|
|
//
|
|
ask < vwapMin &&
|
|
bid < vwapMin &&
|
|
(cBar.high < vwapMin ||
|
|
cBar.close < vwapMin)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isVWapBullishState = triggerConditions.x121Conditions.isVWapBullishState;
|
|
bool isVWapSwitchedToBullishState = triggerConditions.x121Conditions.isVWapSwitchedToBullishState;
|
|
|
|
//
|
|
bool isVWapBearishState = triggerConditions.x121Conditions.isVWapBearishState;
|
|
bool isVWapSwitchedToBearishState = triggerConditions.x121Conditions.isVWapSwitchedToBearishState;
|
|
|
|
//
|
|
bool isVWapBullishOrdered = triggerConditions.x121Conditions.isVWapBullishOrdered;
|
|
bool isVWapSwitchedToBullishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBullishOrdered;
|
|
|
|
//
|
|
bool isVWapBearishOrdered = triggerConditions.x121Conditions.isVWapBearishOrdered;
|
|
bool isVWapSwitchedToBearishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBearishOrdered;
|
|
|
|
//
|
|
// Summary VWap ...
|
|
|
|
//
|
|
bool isVwapBullishFormed =
|
|
//
|
|
isVWapSwitchedToBullishState
|
|
// isCloseOverVwapMax
|
|
// //
|
|
// &&
|
|
//
|
|
// (
|
|
// //
|
|
// // (isVWapBullishOrdered &&
|
|
// // isVWapSwitchedToBullishState)
|
|
// // //
|
|
// // ||
|
|
// // //
|
|
// // (isVWapBullishState &&
|
|
// // isVWapSwitchedToBullishOrdered)
|
|
// //
|
|
// )
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isVwapBearishFormed =
|
|
//
|
|
isVWapSwitchedToBearishState
|
|
// isCloseUnderVwapMin
|
|
// //
|
|
// &&
|
|
//
|
|
// (
|
|
// //
|
|
// // (isVWapBearishOrdered &&
|
|
// // isVWapSwitchedToBearishState)
|
|
// // //
|
|
// // ||
|
|
// // //
|
|
// // (isVWapBearishState &&
|
|
// // isVWapSwitchedToBearishOrdered)
|
|
// //
|
|
// )
|
|
//
|
|
;
|
|
|
|
//
|
|
isBullish =
|
|
// hasBullishTrend &&
|
|
isVwapBullishFormed;
|
|
|
|
//
|
|
isBearish =
|
|
// hasBearishTrend &&
|
|
isVwapBearishFormed;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
|
|
//
|
|
// if (!result)
|
|
// {
|
|
// return result;
|
|
// }
|
|
|
|
// //
|
|
// double sar = triggerConditions.x121Conditions.sarBuffer[1];
|
|
|
|
// //
|
|
// bool isSarBullish = triggerConditions.x121Conditions.isSarBullish;
|
|
// bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish;
|
|
|
|
// //
|
|
// bool isSarBearish = triggerConditions.x121Conditions.isSarBearish;
|
|
// bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish;
|
|
|
|
// //
|
|
// bool isSarBullishFormed = isSarBullish ||
|
|
// isSarSwitchedToBullish;
|
|
|
|
// //
|
|
// bool isSarBearishFormed = isSarBearish ||
|
|
// isSarSwitchedToBearish;
|
|
|
|
// //
|
|
// isBullish =
|
|
// isBullish &&
|
|
// isSarBullishFormed;
|
|
|
|
// //
|
|
// isBearish =
|
|
// isBearish &&
|
|
// isSarBearishFormed;
|
|
|
|
// //
|
|
// result = isBullish ||
|
|
// isBearish;
|
|
// if (!result)
|
|
// {
|
|
// return result;
|
|
// }
|
|
|
|
// //
|
|
// // Detect Pull Backs ...
|
|
|
|
// //
|
|
// bool isSignalBarBullishPullBackFormed =
|
|
// cBar.IsBearish() &&
|
|
// pBar.IsBullish() &&
|
|
// cBar.low > pBar.low;
|
|
|
|
// //
|
|
// bool isSignalBarBearishPullBackFormed =
|
|
// cBar.IsBullish() &&
|
|
// pBar.IsBearish() &&
|
|
// cBar.high < pBar.high;
|
|
|
|
// //
|
|
// // Summary Pull Backs ...
|
|
|
|
// //
|
|
// bool isBullishBarFormed =
|
|
// isSignalBarBullishPullBackFormed;
|
|
|
|
// //
|
|
// bool isBearishhBarFormed =
|
|
// isSignalBarBearishPullBackFormed;
|
|
|
|
// //
|
|
// isBullish =
|
|
// isBullish &&
|
|
// isBullishBarFormed;
|
|
|
|
// //
|
|
// isBearish =
|
|
// isBearish &&
|
|
// isBearishhBarFormed;
|
|
|
|
// //
|
|
// result = isBullish ||
|
|
// isBearish;
|
|
// if (!result)
|
|
// {
|
|
// return result;
|
|
// }
|
|
|
|
// //
|
|
// isBullish =
|
|
// //
|
|
// false
|
|
// //
|
|
// ;
|
|
|
|
// //
|
|
// isBearish =
|
|
// //
|
|
// false
|
|
// //
|
|
// ;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Clean Conditions for Regenerate ...
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.setupTime = cTime;
|
|
conditions.dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Trigger Conditions ...
|
|
bool DetectX121SMCXVWPBSiganlTrigger(
|
|
//
|
|
X121SMCStrategyXVWPBSignalConditions &conditions,
|
|
//
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper,
|
|
//
|
|
int maxAllowedSetupAge = 60 //
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = conditions.IsSetuped();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
datetime setupTime = conditions.setupTime;
|
|
ENUM_X_DIRECTION setupDir = conditions.dir;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
string symbol = _symbol;
|
|
ENUM_TIMEFRAMES period = _period;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL pBar;
|
|
result = pBar.Init(
|
|
symbol,
|
|
period,
|
|
pIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
double ll = cBar.FindLowest(9, MODE_LOW);
|
|
double hh = cBar.FindHighest(9, MODE_HIGH);
|
|
|
|
//
|
|
int zoneValidationDivider = 10;
|
|
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
|
.GetDonChainLength();
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
|
X121SMCCycleConditions triggerConditions;
|
|
result = triggerCycleHelper.GetConditions(
|
|
triggerCycleEvents,
|
|
triggerPoiEvents,
|
|
triggerConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
|
X121SMCCycleConditions verificationConditions;
|
|
result = verificationCycleHelper.GetConditions(
|
|
verificationCycleEvents,
|
|
verificationPoiEvents,
|
|
verificationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState triggerState = triggerConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState verificationState = verificationConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Trigger Conditions ...
|
|
|
|
//
|
|
double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1];
|
|
double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1];
|
|
double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1];
|
|
|
|
//
|
|
double vwaps[3] = {
|
|
vwapFast,
|
|
vwapMid,
|
|
vwapSlow,
|
|
};
|
|
double vwapMax = GetMax(vwaps);
|
|
double vwapMin = GetMin(vwaps);
|
|
|
|
//
|
|
bool isNewPeak = triggerConditions.x121Conditions.isNewPeak;
|
|
bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast;
|
|
bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast;
|
|
|
|
//
|
|
bool isNewVale = triggerConditions.x121Conditions.isNewVale;
|
|
bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast;
|
|
bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast;
|
|
|
|
//
|
|
double triggerPeak = triggerConditions.x121Conditions.peaksBuffer[1];
|
|
double decisionPeak = decisionConditions.x121Conditions.peaksBuffer[1];
|
|
double analysePeak = analyseConditions.x121Conditions.peaksBuffer[1];
|
|
double verificationPeak = verificationConditions.x121Conditions.peaksBuffer[1];
|
|
double consolidationPeak = consolidationConditions.x121Conditions.peaksBuffer[1];
|
|
|
|
//
|
|
double triggerVale = triggerConditions.x121Conditions.valesBuffer[1];
|
|
double decisionVale = decisionConditions.x121Conditions.valesBuffer[1];
|
|
double analyseVale = analyseConditions.x121Conditions.valesBuffer[1];
|
|
double verificationVale = verificationConditions.x121Conditions.valesBuffer[1];
|
|
double consolidationVale = consolidationConditions.x121Conditions.valesBuffer[1];
|
|
|
|
//
|
|
bool isPeaksSameFormed =
|
|
//
|
|
(
|
|
//
|
|
triggerPeak == decisionPeak
|
|
//
|
|
)
|
|
//
|
|
||
|
|
//
|
|
(
|
|
//
|
|
triggerPeak == decisionPeak &&
|
|
triggerPeak == analysePeak
|
|
//
|
|
)
|
|
//
|
|
||
|
|
//
|
|
(
|
|
//
|
|
triggerPeak == decisionPeak &&
|
|
triggerPeak == analysePeak &&
|
|
triggerPeak == verificationPeak
|
|
//
|
|
)
|
|
//
|
|
||
|
|
//
|
|
(
|
|
//
|
|
triggerPeak == decisionPeak &&
|
|
triggerPeak == analysePeak &&
|
|
triggerPeak == verificationPeak &&
|
|
triggerPeak == consolidationPeak
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isValesSameFormed =
|
|
//
|
|
(
|
|
//
|
|
triggerVale == decisionVale
|
|
//
|
|
)
|
|
//
|
|
||
|
|
//
|
|
(
|
|
//
|
|
triggerVale == decisionVale &&
|
|
triggerVale == analyseVale
|
|
//
|
|
)
|
|
//
|
|
||
|
|
//
|
|
(
|
|
//
|
|
triggerVale == decisionVale &&
|
|
triggerVale == analyseVale &&
|
|
triggerVale == verificationVale
|
|
//
|
|
)
|
|
//
|
|
||
|
|
//
|
|
(
|
|
//
|
|
triggerVale == decisionVale &&
|
|
triggerVale == analyseVale &&
|
|
triggerVale == verificationVale &&
|
|
triggerVale == consolidationVale
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
isBullish =
|
|
// isValesSameFormed &&
|
|
IsBullish(setupDir);
|
|
|
|
//
|
|
isBearish =
|
|
// isPeaksSameFormed &&
|
|
IsBearish(setupDir);
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Last VWap State Change ...
|
|
XValueChange vwapStateChnges[];
|
|
int vwapStateChngesCount = triggerCycleHelper
|
|
.FillVWapStateChanges(vwapStateChnges);
|
|
XValueChange lastVWapStateChnged;
|
|
bool hasLastVWapStateChanged = false;
|
|
if (IsValidSize(vwapStateChngesCount) &&
|
|
vwapStateChngesCount >= 2)
|
|
{
|
|
//
|
|
lastVWapStateChnged = vwapStateChnges[vwapStateChngesCount - 2];
|
|
hasLastVWapStateChanged = lastVWapStateChnged.IsValid();
|
|
}
|
|
|
|
//
|
|
double donOpenUpper = triggerConditions.x121Conditions.donOpenUpperBuffer[1];
|
|
double donOpenLower = triggerConditions.x121Conditions.donOpenLowerBuffer[1];
|
|
|
|
//
|
|
double donCloseUpper = triggerConditions.x121Conditions.donCloseUpperBuffer[1];
|
|
double donCloseLower = triggerConditions.x121Conditions.donCloseLowerBuffer[1];
|
|
|
|
//
|
|
bool isDonUpperBullish = donCloseUpper > donOpenUpper;
|
|
bool isDonUpperBearish = donCloseUpper < donOpenUpper;
|
|
|
|
//
|
|
bool isDonLowerBullish = donCloseLower > donOpenLower;
|
|
bool isDonLowerBearish = donCloseLower < donOpenLower;
|
|
|
|
//
|
|
bool isDonBullishFormed =
|
|
//
|
|
(isDonUpperBullish ||
|
|
isDonLowerBullish)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isDonBearishFormed =
|
|
//
|
|
(isDonUpperBearish ||
|
|
isDonLowerBearish)
|
|
//
|
|
;
|
|
|
|
//
|
|
isBullish =
|
|
(isNewValeOverLast ||
|
|
isNewPeakOverLast) &&
|
|
isDonBullishFormed &&
|
|
hasLastVWapStateChanged &&
|
|
(isBullish &&
|
|
IsBullish(lastVWapStateChnged.dir));
|
|
|
|
//
|
|
isBearish =
|
|
(isNewPeakUnderLast ||
|
|
isNewValeUnderLast) &&
|
|
isDonBearishFormed &&
|
|
hasLastVWapStateChanged &&
|
|
(isBearish &&
|
|
IsBearish(lastVWapStateChnged.dir));
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Cleanup Setup Conditions ...
|
|
int setupAge = conditions.GetSetupAge();
|
|
if (IsValidSize(setupAge) &&
|
|
IsValidSize(maxAllowedSetupAge) &&
|
|
setupAge >= maxAllowedSetupAge)
|
|
{
|
|
conditions.Clean();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Selecting SL ...
|
|
|
|
//
|
|
double longSL = 0;
|
|
double shortSL = 0;
|
|
double entry = GetEntry(
|
|
conditions.symbol,
|
|
setupDir //
|
|
);
|
|
|
|
//
|
|
double longDistance = MathAbs(vwapMax - MathMax(triggerVale, donCloseLower)) / 2;
|
|
double shortDistance = MathAbs(vwapMin - MathMin(triggerPeak, donCloseUpper)) / 2;
|
|
|
|
//
|
|
longSL = entry - longDistance;
|
|
shortSL = entry + shortDistance;
|
|
|
|
//
|
|
conditions.triggerTime = cTime;
|
|
conditions.sl = isBullish
|
|
? vwapMin
|
|
: vwapMax;
|
|
conditions.type = isBullish
|
|
? X_POSITION_TYPE_LONG
|
|
: X_POSITION_TYPE_SHORT;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 X121 SMC Signal Class
|
|
// -------------------------------------------------
|
|
// Name:
|
|
// 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 "../Classes/x-121.smc.market.cycle.helper.class.mq5"
|
|
#include "../Libraries/x-121.smc.lib.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
struct X121SMCStrategyXTWPVSignalConditions
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
|
|
//
|
|
double sl;
|
|
double target;
|
|
ENUM_X_DIRECTION dir;
|
|
ENUM_X_POSITION_TYPES type;
|
|
|
|
//
|
|
// Setup Props ...
|
|
|
|
//
|
|
datetime setupTime;
|
|
datetime triggerTime;
|
|
|
|
//
|
|
|
|
//
|
|
// Constructor ...
|
|
X121SMCStrategyXTWPVSignalConditions()
|
|
{
|
|
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();
|
|
}
|
|
|
|
/**
|
|
* 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()
|
|
{
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Extension Functions ...
|
|
|
|
//
|
|
// Detect Setup Conditions ...
|
|
bool DetectX121SMCXTWPVSiganlSetup(
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
X121SMCStrategyXTWPVSignalConditions &conditions,
|
|
//
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
string symbol = _symbol;
|
|
ENUM_TIMEFRAMES period = _period;
|
|
|
|
//
|
|
conditions.symbol = symbol;
|
|
conditions.period = period;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
double ll = cBar.FindLowest(9, MODE_LOW);
|
|
double hh = cBar.FindHighest(9, MODE_HIGH);
|
|
|
|
//
|
|
int zoneValidationDivider = 10;
|
|
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
|
.GetDonChainLength();
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
|
X121SMCCycleConditions triggerConditions;
|
|
result = triggerCycleHelper.GetConditions(
|
|
triggerCycleEvents,
|
|
triggerPoiEvents,
|
|
triggerConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
|
X121SMCCycleConditions verificationConditions;
|
|
result = verificationCycleHelper.GetConditions(
|
|
verificationCycleEvents,
|
|
verificationPoiEvents,
|
|
verificationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState triggerState = triggerConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState verificationState = verificationConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Setup Conditions ...
|
|
|
|
//
|
|
// Detect Market Trend ...
|
|
// ENUM_X_DIRECTION trend;
|
|
// bool hasTrend = verificationCycleHelper
|
|
// .DetectTrend(trend);
|
|
// bool hasBullishTrend = hasTrend &&
|
|
// IsBullish(trend);
|
|
// bool hasBearishTrend = hasTrend &&
|
|
// IsBearish(trend);
|
|
// result = hasBullishTrend ||
|
|
// hasBearishTrend;
|
|
// if (!result)
|
|
// {
|
|
// return result;
|
|
// }
|
|
|
|
//
|
|
// Check Exists Valid Peaks or Vales ...
|
|
|
|
//
|
|
// Peaks ...
|
|
XPVPivotPoint validPeaks[];
|
|
XPVPivotPoint lastValidPeak;
|
|
int validPeaksCount = triggerCycleHelper
|
|
.FillPeakPivotPoints(validPeaks);
|
|
bool hasValidPeaks = IsValidSize(validPeaksCount);
|
|
if (hasValidPeaks)
|
|
{
|
|
lastValidPeak = validPeaks[validPeaksCount - 1];
|
|
}
|
|
|
|
//
|
|
// Vales ...
|
|
XPVPivotPoint validVales[];
|
|
XPVPivotPoint lastValidVale;
|
|
int validValesCount = triggerCycleHelper
|
|
.FillValePivotPoints(validVales);
|
|
bool hasValidVales = IsValidSize(validValesCount);
|
|
if (hasValidVales)
|
|
{
|
|
lastValidVale = validVales[validValesCount - 1];
|
|
}
|
|
|
|
//
|
|
// Looking For New Peak or Vale ...
|
|
|
|
//
|
|
double peak = triggerConditions.x121Conditions.peaksBuffer[1];
|
|
double cale = triggerConditions.x121Conditions.valesBuffer[1];
|
|
|
|
//
|
|
bool isNewPeak = triggerConditions.x121Conditions.isNewPeak;
|
|
bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast;
|
|
bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast;
|
|
|
|
//
|
|
bool isNewVale = triggerConditions.x121Conditions.isNewVale;
|
|
bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast;
|
|
bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast;
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
isNewPeak &&
|
|
hasValidPeaks &&
|
|
isNewPeakUnderLast &&
|
|
lastValidPeak.IsValid()
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
isNewVale &&
|
|
hasValidVales &&
|
|
isNewValeOverLast &&
|
|
lastValidVale.IsValid()
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Sar Change ...
|
|
|
|
//
|
|
double sar = triggerConditions.x121Conditions.sarBuffer[1];
|
|
bool isSarBullish = triggerConditions.x121Conditions.isSarBullish;
|
|
bool isSarBearish = triggerConditions.x121Conditions.isSarBearish;
|
|
|
|
//
|
|
XValueChange lastSarChange;
|
|
bool hasLastSarChange = triggerCycleHelper
|
|
.GetLastSarChange(lastSarChange);
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
isBullish &&
|
|
isSarBullish &&
|
|
hasLastSarChange &&
|
|
sar > lastSarChange.before &&
|
|
ask > lastSarChange.before &&
|
|
bid > lastSarChange.before
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
isBearish &&
|
|
isSarBearish &&
|
|
hasLastSarChange &&
|
|
sar < lastSarChange.before &&
|
|
ask < lastSarChange.before &&
|
|
bid < lastSarChange.before
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.setupTime = cTime;
|
|
conditions.dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Trigger Conditions ...
|
|
bool DetectX121SMCXTWPVSiganlTrigger(
|
|
//
|
|
X121SMCStrategyXTWPVSignalConditions &conditions,
|
|
//
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper,
|
|
//
|
|
int maxAllowedSetupAge = 60 //
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = conditions.IsSetuped();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
datetime setupTime = conditions.setupTime;
|
|
ENUM_X_DIRECTION setupDir = conditions.dir;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
string symbol = _symbol;
|
|
ENUM_TIMEFRAMES period = _period;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
double ll = cBar.FindLowest(9, MODE_LOW);
|
|
double hh = cBar.FindHighest(9, MODE_HIGH);
|
|
|
|
//
|
|
int zoneValidationDivider = 10;
|
|
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
|
.GetDonChainLength();
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
|
X121SMCCycleConditions triggerConditions;
|
|
result = triggerCycleHelper.GetConditions(
|
|
triggerCycleEvents,
|
|
triggerPoiEvents,
|
|
triggerConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
|
X121SMCCycleConditions verificationConditions;
|
|
result = verificationCycleHelper.GetConditions(
|
|
verificationCycleEvents,
|
|
verificationPoiEvents,
|
|
verificationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState triggerState = triggerConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState verificationState = verificationConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Trigger Conditions ...
|
|
|
|
//
|
|
// Check VWap State ...
|
|
|
|
//
|
|
bool isVWapBullishState = triggerConditions.x121Conditions.isVWapBullishState;
|
|
bool isVWapBearishState = triggerConditions.x121Conditions.isVWapBearishState;
|
|
|
|
//
|
|
isBullish =
|
|
IsBullish(setupDir) &&
|
|
isVWapBullishState;
|
|
|
|
//
|
|
isBearish =
|
|
IsBearish(setupDir) &&
|
|
isVWapBearishState;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Waitings For Sar Switched to Direction ...
|
|
|
|
//
|
|
double sar = triggerConditions.x121Conditions.sarBuffer[1];
|
|
|
|
//
|
|
bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish;
|
|
bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish;
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
isBullish &&
|
|
isSarSwitchedToBullish
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
isBearish &&
|
|
isSarSwitchedToBearish
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Cleanup Setup Conditions ...
|
|
int setupAge = conditions.GetSetupAge();
|
|
if (IsValidSize(setupAge) &&
|
|
IsValidSize(maxAllowedSetupAge) &&
|
|
setupAge >= maxAllowedSetupAge)
|
|
{
|
|
conditions.Clean();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Nearest FVG or Supply Zone For Traget ...
|
|
|
|
//
|
|
// Select Source State ...
|
|
XPOIState state = triggerState;
|
|
|
|
//
|
|
double target = CalculateTarget(
|
|
cBar,
|
|
state,
|
|
setupDir //
|
|
);
|
|
|
|
//
|
|
result = target > 0;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.target = target;
|
|
conditions.triggerTime = cTime;
|
|
conditions.sl = isBullish
|
|
? sar
|
|
: sar;
|
|
conditions.type = isBullish
|
|
? X_POSITION_TYPE_LONG
|
|
: X_POSITION_TYPE_SHORT;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 X121 SMC Signal Lib
|
|
// -------------------------------------------------
|
|
// Name:
|
|
// 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 "../Classes/x-121.smc.market.cycle.helper.class.mq5"
|
|
#include "../Libraries/x-121.smc.lib.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
struct X121SMCStrategyXPVSUPDEMSignalConditions
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
|
|
//
|
|
double sl;
|
|
double target;
|
|
ENUM_X_DIRECTION dir;
|
|
ENUM_X_POSITION_TYPES type;
|
|
|
|
//
|
|
// Setup Props ...
|
|
|
|
//
|
|
datetime setupTime;
|
|
datetime triggerTime;
|
|
|
|
//
|
|
XCTicksZone *ticksZone;
|
|
XCSupplyZone *supplyZones[];
|
|
XCDemandZone *demandZones[];
|
|
datetime activeZoneFoundedAt;
|
|
XCSupplyZone *activeSupplyZone;
|
|
XCDemandZone *activeDemandZone;
|
|
|
|
//
|
|
// Constructor ...
|
|
X121SMCStrategyXPVSUPDEMSignalConditions()
|
|
{
|
|
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();
|
|
}
|
|
|
|
/**
|
|
* 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()
|
|
{
|
|
//
|
|
ticksZone = NULL;
|
|
activeSupplyZone = NULL;
|
|
activeDemandZone = NULL;
|
|
activeZoneFoundedAt = NULL;
|
|
|
|
//
|
|
Clean(supplyZones);
|
|
Clean(demandZones);
|
|
}
|
|
|
|
/**
|
|
* Count Supply Zones ...
|
|
*
|
|
* @return ( int )
|
|
*/
|
|
int CountSupplyZones()
|
|
{
|
|
return ArraySize(supplyZones);
|
|
}
|
|
|
|
/**
|
|
* Count Demand Zones ...
|
|
*
|
|
* @return ( int )
|
|
*/
|
|
int CountDemandZones()
|
|
{
|
|
return ArraySize(demandZones);
|
|
}
|
|
|
|
/**
|
|
* Check Has Supply Zones ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool HasSupplyZones()
|
|
{
|
|
return IsValidSize(CountSupplyZones());
|
|
}
|
|
|
|
/**
|
|
* Check Has Demand Zones ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool HasDemandZones()
|
|
{
|
|
return IsValidSize(CountDemandZones());
|
|
}
|
|
|
|
/**
|
|
* Check Has Active Supply or Demand Zone ...
|
|
*
|
|
* @param _dir: ENUM_X_DIRECTION member Reference for Specify Active Zone ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool HasActiveZone(ENUM_X_DIRECTION &_dir)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
_dir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
// Check Supplies ...
|
|
bool hasActiveSupplyZone = activeSupplyZone != NULL &&
|
|
activeSupplyZone.IsValid();
|
|
|
|
//
|
|
// Check Demnds ...
|
|
bool hasActiveDemandZone = activeDemandZone != NULL &&
|
|
activeDemandZone.IsValid();
|
|
|
|
//
|
|
result = hasActiveSupplyZone ||
|
|
hasActiveDemandZone;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
_dir = hasActiveDemandZone
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Retrieve Active Zone Reference if Exists ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool GetActiveZone(XCBarZone *&activeZone)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
activeZone = NULL;
|
|
|
|
//
|
|
ENUM_X_DIRECTION activeZoneDir;
|
|
result = HasActiveZone(activeZoneDir);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
if (IsBullish(activeZoneDir))
|
|
{
|
|
//
|
|
activeDemandZone.To(TimeCurrent());
|
|
activeZone = activeDemandZone;
|
|
}
|
|
else
|
|
{
|
|
//
|
|
activeSupplyZone.To(TimeCurrent());
|
|
activeZone = activeSupplyZone;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Clean Active Zone ...
|
|
*/
|
|
void CleanActiveZone()
|
|
{
|
|
//
|
|
activeSupplyZone = NULL;
|
|
activeDemandZone = NULL;
|
|
activeZoneFoundedAt = NULL;
|
|
}
|
|
|
|
/**
|
|
* Check Ticks Zone is Initialized or not ...
|
|
* @return ( bool )
|
|
*/
|
|
bool HasTicksZone()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
ticksZone != NULL &&
|
|
ticksZone.IsValid() &&
|
|
IsValidSize(ticksZone.Count())
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Extension Functions ...
|
|
|
|
//
|
|
// Detect Setup Conditions ...
|
|
bool DetectX121SMCXPVSUPDEMSiganlSetup(
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
X121SMCStrategyXPVSUPDEMSignalConditions &conditions,
|
|
//
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
string symbol = _symbol;
|
|
ENUM_TIMEFRAMES period = _period;
|
|
|
|
//
|
|
conditions.symbol = symbol;
|
|
conditions.period = period;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
double ll = cBar.FindLowest(9, MODE_LOW);
|
|
double hh = cBar.FindHighest(9, MODE_HIGH);
|
|
|
|
//
|
|
int zoneValidationDivider = 10;
|
|
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
|
.GetDonChainLength();
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
|
X121SMCCycleConditions triggerConditions;
|
|
result = triggerCycleHelper.GetConditions(
|
|
triggerCycleEvents,
|
|
triggerPoiEvents,
|
|
triggerConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
|
X121SMCCycleConditions verificationConditions;
|
|
result = verificationCycleHelper.GetConditions(
|
|
verificationCycleEvents,
|
|
verificationPoiEvents,
|
|
verificationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState triggerState = triggerConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState verificationState = verificationConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Setup Conditions ...
|
|
|
|
//
|
|
// Detect Market Trend ...
|
|
ENUM_X_DIRECTION trend;
|
|
bool hasTrend = consolidationCycleHelper
|
|
.DetectTrend(trend);
|
|
bool hasBullishTrend = hasTrend &&
|
|
IsBullish(trend);
|
|
bool hasBearishTrend = hasTrend &&
|
|
IsBearish(trend);
|
|
result = hasBullishTrend ||
|
|
hasBearishTrend;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Select Source State ...
|
|
XPOIState state = consolidationState;
|
|
|
|
//
|
|
// Detect Supply and Demand Zones ...
|
|
|
|
//
|
|
// Supply ...
|
|
bool hasSupplyZones = conditions.HasSupplyZones();
|
|
if (!hasSupplyZones)
|
|
{
|
|
//
|
|
int count = state.CountSupplyZones();
|
|
for (int i = count - 1; i >= 0; i--)
|
|
{
|
|
//
|
|
XCSupplyZone *iZone = state.supplyZones[i];
|
|
|
|
//
|
|
bool isValid =
|
|
//
|
|
ask < iZone.Lower() &&
|
|
bid < iZone.Lower() &&
|
|
cBar.high < iZone.Lower()
|
|
//
|
|
;
|
|
if (isValid)
|
|
{
|
|
//
|
|
Add(
|
|
iZone,
|
|
conditions.supplyZones //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
hasSupplyZones = conditions.HasSupplyZones();
|
|
result = hasSupplyZones;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Demand ...
|
|
bool hasDemandZones = conditions.HasDemandZones();
|
|
if (!hasDemandZones)
|
|
{
|
|
//
|
|
int count = state.CountDemandZones();
|
|
for (int i = count - 1; i >= 0; i--)
|
|
{
|
|
//
|
|
XCDemandZone *iZone = state.demandZones[i];
|
|
|
|
//
|
|
bool isValid =
|
|
//
|
|
ask > iZone.Upper() &&
|
|
bid > iZone.Upper() &&
|
|
cBar.low > iZone.Upper()
|
|
//
|
|
;
|
|
if (isValid)
|
|
{
|
|
//
|
|
Add(
|
|
iZone,
|
|
conditions.demandZones //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
hasDemandZones = conditions.HasDemandZones();
|
|
result = hasDemandZones;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Waits For Price to Go Inside a Zone ...
|
|
ENUM_X_DIRECTION activeZoneDir = X_DIRECTION_NONE;
|
|
bool hasActiveZone = conditions.HasActiveZone(activeZoneDir);
|
|
if (!hasActiveZone)
|
|
{
|
|
//
|
|
// Looking Up For Active Zone ...
|
|
|
|
//
|
|
// Supply ...
|
|
if (hasSupplyZones)
|
|
{
|
|
//
|
|
int count = conditions.CountSupplyZones();
|
|
for (int i = count - 1; i >= 0; i--)
|
|
{
|
|
//
|
|
XCSupplyZone *iZone = conditions.supplyZones[i];
|
|
|
|
//
|
|
bool isValid =
|
|
//
|
|
ask <= iZone.Upper() &&
|
|
bid <= iZone.Upper() &&
|
|
ask >= iZone.Lower() &&
|
|
bid >= iZone.Lower() &&
|
|
cBar.high <= iZone.Upper() &&
|
|
cBar.low >= iZone.Lower()
|
|
//
|
|
;
|
|
if (isValid)
|
|
{
|
|
//
|
|
conditions.activeSupplyZone = iZone;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
hasActiveZone = conditions.HasActiveZone(activeZoneDir);
|
|
if (!hasActiveZone)
|
|
{
|
|
//
|
|
// Demand ...
|
|
if (hasDemandZones)
|
|
{
|
|
//
|
|
int count = conditions.CountDemandZones();
|
|
for (int i = count - 1; i >= 0; i--)
|
|
{
|
|
//
|
|
XCDemandZone *iZone = conditions.demandZones[i];
|
|
|
|
//
|
|
bool isValid =
|
|
//
|
|
ask <= iZone.Upper() &&
|
|
bid <= iZone.Upper() &&
|
|
ask >= iZone.Lower() &&
|
|
bid >= iZone.Lower() &&
|
|
cBar.high <= iZone.Upper() &&
|
|
cBar.low >= iZone.Lower()
|
|
//
|
|
;
|
|
if (isValid)
|
|
{
|
|
//
|
|
conditions.activeDemandZone = iZone;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
hasActiveZone = conditions.HasActiveZone(activeZoneDir);
|
|
result = hasActiveZone;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.activeZoneFoundedAt = cTime;
|
|
}
|
|
|
|
//
|
|
// Now we Have to Calculate Active Zones Ticks ...
|
|
|
|
//
|
|
bool isValidDemandZone =
|
|
hasActiveZone &&
|
|
hasBullishTrend &&
|
|
IsBullish(activeZoneDir);
|
|
|
|
//
|
|
bool isValidSupplyZone =
|
|
hasActiveZone &&
|
|
hasBearishTrend &&
|
|
IsBearish(activeZoneDir);
|
|
|
|
//
|
|
result = isValidDemandZone ||
|
|
isValidSupplyZone;
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.CleanActiveZone();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Select Active Zone ...
|
|
XCBarZone *activeZone = NULL;
|
|
result = conditions.GetActiveZone(activeZone);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Extract Active Zone Start Bar ...
|
|
XOHCL fromBar;
|
|
datetime fromTime = activeZone.BarTime();
|
|
result = triggerCycleHelper.GetBar(
|
|
fromBar,
|
|
fromTime //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool hasTicksZone = conditions.HasTicksZone();
|
|
if (!hasTicksZone)
|
|
{
|
|
//
|
|
// Istantiate Ticks Zone ...
|
|
conditions.ticksZone = new XCTicksZone();
|
|
conditions.ticksZone.Levels(40);
|
|
}
|
|
|
|
//
|
|
// Update Ticks Zone ...
|
|
result = conditions.ticksZone.Init(
|
|
fromBar,
|
|
cBar //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Regenrate Conditions ...
|
|
hasTicksZone = conditions.HasTicksZone();
|
|
result = hasTicksZone;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Make Sure we Have a Direction for Setup ...
|
|
isBullish = IsBullish(activeZoneDir);
|
|
isBearish = IsBearish(activeZoneDir);
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check New Peaks or Vales Happens inside Zero Tick or Volume Percent Zone and
|
|
// also Active Zone ...
|
|
double peak = triggerConditions.x121Conditions.peaksBuffer[1];
|
|
double vale = triggerConditions.x121Conditions.valesBuffer[1];
|
|
bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast;
|
|
bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast;
|
|
|
|
//
|
|
bool isPeakInsideActiveZone =
|
|
//
|
|
peak <= activeZone.Upper() &&
|
|
peak >= activeZone.Lower()
|
|
//
|
|
;
|
|
bool isValeInsideActiveZone =
|
|
//
|
|
vale <= activeZone.Upper() &&
|
|
vale >= activeZone.Lower()
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isPeakInsideZeroZone = false;
|
|
bool isValeInsideZeroZone = false;
|
|
int tzCount = conditions.ticksZone.Count();
|
|
if (IsValidSize(tzCount))
|
|
{
|
|
//
|
|
for (int i = 0; i < tzCount; i++)
|
|
{
|
|
//
|
|
XCTickZone *iTZ = conditions.ticksZone.GetZone(i);
|
|
|
|
//
|
|
if (isBearish &&
|
|
!isPeakInsideZeroZone)
|
|
{
|
|
//
|
|
isPeakInsideZeroZone =
|
|
//
|
|
peak <= iTZ.high &&
|
|
peak >= iTZ.low &&
|
|
(iTZ.percent == 0 ||
|
|
iTZ.volumePercent == 0)
|
|
//
|
|
;
|
|
}
|
|
|
|
//
|
|
if (isBullish &&
|
|
!isValeInsideZeroZone)
|
|
{
|
|
//
|
|
isValeInsideZeroZone =
|
|
//
|
|
vale <= iTZ.high &&
|
|
vale >= iTZ.low &&
|
|
(iTZ.percent == 0 ||
|
|
iTZ.volumePercent == 0)
|
|
//
|
|
;
|
|
}
|
|
|
|
//
|
|
if (isPeakInsideZeroZone ||
|
|
isValeInsideZeroZone)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
isBullish &&
|
|
isNewValeUnderLast &&
|
|
isValeInsideZeroZone &&
|
|
isValeInsideActiveZone
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
isBearish &&
|
|
isNewPeakOverLast &&
|
|
isPeakInsideZeroZone &&
|
|
isPeakInsideActiveZone
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Clean Conditions for Regenerate ...
|
|
int activeZoneAge = (int)(cTime - conditions.activeZoneFoundedAt) / PeriodSeconds(conditions.period);
|
|
if (activeZoneAge >= 200)
|
|
{
|
|
conditions.Clean();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.setupTime = cTime;
|
|
conditions.dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Trigger Conditions ...
|
|
bool DetectX121SMCXPVSUPDEMSiganlTrigger(
|
|
//
|
|
X121SMCStrategyXPVSUPDEMSignalConditions &conditions,
|
|
//
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper,
|
|
//
|
|
int maxAllowedSetupAge = 60 //
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = conditions.IsSetuped();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
datetime setupTime = conditions.setupTime;
|
|
ENUM_X_DIRECTION setupDir = conditions.dir;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
string symbol = _symbol;
|
|
ENUM_TIMEFRAMES period = _period;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
double ll = cBar.FindLowest(9, MODE_LOW);
|
|
double hh = cBar.FindHighest(9, MODE_HIGH);
|
|
|
|
//
|
|
int zoneValidationDivider = 10;
|
|
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
|
.GetDonChainLength();
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
|
X121SMCCycleConditions triggerConditions;
|
|
result = triggerCycleHelper.GetConditions(
|
|
triggerCycleEvents,
|
|
triggerPoiEvents,
|
|
triggerConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
|
X121SMCCycleConditions verificationConditions;
|
|
result = verificationCycleHelper.GetConditions(
|
|
verificationCycleEvents,
|
|
verificationPoiEvents,
|
|
verificationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState triggerState = triggerConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState verificationState = verificationConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Trigger Conditions ...
|
|
|
|
//
|
|
// Select Active Zone Class ...
|
|
XCBarZone *activeZone = NULL;
|
|
result = conditions.GetActiveZone(activeZone);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Last Valid Peak or Last Valid Vales Breaks ...
|
|
// Beak Of Structure ...
|
|
|
|
//
|
|
// Peak ...
|
|
double peak = triggerConditions.x121Conditions.peaksBuffer[1];
|
|
XPVPivotPoint lastPeakPivot;
|
|
bool hasLastPeakPivot = triggerCycleHelper
|
|
.GetLastPeakPivotPoint(lastPeakPivot);
|
|
bool isLastPeakPivotBreaked =
|
|
//
|
|
lastPeakPivot.IsPeak() &&
|
|
lastPeakPivot.IsValid() &&
|
|
peak > lastPeakPivot.value
|
|
//
|
|
;
|
|
|
|
//
|
|
// Vale ...
|
|
double vale = triggerConditions.x121Conditions.valesBuffer[1];
|
|
XPVPivotPoint lastValePivot;
|
|
bool hasLastValePivot = triggerCycleHelper
|
|
.GetLastValePivotPoint(lastValePivot);
|
|
bool isLastValePivotBreaked =
|
|
//
|
|
lastValePivot.IsVale() &&
|
|
lastValePivot.IsValid() &&
|
|
vale < lastValePivot.value
|
|
//
|
|
;
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
IsBullish(setupDir) &&
|
|
isLastValePivotBreaked
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
IsBearish(setupDir) &&
|
|
isLastPeakPivotBreaked
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Cleanup Setup Conditions ...
|
|
int setupAge = conditions.GetSetupAge();
|
|
if (IsValidSize(setupAge) &&
|
|
IsValidSize(maxAllowedSetupAge) &&
|
|
setupAge >= maxAllowedSetupAge)
|
|
{
|
|
conditions.Clean();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.triggerTime = cTime;
|
|
conditions.sl = isBullish
|
|
? activeZone.Lower()
|
|
: activeZone.Upper();
|
|
conditions.type = isBullish
|
|
? X_POSITION_TYPE_LONG
|
|
: X_POSITION_TYPE_SHORT;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 X121 SMC Signal Lib
|
|
// -------------------------------------------------
|
|
// Name:
|
|
// 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 "../Classes/x-121.smc.market.cycle.helper.class.mq5"
|
|
#include "../Libraries/x-121.smc.lib.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
struct X121SMCStrategyXPVOBSignalConditions
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
|
|
//
|
|
double sl;
|
|
double target;
|
|
ENUM_X_DIRECTION dir;
|
|
ENUM_X_POSITION_TYPES type;
|
|
|
|
//
|
|
// Setup Props ...
|
|
|
|
//
|
|
datetime setupTime;
|
|
datetime triggerTime;
|
|
|
|
//
|
|
XCOrderBlock *bullishOBs[];
|
|
XCOrderBlock *bearishOBs[];
|
|
|
|
//
|
|
XCFVG *activeFVG;
|
|
XCFVG *bullishFVGs[];
|
|
XCFVG *bearishFVGs[];
|
|
|
|
//
|
|
// Constructor ...
|
|
X121SMCStrategyXPVOBSignalConditions()
|
|
{
|
|
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;
|
|
|
|
//
|
|
activeFVG = NULL;
|
|
Clean(bullishOBs);
|
|
Clean(bearishOBs);
|
|
}
|
|
|
|
/**
|
|
* 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 ...
|
|
|
|
//
|
|
int CountBullishOBs()
|
|
{
|
|
return ArraySize(bullishOBs);
|
|
}
|
|
|
|
//
|
|
int CountBearishOBs()
|
|
{
|
|
return ArraySize(bearishOBs);
|
|
}
|
|
|
|
//
|
|
bool HasBullishOB()
|
|
{
|
|
return IsValidSize(CountBullishOBs());
|
|
}
|
|
|
|
//
|
|
bool HasBearishOB()
|
|
{
|
|
return IsValidSize(CountBearishOBs());
|
|
}
|
|
|
|
//
|
|
int CountBullishFVGs()
|
|
{
|
|
return ArraySize(bullishFVGs);
|
|
}
|
|
|
|
//
|
|
int CountBearishFVGs()
|
|
{
|
|
return ArraySize(bearishFVGs);
|
|
}
|
|
|
|
//
|
|
bool HasBullishFVG()
|
|
{
|
|
return IsValidSize(CountBullishFVGs());
|
|
}
|
|
|
|
//
|
|
bool HasBearishFVG()
|
|
{
|
|
return IsValidSize(CountBearishFVGs());
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Extension Functions ...
|
|
|
|
//
|
|
// Detect Setup Conditions ...
|
|
bool DetectX121SMCXPVOBSiganlSetup(
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
X121SMCStrategyXPVOBSignalConditions &conditions,
|
|
//
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
string symbol = _symbol;
|
|
ENUM_TIMEFRAMES period = _period;
|
|
|
|
//
|
|
conditions.symbol = symbol;
|
|
conditions.period = period;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
double ll = cBar.FindLowest(9, MODE_LOW);
|
|
double hh = cBar.FindHighest(9, MODE_HIGH);
|
|
|
|
//
|
|
int zoneValidationDivider = 10;
|
|
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
|
.GetDonChainLength();
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
|
X121SMCCycleConditions triggerConditions;
|
|
result = triggerCycleHelper.GetConditions(
|
|
triggerCycleEvents,
|
|
triggerPoiEvents,
|
|
triggerConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
|
X121SMCCycleConditions verificationConditions;
|
|
result = verificationCycleHelper.GetConditions(
|
|
verificationCycleEvents,
|
|
verificationPoiEvents,
|
|
verificationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState triggerState = triggerConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState verificationState = verificationConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Setup Conditions ...
|
|
|
|
//
|
|
// Detect Market Trend ...
|
|
ENUM_X_DIRECTION trend;
|
|
bool hasTrend = consolidationCycleHelper
|
|
.DetectTrend(trend);
|
|
bool hasBullishTrend = hasTrend &&
|
|
IsBullish(trend);
|
|
bool hasBearishTrend = hasTrend &&
|
|
IsBearish(trend);
|
|
result = hasBullishTrend ||
|
|
hasBearishTrend;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Select Source State ...
|
|
XPOIState state = decisionState;
|
|
|
|
//
|
|
// Detect Imbalance ...
|
|
|
|
//
|
|
bool hasBullishOB = conditions.HasBullishOB();
|
|
if (!hasBullishOB)
|
|
{
|
|
//
|
|
int count = state.CountBullishOrderBlocks();
|
|
if (IsValidSize(count))
|
|
{
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCOrderBlock *iOB = state.bullishOrderBlocks[i];
|
|
|
|
//
|
|
// Validate Order Block ...
|
|
bool isValid =
|
|
//
|
|
cBar.low > iOB.Upper()
|
|
//
|
|
;
|
|
if (isValid)
|
|
{
|
|
//
|
|
Add(
|
|
iOB,
|
|
conditions.bullishOBs //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
hasBullishOB = conditions.HasBullishOB();
|
|
}
|
|
|
|
//
|
|
bool hasBearishOB = conditions.HasBearishOB();
|
|
if (!hasBearishOB)
|
|
{
|
|
//
|
|
int count = state.CountBearishOrderBlocks();
|
|
if (IsValidSize(count))
|
|
{
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCOrderBlock *iOB = state.bearishOrderBlocks[i];
|
|
|
|
//
|
|
// Validate Order Block ...
|
|
bool isValid =
|
|
//
|
|
cBar.high < iOB.Lower()
|
|
//
|
|
;
|
|
if (isValid)
|
|
{
|
|
//
|
|
Add(
|
|
iOB,
|
|
conditions.bearishOBs //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
hasBearishOB = conditions.HasBearishOB();
|
|
}
|
|
|
|
//
|
|
result = hasBullishOB ||
|
|
hasBearishOB;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int fvgValidationLength = 5;
|
|
|
|
//
|
|
bool hasBullishFVG = conditions.HasBullishFVG();
|
|
if (!hasBullishFVG)
|
|
{
|
|
//
|
|
if (hasBullishOB)
|
|
{
|
|
//
|
|
int obsCount = conditions.CountBullishOBs();
|
|
int count = state.CountBullishFairValueGaps();
|
|
for (int i = 0; i < obsCount; i++)
|
|
{
|
|
//
|
|
XCOrderBlock *iOB = conditions.bullishOBs[i];
|
|
|
|
//
|
|
for (int j = 0; j < count; j++)
|
|
{
|
|
//
|
|
XCFVG *jFVG = state.bullishFairValueGaps[j];
|
|
|
|
//
|
|
bool isValid =
|
|
//
|
|
cBar.low > iOB.Upper() &&
|
|
cBar.low > jFVG.Upper() &&
|
|
//
|
|
jFVG.From() > iOB.From() &&
|
|
(((int)(jFVG.From() - iOB.From())) / PeriodSeconds(state.period)) <= fvgValidationLength
|
|
//
|
|
;
|
|
if (isValid)
|
|
{
|
|
//
|
|
Add(
|
|
jFVG,
|
|
conditions.bullishFVGs //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
hasBullishFVG = conditions.HasBullishFVG();
|
|
}
|
|
|
|
//
|
|
bool hasBearishFVG = conditions.HasBearishFVG();
|
|
if (!hasBearishFVG)
|
|
{
|
|
//
|
|
if (hasBullishOB)
|
|
{
|
|
//
|
|
int obsCount = conditions.CountBearishOBs();
|
|
int count = state.CountBearishFairValueGaps();
|
|
for (int i = 0; i < obsCount; i++)
|
|
{
|
|
//
|
|
XCOrderBlock *iOB = conditions.bearishOBs[i];
|
|
|
|
//
|
|
for (int j = 0; j < count; j++)
|
|
{
|
|
//
|
|
XCFVG *jFVG = state.bearishFairValueGaps[j];
|
|
|
|
//
|
|
bool isValid =
|
|
//
|
|
cBar.high < iOB.Lower() &&
|
|
cBar.high < jFVG.Lower() &&
|
|
//
|
|
jFVG.From() > iOB.From() &&
|
|
(((int)(jFVG.From() - iOB.From())) / PeriodSeconds(state.period)) <= fvgValidationLength
|
|
//
|
|
;
|
|
if (isValid)
|
|
{
|
|
//
|
|
Add(
|
|
jFVG,
|
|
conditions.bearishFVGs //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
hasBearishFVG = conditions.HasBearishFVG();
|
|
}
|
|
|
|
//
|
|
result = (hasBullishOB &&
|
|
hasBullishFVG) ||
|
|
(hasBearishOB &&
|
|
hasBearishFVG);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect new Peak or new Vale ...
|
|
|
|
//
|
|
bool isNewPeak = triggerConditions.x121Conditions.isNewPeak;
|
|
double peak = triggerConditions.x121Conditions.peaksBuffer[1];
|
|
bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast;
|
|
bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast;
|
|
|
|
//
|
|
bool isNewVale = triggerConditions.x121Conditions.isNewVale;
|
|
double vale = triggerConditions.x121Conditions.valesBuffer[1];
|
|
bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast;
|
|
bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast;
|
|
|
|
//
|
|
result = isNewPeak ||
|
|
isNewVale;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Setup Conditions based on Peaks or Vales Occurance ...
|
|
|
|
//
|
|
bool lookupForLong = isNewVale &&
|
|
hasBullishOB &&
|
|
hasBullishFVG &&
|
|
hasBullishTrend;
|
|
|
|
//
|
|
bool lookupForShort = isNewPeak &&
|
|
hasBearishOB &&
|
|
hasBearishFVG &&
|
|
hasBearishTrend;
|
|
|
|
//
|
|
result = lookupForLong ||
|
|
lookupForShort;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XCFVG *fvg = NULL;
|
|
double fvgZoneValidationRangePercent = 0;
|
|
if (lookupForLong)
|
|
{
|
|
//
|
|
// Long Conditions ...
|
|
// Vales must be Happens Inside Bullish Fair Value Gaps ...
|
|
int count = conditions.CountBullishFVGs();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCFVG *iFVG = conditions.bullishFVGs[i];
|
|
|
|
//
|
|
bool isValid =
|
|
//
|
|
vale <= iFVG.Upper() &&
|
|
vale >= iFVG.Lower() &&
|
|
(fvgZoneValidationRangePercent <= 0
|
|
? true
|
|
: (vale < iFVG.Upper() - (iFVG.RangePercent() * fvgZoneValidationRangePercent)))
|
|
//
|
|
;
|
|
if (isValid)
|
|
{
|
|
//
|
|
fvg = iFVG;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
fvg != NULL &&
|
|
fvg.IsValid()
|
|
//
|
|
;
|
|
if (isBullish)
|
|
{
|
|
conditions.activeFVG = fvg;
|
|
}
|
|
}
|
|
else if (lookupForShort)
|
|
{
|
|
//
|
|
// Short Conditions ...
|
|
// Peaks Must be Happens Inside Bearish Fair Value Gaps ...
|
|
int count = conditions.CountBearishFVGs();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCFVG *iFVG = conditions.bearishFVGs[i];
|
|
|
|
//
|
|
bool isValid =
|
|
//
|
|
peak <= iFVG.Upper() &&
|
|
peak >= iFVG.Lower() &&
|
|
(fvgZoneValidationRangePercent <= 0
|
|
? true
|
|
: (peak > iFVG.Lower() + (iFVG.RangePercent() * fvgZoneValidationRangePercent)))
|
|
//
|
|
;
|
|
if (isValid)
|
|
{
|
|
//
|
|
fvg = iFVG;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
fvg != NULL &&
|
|
fvg.IsValid()
|
|
//
|
|
;
|
|
if (isBearish)
|
|
{
|
|
conditions.activeFVG = fvg;
|
|
}
|
|
}
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
if (lookupForLong)
|
|
{
|
|
//
|
|
conditions.activeFVG = NULL;
|
|
Clean(conditions.bullishOBs);
|
|
Clean(conditions.bullishFVGs);
|
|
}
|
|
else if (lookupForShort)
|
|
{
|
|
//
|
|
conditions.activeFVG = NULL;
|
|
Clean(conditions.bearishOBs);
|
|
Clean(conditions.bearishFVGs);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.setupTime = cTime;
|
|
conditions.dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Trigger Conditions ...
|
|
bool DetectX121SMCXPVOBSiganlTrigger(
|
|
//
|
|
X121SMCStrategyXPVOBSignalConditions &conditions,
|
|
//
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper,
|
|
//
|
|
int maxAllowedSetupAge = 60 //
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = conditions.IsSetuped();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
datetime setupTime = conditions.setupTime;
|
|
ENUM_X_DIRECTION setupDir = conditions.dir;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
string symbol = _symbol;
|
|
ENUM_TIMEFRAMES period = _period;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
double ll = cBar.FindLowest(9, MODE_LOW);
|
|
double hh = cBar.FindHighest(9, MODE_HIGH);
|
|
|
|
//
|
|
int zoneValidationDivider = 10;
|
|
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
|
.GetDonChainLength();
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
|
X121SMCCycleConditions triggerConditions;
|
|
result = triggerCycleHelper.GetConditions(
|
|
triggerCycleEvents,
|
|
triggerPoiEvents,
|
|
triggerConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
|
X121SMCCycleConditions verificationConditions;
|
|
result = verificationCycleHelper.GetConditions(
|
|
verificationCycleEvents,
|
|
verificationPoiEvents,
|
|
verificationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState triggerState = triggerConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState verificationState = verificationConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Trigger Conditions ...
|
|
XCFVG *iFVG = conditions.activeFVG;
|
|
result = iFVG != NULL &&
|
|
iFVG.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool lookupLong = IsBullish(setupDir) &&
|
|
iFVG.IsBullish();
|
|
bool lookupShort = IsBearish(setupDir) &&
|
|
iFVG.IsBearish();
|
|
result = lookupLong ||
|
|
lookupShort;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check PEAKS and Vales ...
|
|
|
|
//
|
|
// Trigger ...
|
|
|
|
//
|
|
// Peaks and Vales ...
|
|
double triggerPeak = triggerConditions.x121Conditions.peaksBuffer[1];
|
|
double triggerVale = triggerConditions.x121Conditions.valesBuffer[1];
|
|
|
|
//
|
|
bool isTriggerPeakInsideFVG =
|
|
//
|
|
triggerPeak <= iFVG.Upper() &&
|
|
triggerPeak >= iFVG.Lower()
|
|
//
|
|
;
|
|
bool isTriggerValeInsideFVG =
|
|
//
|
|
triggerVale <= iFVG.Upper() &&
|
|
triggerVale >= iFVG.Lower()
|
|
//
|
|
;
|
|
|
|
//
|
|
// VWap ...
|
|
|
|
//
|
|
bool isTriggerVWapFastBullish = triggerConditions.x121Conditions.isVWapFastBullish;
|
|
bool isTriggerVWapMidBullish = triggerConditions.x121Conditions.isVWapMidBullish;
|
|
bool isTriggerVWapSlowBullish = triggerConditions.x121Conditions.isVWapSlowBullish;
|
|
|
|
//
|
|
bool isTriggerVWapFastOverMid = triggerConditions.x121Conditions.isVWapFastOverMid;
|
|
bool isTriggerVWapMidOverSlow = triggerConditions.x121Conditions.isVWapMidOverSlow;
|
|
|
|
//
|
|
bool isTriggerVWapFastBearish = triggerConditions.x121Conditions.isVWapFastBearish;
|
|
bool isTriggerVWapMidBearish = triggerConditions.x121Conditions.isVWapMidBearish;
|
|
bool isTriggerVWapSlowBearish = triggerConditions.x121Conditions.isVWapSlowBearish;
|
|
|
|
//
|
|
bool isTriggerVWapFastUnderMid = triggerConditions.x121Conditions.isVWapFastUnderMid;
|
|
bool isTriggerVWapMidUnderSlow = triggerConditions.x121Conditions.isVWapMidUnderSlow;
|
|
|
|
//
|
|
bool isTriggerMarketBullish =
|
|
//
|
|
// State ...
|
|
(
|
|
//
|
|
(isTriggerVWapFastBullish &&
|
|
isTriggerVWapMidBullish &&
|
|
isTriggerVWapSlowBullish)
|
|
//
|
|
||
|
|
//
|
|
(isTriggerVWapMidBullish &&
|
|
isTriggerVWapSlowBullish)
|
|
//
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
// Order ...
|
|
(
|
|
//
|
|
(isTriggerVWapFastOverMid &&
|
|
isTriggerVWapMidOverSlow)
|
|
//
|
|
||
|
|
//
|
|
isTriggerVWapMidOverSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isTriggerMarketBearish =
|
|
//
|
|
// State ...
|
|
(
|
|
//
|
|
(isTriggerVWapFastBearish &&
|
|
isTriggerVWapMidBearish &&
|
|
isTriggerVWapSlowBearish)
|
|
//
|
|
||
|
|
//
|
|
(isTriggerVWapMidBearish &&
|
|
isTriggerVWapSlowBearish)
|
|
//
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
// Order ...
|
|
(
|
|
//
|
|
(isTriggerVWapFastUnderMid &&
|
|
isTriggerVWapMidUnderSlow)
|
|
//
|
|
||
|
|
//
|
|
isTriggerVWapMidUnderSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Decision ...
|
|
|
|
//
|
|
double decisionPeak = decisionConditions.x121Conditions.peaksBuffer[1];
|
|
double decisionVale = decisionConditions.x121Conditions.valesBuffer[1];
|
|
|
|
//
|
|
bool isDecisionPeakInsideFVG =
|
|
//
|
|
decisionPeak <= iFVG.Upper() &&
|
|
decisionPeak >= iFVG.Lower()
|
|
//
|
|
;
|
|
bool isDecisionValeInsideFVG =
|
|
//
|
|
decisionVale <= iFVG.Upper() &&
|
|
decisionVale >= iFVG.Lower()
|
|
//
|
|
;
|
|
|
|
//
|
|
// VWap ...
|
|
|
|
//
|
|
bool isDecisionVWapFastBullish = decisionConditions.x121Conditions.isVWapFastBullish;
|
|
bool isDecisionVWapMidBullish = decisionConditions.x121Conditions.isVWapMidBullish;
|
|
bool isDecisionVWapSlowBullish = decisionConditions.x121Conditions.isVWapSlowBullish;
|
|
|
|
//
|
|
bool isDecisionVWapFastOverMid = decisionConditions.x121Conditions.isVWapFastOverMid;
|
|
bool isDecisionVWapMidOverSlow = decisionConditions.x121Conditions.isVWapMidOverSlow;
|
|
|
|
//
|
|
bool isDecisionVWapFastBearish = decisionConditions.x121Conditions.isVWapFastBearish;
|
|
bool isDecisionVWapMidBearish = decisionConditions.x121Conditions.isVWapMidBearish;
|
|
bool isDecisionVWapSlowBearish = decisionConditions.x121Conditions.isVWapSlowBearish;
|
|
|
|
//
|
|
bool isDecisionVWapFastUnderMid = decisionConditions.x121Conditions.isVWapFastUnderMid;
|
|
bool isDecisionVWapMidUnderSlow = decisionConditions.x121Conditions.isVWapMidUnderSlow;
|
|
|
|
//
|
|
bool isDecisionMarketBullish =
|
|
//
|
|
// State ...
|
|
(
|
|
//
|
|
(isDecisionVWapFastBullish &&
|
|
isDecisionVWapMidBullish &&
|
|
isDecisionVWapSlowBullish)
|
|
//
|
|
||
|
|
//
|
|
(isDecisionVWapMidBullish &&
|
|
isDecisionVWapSlowBullish)
|
|
//
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
// Order ...
|
|
(
|
|
//
|
|
(isDecisionVWapFastOverMid &&
|
|
isDecisionVWapMidOverSlow)
|
|
//
|
|
||
|
|
//
|
|
isDecisionVWapMidOverSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isDecisionMarketBearish =
|
|
//
|
|
// State ...
|
|
(
|
|
//
|
|
(isDecisionVWapFastBearish &&
|
|
isDecisionVWapMidBearish &&
|
|
isDecisionVWapSlowBearish)
|
|
//
|
|
||
|
|
//
|
|
(isDecisionVWapMidBearish &&
|
|
isDecisionVWapSlowBearish)
|
|
//
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
// Order ...
|
|
(
|
|
//
|
|
(isDecisionVWapFastUnderMid &&
|
|
isDecisionVWapMidUnderSlow)
|
|
//
|
|
||
|
|
//
|
|
isDecisionVWapMidUnderSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Analyse ...
|
|
|
|
//
|
|
double analysePeak = analyseConditions.x121Conditions.peaksBuffer[1];
|
|
double analyseVale = analyseConditions.x121Conditions.valesBuffer[1];
|
|
|
|
//
|
|
bool isAnalysePeakInsideFVG =
|
|
//
|
|
analysePeak <= iFVG.Upper() &&
|
|
analysePeak >= iFVG.Lower()
|
|
//
|
|
;
|
|
bool isAnalyseValeInsideFVG =
|
|
//
|
|
analyseVale <= iFVG.Upper() &&
|
|
analyseVale >= iFVG.Lower()
|
|
//
|
|
;
|
|
|
|
//
|
|
// VWap ...
|
|
|
|
//
|
|
bool isAnalyseVWapFastBullish = analyseConditions.x121Conditions.isVWapFastBullish;
|
|
bool isAnalyseVWapMidBullish = analyseConditions.x121Conditions.isVWapMidBullish;
|
|
bool isAnalyseVWapSlowBullish = analyseConditions.x121Conditions.isVWapSlowBullish;
|
|
|
|
//
|
|
bool isAnalyseVWapFastOverMid = analyseConditions.x121Conditions.isVWapFastOverMid;
|
|
bool isAnalyseVWapMidOverSlow = analyseConditions.x121Conditions.isVWapMidOverSlow;
|
|
|
|
//
|
|
bool isAnalyseVWapFastBearish = analyseConditions.x121Conditions.isVWapFastBearish;
|
|
bool isAnalyseVWapMidBearish = analyseConditions.x121Conditions.isVWapMidBearish;
|
|
bool isAnalyseVWapSlowBearish = analyseConditions.x121Conditions.isVWapSlowBearish;
|
|
|
|
//
|
|
bool isAnalyseVWapFastUnderMid = analyseConditions.x121Conditions.isVWapFastUnderMid;
|
|
bool isAnalyseVWapMidUnderSlow = analyseConditions.x121Conditions.isVWapMidUnderSlow;
|
|
|
|
//
|
|
bool isAnalyseMarketBullish =
|
|
//
|
|
// State ...
|
|
(
|
|
//
|
|
(isAnalyseVWapFastBullish &&
|
|
isAnalyseVWapMidBullish &&
|
|
isAnalyseVWapSlowBullish)
|
|
//
|
|
||
|
|
//
|
|
(isAnalyseVWapMidBullish &&
|
|
isAnalyseVWapSlowBullish)
|
|
//
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
// Order ...
|
|
(
|
|
//
|
|
(isAnalyseVWapFastOverMid &&
|
|
isAnalyseVWapMidOverSlow)
|
|
//
|
|
||
|
|
//
|
|
isAnalyseVWapMidOverSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isAnalyseMarketBearish =
|
|
//
|
|
// State ...
|
|
(
|
|
//
|
|
(isAnalyseVWapFastBearish &&
|
|
isAnalyseVWapMidBearish &&
|
|
isAnalyseVWapSlowBearish)
|
|
//
|
|
||
|
|
//
|
|
(isAnalyseVWapMidBearish &&
|
|
isAnalyseVWapSlowBearish)
|
|
//
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
// Order ...
|
|
(
|
|
//
|
|
(isAnalyseVWapFastUnderMid &&
|
|
isAnalyseVWapMidUnderSlow)
|
|
//
|
|
||
|
|
//
|
|
isAnalyseVWapMidUnderSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Verification ...
|
|
|
|
//
|
|
double verificationPeak = verificationConditions.x121Conditions.peaksBuffer[1];
|
|
double verificationVale = verificationConditions.x121Conditions.valesBuffer[1];
|
|
|
|
//
|
|
bool isVerificationPeakInsideFVG =
|
|
//
|
|
verificationPeak <= iFVG.Upper() &&
|
|
verificationPeak >= iFVG.Lower()
|
|
//
|
|
;
|
|
bool isVerificationValeInsideFVG =
|
|
//
|
|
verificationVale <= iFVG.Upper() &&
|
|
verificationVale >= iFVG.Lower()
|
|
//
|
|
;
|
|
|
|
//
|
|
// VWap ...
|
|
|
|
//
|
|
bool isVerificationVWapFastBullish = verificationConditions.x121Conditions.isVWapFastBullish;
|
|
bool isVerificationVWapMidBullish = verificationConditions.x121Conditions.isVWapMidBullish;
|
|
bool isVerificationVWapSlowBullish = verificationConditions.x121Conditions.isVWapSlowBullish;
|
|
|
|
//
|
|
bool isVerificationVWapFastOverMid = verificationConditions.x121Conditions.isVWapFastOverMid;
|
|
bool isVerificationVWapMidOverSlow = verificationConditions.x121Conditions.isVWapMidOverSlow;
|
|
|
|
//
|
|
bool isVerificationVWapFastBearish = verificationConditions.x121Conditions.isVWapFastBearish;
|
|
bool isVerificationVWapMidBearish = verificationConditions.x121Conditions.isVWapMidBearish;
|
|
bool isVerificationVWapSlowBearish = verificationConditions.x121Conditions.isVWapSlowBearish;
|
|
|
|
//
|
|
bool isVerificationVWapFastUnderMid = verificationConditions.x121Conditions.isVWapFastUnderMid;
|
|
bool isVerificationVWapMidUnderSlow = verificationConditions.x121Conditions.isVWapMidUnderSlow;
|
|
|
|
//
|
|
bool isVerificationMarketBullish =
|
|
//
|
|
// State ...
|
|
(
|
|
//
|
|
(isVerificationVWapFastBullish &&
|
|
isVerificationVWapMidBullish &&
|
|
isVerificationVWapSlowBullish)
|
|
//
|
|
||
|
|
//
|
|
(isVerificationVWapMidBullish &&
|
|
isVerificationVWapSlowBullish)
|
|
//
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
// Order ...
|
|
(
|
|
//
|
|
(isVerificationVWapFastOverMid &&
|
|
isVerificationVWapMidOverSlow)
|
|
//
|
|
||
|
|
//
|
|
isVerificationVWapMidOverSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isVerificationMarketBearish =
|
|
//
|
|
// State ...
|
|
(
|
|
//
|
|
(isVerificationVWapFastBearish &&
|
|
isVerificationVWapMidBearish &&
|
|
isVerificationVWapSlowBearish)
|
|
//
|
|
||
|
|
//
|
|
(isVerificationVWapMidBearish &&
|
|
isVerificationVWapSlowBearish)
|
|
//
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
// Order ...
|
|
(
|
|
//
|
|
(isVerificationVWapFastUnderMid &&
|
|
isVerificationVWapMidUnderSlow)
|
|
//
|
|
||
|
|
//
|
|
isVerificationVWapMidUnderSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Consolidation ...
|
|
|
|
//
|
|
double consolidationPeak = consolidationConditions.x121Conditions.peaksBuffer[1];
|
|
double consolidationVale = consolidationConditions.x121Conditions.valesBuffer[1];
|
|
|
|
//
|
|
bool isConsolidationPeakInsideFVG =
|
|
//
|
|
consolidationPeak <= iFVG.Upper() &&
|
|
consolidationPeak >= iFVG.Lower()
|
|
//
|
|
;
|
|
bool isConsolidationValeInsideFVG =
|
|
//
|
|
consolidationVale <= iFVG.Upper() &&
|
|
consolidationVale >= iFVG.Lower()
|
|
//
|
|
;
|
|
|
|
//
|
|
// VWap ...
|
|
|
|
//
|
|
bool isConsolidationVWapFastBullish = consolidationConditions.x121Conditions.isVWapFastBullish;
|
|
bool isConsolidationVWapMidBullish = consolidationConditions.x121Conditions.isVWapMidBullish;
|
|
bool isConsolidationVWapSlowBullish = consolidationConditions.x121Conditions.isVWapSlowBullish;
|
|
|
|
//
|
|
bool isConsolidationVWapFastOverMid = consolidationConditions.x121Conditions.isVWapFastOverMid;
|
|
bool isConsolidationVWapMidOverSlow = consolidationConditions.x121Conditions.isVWapMidOverSlow;
|
|
|
|
//
|
|
bool isConsolidationVWapFastBearish = consolidationConditions.x121Conditions.isVWapFastBearish;
|
|
bool isConsolidationVWapMidBearish = consolidationConditions.x121Conditions.isVWapMidBearish;
|
|
bool isConsolidationVWapSlowBearish = consolidationConditions.x121Conditions.isVWapSlowBearish;
|
|
|
|
//
|
|
bool isConsolidationVWapFastUnderMid = consolidationConditions.x121Conditions.isVWapFastUnderMid;
|
|
bool isConsolidationVWapMidUnderSlow = consolidationConditions.x121Conditions.isVWapMidUnderSlow;
|
|
|
|
//
|
|
bool isConsolidationMarketBullish =
|
|
//
|
|
// State ...
|
|
(
|
|
//
|
|
(isConsolidationVWapFastBullish &&
|
|
isConsolidationVWapMidBullish &&
|
|
isConsolidationVWapSlowBullish)
|
|
//
|
|
||
|
|
//
|
|
(isConsolidationVWapMidBullish &&
|
|
isConsolidationVWapSlowBullish)
|
|
//
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
// Order ...
|
|
(
|
|
//
|
|
(isConsolidationVWapFastOverMid &&
|
|
isConsolidationVWapMidOverSlow)
|
|
//
|
|
||
|
|
//
|
|
isConsolidationVWapMidOverSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isConsolidationMarketBearish =
|
|
//
|
|
// State ...
|
|
(
|
|
//
|
|
(isConsolidationVWapFastBearish &&
|
|
isConsolidationVWapMidBearish &&
|
|
isConsolidationVWapSlowBearish)
|
|
//
|
|
||
|
|
//
|
|
(isConsolidationVWapMidBearish &&
|
|
isConsolidationVWapSlowBearish)
|
|
//
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
// Order ...
|
|
(
|
|
//
|
|
(isConsolidationVWapFastUnderMid &&
|
|
isConsolidationVWapMidUnderSlow)
|
|
//
|
|
||
|
|
//
|
|
isConsolidationVWapMidUnderSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Sar ...
|
|
|
|
//
|
|
bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish;
|
|
bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish;
|
|
|
|
//
|
|
// Summarize Conditions ...
|
|
|
|
//
|
|
bool isSamePeak =
|
|
triggerPeak == decisionPeak &&
|
|
triggerPeak == analysePeak &&
|
|
triggerPeak == verificationPeak;
|
|
|
|
//
|
|
bool isPeaksInsideFVG =
|
|
//
|
|
isTriggerPeakInsideFVG &&
|
|
isDecisionPeakInsideFVG &&
|
|
isAnalysePeakInsideFVG &&
|
|
isVerificationPeakInsideFVG
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isSameVale =
|
|
triggerVale == decisionVale &&
|
|
triggerVale == analyseVale &&
|
|
triggerVale == verificationVale;
|
|
|
|
//
|
|
bool isValesInsideFVG =
|
|
//
|
|
isTriggerValeInsideFVG &&
|
|
isDecisionValeInsideFVG &&
|
|
isAnalyseValeInsideFVG &&
|
|
isVerificationValeInsideFVG
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isMarketReadyForLong =
|
|
//
|
|
// !isTriggerMarketBearish &&
|
|
// !isDecisionMarketBearish &&
|
|
// !isAnalyseMarketBearish &&
|
|
isTriggerMarketBullish &&
|
|
!isVerificationMarketBearish &&
|
|
!isConsolidationMarketBearish
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isMarketReadyForShort =
|
|
//
|
|
// !isTriggerMarketBullish &&
|
|
// !isDecisionMarketBullish &&
|
|
// !isAnalyseMarketBullish &&
|
|
isTriggerMarketBearish &&
|
|
!isVerificationMarketBullish &&
|
|
!isConsolidationMarketBullish
|
|
//
|
|
;
|
|
|
|
//
|
|
// Create Trigger ...
|
|
|
|
//
|
|
isBullish =
|
|
// isSameVale &&
|
|
lookupLong &&
|
|
isValesInsideFVG &&
|
|
// isMarketReadyForLong &&
|
|
isSarSwitchedToBullish &&
|
|
triggerVale <= iFVG.Upper() &&
|
|
triggerVale >= iFVG.Lower();
|
|
|
|
//
|
|
isBearish =
|
|
// isSamePeak &&
|
|
lookupShort &&
|
|
isPeaksInsideFVG &&
|
|
// isMarketReadyForShort &&
|
|
isSarSwitchedToBearish &&
|
|
triggerPeak <= iFVG.Upper() &&
|
|
triggerPeak >= iFVG.Lower();
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Cleanup Setup Conditions ...
|
|
int setupAge = conditions.GetSetupAge();
|
|
if (IsValidSize(setupAge) &&
|
|
IsValidSize(maxAllowedSetupAge) &&
|
|
setupAge >= maxAllowedSetupAge)
|
|
{
|
|
conditions.Clean();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.triggerTime = cTime;
|
|
conditions.sl = isBullish
|
|
? iFVG.Lower()
|
|
: iFVG.Upper();
|
|
conditions.type = isBullish
|
|
? X_POSITION_TYPE_LONG
|
|
: X_POSITION_TYPE_SHORT;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 X121 SMC Signal Lib
|
|
// -------------------------------------------------
|
|
// Name:
|
|
// 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 "../Classes/x-121.smc.market.cycle.helper.class.mq5"
|
|
#include "../Libraries/x-121.smc.lib.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
struct X121SMCStrategyXPVDPSignalConditions
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
|
|
//
|
|
double sl;
|
|
double target;
|
|
ENUM_X_DIRECTION dir;
|
|
ENUM_X_POSITION_TYPES type;
|
|
|
|
//
|
|
// Setup Props ...
|
|
|
|
//
|
|
datetime setupTime;
|
|
datetime triggerTime;
|
|
|
|
//
|
|
double peak;
|
|
double vale;
|
|
|
|
//
|
|
// Constructor ...
|
|
X121SMCStrategyXPVDPSignalConditions()
|
|
{
|
|
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();
|
|
}
|
|
|
|
/**
|
|
* 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()
|
|
{
|
|
//
|
|
peak = 0;
|
|
vale = 0;
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Extension Functions ...
|
|
|
|
//
|
|
// Detect Setup Conditions ...
|
|
bool DetectX121SMCXPVDPSiganlSetup(
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
X121SMCStrategyXPVDPSignalConditions &conditions,
|
|
//
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
string symbol = _symbol;
|
|
ENUM_TIMEFRAMES period = _period;
|
|
|
|
//
|
|
conditions.symbol = symbol;
|
|
conditions.period = period;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
double ll = cBar.FindLowest(9, MODE_LOW);
|
|
double hh = cBar.FindHighest(9, MODE_HIGH);
|
|
|
|
//
|
|
int zoneValidationDivider = 10;
|
|
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
|
.GetDonChainLength();
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
|
X121SMCCycleConditions triggerConditions;
|
|
result = triggerCycleHelper.GetConditions(
|
|
triggerCycleEvents,
|
|
triggerPoiEvents,
|
|
triggerConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
|
X121SMCCycleConditions verificationConditions;
|
|
result = verificationCycleHelper.GetConditions(
|
|
verificationCycleEvents,
|
|
verificationPoiEvents,
|
|
verificationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState triggerState = triggerConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState verificationState = verificationConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Setup Conditions ...
|
|
|
|
//
|
|
// Detect Market Trend ...
|
|
ENUM_X_DIRECTION trend;
|
|
bool hasTrend = consolidationCycleHelper
|
|
.DetectTrend(trend);
|
|
bool hasBullishTrend = hasTrend &&
|
|
IsBullish(trend);
|
|
bool hasBearishTrend = hasTrend &&
|
|
IsBearish(trend);
|
|
result = hasBullishTrend ||
|
|
hasBearishTrend;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Select Source State ...
|
|
XPOIState state = decisionState;
|
|
|
|
//
|
|
// Detect High Equals to Peaks or Low Equals to Vale ...
|
|
|
|
//
|
|
// Peak ...
|
|
double peak = triggerConditions.x121Conditions.peaksBuffer[1];
|
|
bool isNewPeak = triggerConditions.x121Conditions.isNewPeak;
|
|
bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast;
|
|
bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast;
|
|
|
|
//
|
|
// Vale ...
|
|
double vale = triggerConditions.x121Conditions.valesBuffer[1];
|
|
bool isNewVale = triggerConditions.x121Conditions.isNewVale;
|
|
bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast;
|
|
bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast;
|
|
|
|
//
|
|
bool isHighEqualsToPeak =
|
|
isNewPeak &&
|
|
peak == cBar.high;
|
|
|
|
//
|
|
bool isLowEqualsToVale =
|
|
isNewVale &&
|
|
vale == cBar.low;
|
|
|
|
//
|
|
result = isHighEqualsToPeak ||
|
|
isLowEqualsToVale;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Now We Have To Check DONChain Status ...
|
|
|
|
//
|
|
double donCUpper = triggerConditions.x121Conditions.donCloseUpperBuffer[1];
|
|
double donCUpperPrev = triggerConditions.x121Conditions.donCloseUpperBuffer[2];
|
|
|
|
//
|
|
double donCLower = triggerConditions.x121Conditions.donCloseLowerBuffer[1];
|
|
double donCLowerPrev = triggerConditions.x121Conditions.donCloseLowerBuffer[2];
|
|
|
|
//
|
|
double donOUpper = triggerConditions.x121Conditions.donOpenUpperBuffer[1];
|
|
double donOUpperPrev = triggerConditions.x121Conditions.donOpenUpperBuffer[2];
|
|
|
|
//
|
|
double donOLower = triggerConditions.x121Conditions.donOpenLowerBuffer[1];
|
|
double donOLowerPrev = triggerConditions.x121Conditions.donOpenLowerBuffer[2];
|
|
|
|
//
|
|
bool isDonUpperBullish = donCUpper > donOUpper;
|
|
bool isDonUpperBullishPrev = donCUpperPrev > donOUpperPrev;
|
|
|
|
//
|
|
bool isDonUpperBearish = donCUpper < donOUpper;
|
|
bool isDonUpperBearishPrev = donCUpperPrev < donOUpperPrev;
|
|
|
|
//
|
|
bool isDonUpperSwitchedToBullish = isDonUpperBullish &&
|
|
!isDonUpperBullishPrev;
|
|
|
|
//
|
|
bool isDonUpperSwitchedToBearish = isDonUpperBearish &&
|
|
!isDonUpperBearishPrev;
|
|
|
|
//
|
|
bool isDonLowerBullish = donCLower > donOLower;
|
|
bool isDonLowerBullishPrev = donCLowerPrev > donOLowerPrev;
|
|
|
|
//
|
|
bool isDonLowerBearish = donCLower < donOLower;
|
|
bool isDonLowerBearishPrev = donCLowerPrev < donOLowerPrev;
|
|
|
|
//
|
|
bool isDonLowerSwitchedToBullish = isDonLowerBullish &&
|
|
!isDonLowerBullishPrev;
|
|
|
|
//
|
|
bool isDonLowerSwitchedToBearish = isDonLowerBearish &&
|
|
!isDonLowerBearishPrev;
|
|
|
|
//
|
|
// Calculate State ...
|
|
|
|
//
|
|
bool isDonInBullishState =
|
|
//
|
|
// Upper ...
|
|
(isDonUpperBullish ||
|
|
isDonUpperSwitchedToBullish)
|
|
//
|
|
&&
|
|
//
|
|
// Lower ...
|
|
(isDonLowerBullish ||
|
|
isDonLowerSwitchedToBullish)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isDonInBearishState =
|
|
//
|
|
// Upper ...
|
|
(isDonUpperBearish ||
|
|
isDonUpperSwitchedToBearish)
|
|
//
|
|
&&
|
|
//
|
|
// Lower ...
|
|
(isDonLowerBearish ||
|
|
isDonLowerSwitchedToBearish)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Summary DonChain State ...
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
hasBullishTrend
|
|
//
|
|
&&
|
|
//
|
|
isDonInBullishState
|
|
//
|
|
&&
|
|
//
|
|
(isHighEqualsToPeak ||
|
|
isLowEqualsToVale)
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
hasBearishTrend
|
|
//
|
|
&&
|
|
//
|
|
isDonInBearishState
|
|
//
|
|
&&
|
|
//
|
|
(isHighEqualsToPeak ||
|
|
isLowEqualsToVale)
|
|
//
|
|
;
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check VWap Conditions ...
|
|
|
|
//
|
|
double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1];
|
|
double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1];
|
|
double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1];
|
|
|
|
//
|
|
double vwaps[3] = {
|
|
vwapFast,
|
|
vwapMid,
|
|
vwapSlow,
|
|
};
|
|
double vwapMax = GetMax(vwaps);
|
|
double vwapMin = GetMin(vwaps);
|
|
|
|
//
|
|
bool isCloseOverVwapMax =
|
|
//
|
|
ask > vwapMax &&
|
|
bid > vwapMax &&
|
|
(cBar.low > vwapMax ||
|
|
cBar.close > vwapMax)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCloseUnderVwapMin =
|
|
//
|
|
ask < vwapMin &&
|
|
bid < vwapMin &&
|
|
(cBar.high < vwapMin ||
|
|
cBar.close < vwapMin)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isVWapFastBullish = triggerConditions.x121Conditions.isVWapFastBullish;
|
|
bool isVWapFastBearish = triggerConditions.x121Conditions.isVWapFastBearish;
|
|
bool isVWapMidBullish = triggerConditions.x121Conditions.isVWapMidBullish;
|
|
bool isVWapMidBearish = triggerConditions.x121Conditions.isVWapMidBearish;
|
|
bool isVWapSlowBullish = triggerConditions.x121Conditions.isVWapSlowBullish;
|
|
bool isVWapSlowBearish = triggerConditions.x121Conditions.isVWapSlowBearish;
|
|
bool isVWapFastOverMid = triggerConditions.x121Conditions.isVWapFastOverMid;
|
|
bool isVWapMidOverSlow = triggerConditions.x121Conditions.isVWapMidOverSlow;
|
|
bool isVWapFastUnderMid = triggerConditions.x121Conditions.isVWapFastUnderMid;
|
|
bool isVWapMidUnderSlow = triggerConditions.x121Conditions.isVWapMidUnderSlow;
|
|
|
|
//
|
|
bool isVwapBullishFormed =
|
|
//
|
|
// Order ...
|
|
(isVWapFastOverMid ||
|
|
isVWapMidOverSlow ||
|
|
(isVWapFastOverMid &&
|
|
isVWapMidOverSlow))
|
|
//
|
|
&&
|
|
// State ...
|
|
((isVWapFastBullish &&
|
|
isVWapMidBullish) ||
|
|
(isVWapMidBullish &&
|
|
isVWapSlowBullish) ||
|
|
(isVWapFastBullish &&
|
|
isVWapMidBullish &&
|
|
isVWapSlowBullish))
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isVwapBearishFormed =
|
|
//
|
|
// Order ...
|
|
(isVWapFastUnderMid ||
|
|
isVWapMidUnderSlow ||
|
|
(isVWapFastUnderMid &&
|
|
isVWapMidUnderSlow))
|
|
//
|
|
&&
|
|
// State ...
|
|
((isVWapFastBearish &&
|
|
isVWapMidBearish) ||
|
|
(isVWapMidBearish &&
|
|
isVWapSlowBearish) ||
|
|
(isVWapFastBearish &&
|
|
isVWapMidBearish &&
|
|
isVWapSlowBearish))
|
|
//
|
|
;
|
|
|
|
//
|
|
// Summar VWap State ...
|
|
|
|
//
|
|
isBullish =
|
|
isBullish &&
|
|
isCloseOverVwapMax &&
|
|
isVwapBullishFormed;
|
|
|
|
//
|
|
isBearish =
|
|
isBearish &&
|
|
isCloseUnderVwapMin &&
|
|
isVwapBearishFormed;
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Sar State ...
|
|
double sar = triggerConditions.x121Conditions.sarBuffer[1];
|
|
|
|
//
|
|
bool isSarBullish = triggerConditions.x121Conditions.isSarBullish;
|
|
bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish;
|
|
|
|
//
|
|
bool isSarBearish = triggerConditions.x121Conditions.isSarBearish;
|
|
bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish;
|
|
|
|
//
|
|
// Summary Sar ...
|
|
|
|
//
|
|
bool isSarBullishFormed = isSarBullish ||
|
|
isSarSwitchedToBullish;
|
|
|
|
//
|
|
bool isSarBearishFormed = isSarBearish ||
|
|
isSarSwitchedToBearish;
|
|
|
|
//
|
|
isBullish =
|
|
isBullish &&
|
|
isSarBullishFormed;
|
|
|
|
//
|
|
isBearish =
|
|
isBearish &&
|
|
isSarBearishFormed;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.setupTime = cTime;
|
|
conditions.dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Trigger Conditions ...
|
|
bool DetectX121SMCXPVDPSiganlTrigger(
|
|
//
|
|
X121SMCStrategyXPVDPSignalConditions &conditions,
|
|
//
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper,
|
|
//
|
|
int maxAllowedSetupAge = 60 //
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = conditions.IsSetuped();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
datetime setupTime = conditions.setupTime;
|
|
ENUM_X_DIRECTION setupDir = conditions.dir;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
string symbol = _symbol;
|
|
ENUM_TIMEFRAMES period = _period;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
double ll = cBar.FindLowest(9, MODE_LOW);
|
|
double hh = cBar.FindHighest(9, MODE_HIGH);
|
|
|
|
//
|
|
int zoneValidationDivider = 10;
|
|
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
|
.GetDonChainLength();
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
|
X121SMCCycleConditions triggerConditions;
|
|
result = triggerCycleHelper.GetConditions(
|
|
triggerCycleEvents,
|
|
triggerPoiEvents,
|
|
triggerConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
|
X121SMCCycleConditions verificationConditions;
|
|
result = verificationCycleHelper.GetConditions(
|
|
verificationCycleEvents,
|
|
verificationPoiEvents,
|
|
verificationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState triggerState = triggerConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState verificationState = verificationConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Trigger Conditions ...
|
|
|
|
//
|
|
double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1];
|
|
double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1];
|
|
double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1];
|
|
|
|
//
|
|
double vwaps[3] = {
|
|
vwapFast,
|
|
vwapMid,
|
|
vwapSlow,
|
|
};
|
|
double vwapMax = GetMax(vwaps);
|
|
double vwapMin = GetMin(vwaps);
|
|
|
|
//
|
|
double sar = triggerConditions.x121Conditions.sarBuffer[1];
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
IsBullish(setupDir)
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
IsBearish(setupDir)
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Cleanup Setup Conditions ...
|
|
int setupAge = conditions.GetSetupAge();
|
|
if (IsValidSize(setupAge) &&
|
|
IsValidSize(maxAllowedSetupAge) &&
|
|
setupAge >= maxAllowedSetupAge)
|
|
{
|
|
conditions.Clean();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.triggerTime = cTime;
|
|
conditions.sl = isBullish
|
|
? MathMin(sar, vwapMin)
|
|
: MathMin(sar, vwapMax);
|
|
conditions.type = isBullish
|
|
? X_POSITION_TYPE_LONG
|
|
: X_POSITION_TYPE_SHORT;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 X121 SMC Signal Class
|
|
// -------------------------------------------------
|
|
// Name:
|
|
// 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 "../Classes/x-121.smc.market.cycle.helper.class.mq5"
|
|
#include "../Libraries/x-121.smc.lib.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
struct X121SMCStrategyTestSignalConditions
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
|
|
//
|
|
double sl;
|
|
double target;
|
|
ENUM_X_DIRECTION dir;
|
|
ENUM_X_POSITION_TYPES type;
|
|
|
|
//
|
|
// Setup Props ...
|
|
|
|
//
|
|
datetime setupTime;
|
|
datetime triggerTime;
|
|
|
|
//
|
|
// Constructor ...
|
|
X121SMCStrategyTestSignalConditions()
|
|
{
|
|
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();
|
|
}
|
|
|
|
/**
|
|
* 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()
|
|
{
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Extension Functions ...
|
|
|
|
//
|
|
// Detect Setup Conditions ...
|
|
bool DetectX121SMCTestSiganlSetup(
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
X121SMCStrategyTestSignalConditions &conditions,
|
|
//
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
string symbol = _symbol;
|
|
ENUM_TIMEFRAMES period = _period;
|
|
|
|
//
|
|
conditions.symbol = symbol;
|
|
conditions.period = period;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
double ll = cBar.FindLowest(9, MODE_LOW);
|
|
double hh = cBar.FindHighest(9, MODE_HIGH);
|
|
|
|
//
|
|
int zoneValidationDivider = 10;
|
|
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
|
.GetDonChainLength();
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
|
X121SMCCycleConditions triggerConditions;
|
|
result = triggerCycleHelper.GetConditions(
|
|
triggerCycleEvents,
|
|
triggerPoiEvents,
|
|
triggerConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
|
X121SMCCycleConditions verificationConditions;
|
|
result = verificationCycleHelper.GetConditions(
|
|
verificationCycleEvents,
|
|
verificationPoiEvents,
|
|
verificationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState triggerState = triggerConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState verificationState = verificationConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Setup Conditions ...
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
false
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
false
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Clean Conditions for Regenerate ...
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.setupTime = cTime;
|
|
conditions.dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Trigger Conditions ...
|
|
bool DetectX121SMCTestSiganlTrigger(
|
|
//
|
|
X121SMCStrategyTestSignalConditions &conditions,
|
|
//
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
XC121SMCCycleHelper *triggerCycleHelper,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *verificationCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper,
|
|
//
|
|
int maxAllowedSetupAge = 60 //
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = conditions.IsSetuped();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
datetime setupTime = conditions.setupTime;
|
|
ENUM_X_DIRECTION setupDir = conditions.dir;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
string symbol = _symbol;
|
|
ENUM_TIMEFRAMES period = _period;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
double ll = cBar.FindLowest(9, MODE_LOW);
|
|
double hh = cBar.FindHighest(9, MODE_HIGH);
|
|
|
|
//
|
|
int zoneValidationDivider = 10;
|
|
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
|
.GetDonChainLength();
|
|
|
|
//
|
|
double selectedSL = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Trigger ...
|
|
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
|
X121SMCCycleConditions triggerConditions;
|
|
result = triggerCycleHelper.GetConditions(
|
|
triggerCycleEvents,
|
|
triggerPoiEvents,
|
|
triggerConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Verification ...
|
|
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
|
X121SMCCycleConditions verificationConditions;
|
|
result = verificationCycleHelper.GetConditions(
|
|
verificationCycleEvents,
|
|
verificationPoiEvents,
|
|
verificationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState triggerState = triggerConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState verificationState = verificationConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Trigger Conditions ...
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
false
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
false
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Cleanup Setup Conditions ...
|
|
int setupAge = conditions.GetSetupAge();
|
|
if (IsValidSize(setupAge) &&
|
|
IsValidSize(maxAllowedSetupAge) &&
|
|
setupAge >= maxAllowedSetupAge)
|
|
{
|
|
conditions.Clean();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
conditions.triggerTime = cTime;
|
|
conditions.sl = isBullish
|
|
? 0
|
|
: 0;
|
|
conditions.type = isBullish
|
|
? X_POSITION_TYPE_LONG
|
|
: X_POSITION_TYPE_SHORT;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
////////////////////////////////////////// |