2101 lines
48 KiB
Plaintext
2101 lines
48 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"
|
|
|
|
//
|
|
const string X121SMCXTWPV_Method_1_Token = "X121SMCXTWPV_1";
|
|
const string X121SMCXTWPV_Method_2_Token = "X121SMCXTWPV_2";
|
|
const string X121SMCXTWPV_Method_3_Token = "X121SMCXTWPV_3";
|
|
|
|
//
|
|
enum ENUM_X_X121SMC_XTWPV_METHODS
|
|
{
|
|
X_X121SMC_XTWPV_METHOD_UNKNOWN,
|
|
X_X121SMC_XTWPV_METHOD_1,
|
|
X_X121SMC_XTWPV_METHOD_2,
|
|
X_X121SMC_XTWPV_METHOD_3,
|
|
};
|
|
|
|
//
|
|
string ToString(ENUM_X_X121SMC_XTWPV_METHODS value)
|
|
{
|
|
//
|
|
string result = NULL;
|
|
|
|
//
|
|
if (value == X_X121SMC_XTWPV_METHOD_UNKNOWN)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
switch (value)
|
|
{
|
|
//
|
|
case X_X121SMC_XTWPV_METHOD_1:
|
|
result = "Method_1";
|
|
break;
|
|
|
|
//
|
|
case X_X121SMC_XTWPV_METHOD_2:
|
|
result = "Method_2";
|
|
break;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ENUM_X_X121SMC_XTWPV_METHODS ParseMethod(string value)
|
|
{
|
|
//
|
|
ENUM_X_X121SMC_XTWPV_METHODS result = X_X121SMC_XTWPV_METHOD_UNKNOWN;
|
|
|
|
//
|
|
if (!IsValid(value))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
if (Contains(X121SMCXTWPV_Method_1_Token, value))
|
|
{
|
|
result = X_X121SMC_XTWPV_METHOD_1;
|
|
}
|
|
else if (Contains(X121SMCXTWPV_Method_2_Token, value))
|
|
{
|
|
result = X_X121SMC_XTWPV_METHOD_2;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// 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;
|
|
|
|
//
|
|
double point;
|
|
XPVPivot pivot;
|
|
|
|
//
|
|
XConsolidationZone consolidationZone;
|
|
|
|
//
|
|
string method;
|
|
|
|
//
|
|
bool hasSupportZone;
|
|
bool hasResistanceZone;
|
|
bool hasSupplyZone;
|
|
bool hasDemandZone;
|
|
bool hasOrderBlock;
|
|
bool hasFairValueGap;
|
|
XCSupportZone *supportZone;
|
|
XCResistanceZone *resistanceZone;
|
|
XCSupplyZone *supplyZone;
|
|
XCDemandZone *demandZone;
|
|
XCOrderBlock *orderBlock;
|
|
XCFVG *fairValueGap;
|
|
|
|
//
|
|
// 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()
|
|
{
|
|
//
|
|
point = 0;
|
|
pivot.Clean();
|
|
consolidationZone.Clean();
|
|
|
|
//
|
|
method = NULL;
|
|
|
|
//
|
|
CleanPriceInsideZones();
|
|
}
|
|
|
|
/**
|
|
* Clean Price Insie Zones ...
|
|
*/
|
|
void CleanPriceInsideZones()
|
|
{
|
|
//
|
|
hasSupportZone = false;
|
|
hasResistanceZone = false;
|
|
hasSupplyZone = false;
|
|
hasDemandZone = false;
|
|
hasOrderBlock = false;
|
|
hasFairValueGap = false;
|
|
|
|
//
|
|
supportZone = NULL;
|
|
resistanceZone = NULL;
|
|
supplyZone = NULL;
|
|
demandZone = NULL;
|
|
orderBlock = NULL;
|
|
fairValueGap = NULL;
|
|
}
|
|
|
|
/**
|
|
* Count Price Inside Zones ...
|
|
*
|
|
* @return ( int )
|
|
*/
|
|
int CountPriceInsideZones()
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
if (hasSupportZone)
|
|
{
|
|
result++;
|
|
}
|
|
|
|
//
|
|
if (hasResistanceZone)
|
|
{
|
|
result++;
|
|
}
|
|
|
|
//
|
|
if (hasSupplyZone)
|
|
{
|
|
result++;
|
|
}
|
|
|
|
//
|
|
if (hasDemandZone)
|
|
{
|
|
result++;
|
|
}
|
|
|
|
//
|
|
if (hasOrderBlock)
|
|
{
|
|
result++;
|
|
}
|
|
|
|
//
|
|
if (hasFairValueGap)
|
|
{
|
|
result++;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check Conditions Has Price Inside Zones ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool HasPriceInsideZones()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = IsValidSize(CountPriceInsideZones());
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check Conditions Has Bullish Price Inside Zone ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool HasBullishPriceInsideZone()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
HasPriceInsideZones() &&
|
|
//
|
|
(hasDemandZone ||
|
|
hasSupportZone ||
|
|
(hasOrderBlock &&
|
|
orderBlock.IsBullish()) ||
|
|
(hasFairValueGap &&
|
|
fairValueGap.IsBullish()))
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check Conditions Has Bearish Price Inside Zone ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool HasBearishPriceInsideZone()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
HasPriceInsideZones() &&
|
|
//
|
|
(hasSupplyZone ||
|
|
hasResistanceZone ||
|
|
(hasOrderBlock &&
|
|
orderBlock.IsBearish()) ||
|
|
(hasFairValueGap &&
|
|
fairValueGap.IsBearish()))
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check has Vald Pivot or not ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool HasPivot()
|
|
{
|
|
return pivot.IsValid();
|
|
}
|
|
|
|
/**
|
|
* Check Model Has Consolidation Zone or not ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool HasConsolidationZone()
|
|
{
|
|
return consolidationZone.IsValid();
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// 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;
|
|
}
|
|
|
|
//
|
|
XOHCL pBar;
|
|
result = pBar.Init(
|
|
symbol,
|
|
period,
|
|
pIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
double points = GetPoints(symbol);
|
|
|
|
//
|
|
int swingLoopback = 9;
|
|
double ll = cBar.FindLowest(swingLoopback, MODE_LOW);
|
|
double hh = cBar.FindHighest(swingLoopback, MODE_HIGH);
|
|
double llDown = cBar.FindLowesttDown(swingLoopback);
|
|
double hhUp = cBar.FindHighestUp(swingLoopback);
|
|
|
|
//
|
|
// 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 ...
|
|
|
|
//
|
|
XOHCL analyseCBar;
|
|
result = analyseCycleHelper.GetBar(
|
|
cBar,
|
|
analyseCBar //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL analysePBar;
|
|
result = analyseCBar.GetPreviousBar(analysePBar);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double bullishFib = GetFibonacciLevel(
|
|
analyseCBar.high,
|
|
analyseCBar.low,
|
|
GetFiboLevelValue(X_FIBO_LEVEL_382),
|
|
-1 //
|
|
);
|
|
|
|
//
|
|
double bearishFib = GetFibonacciLevel(
|
|
analyseCBar.high,
|
|
analyseCBar.low,
|
|
GetFiboLevelValue(X_FIBO_LEVEL_382),
|
|
1 //
|
|
);
|
|
|
|
//
|
|
// 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;
|
|
// }
|
|
|
|
//
|
|
// Detect Trend Based On Peaks and Vales ...
|
|
ENUM_X_DIRECTION trend;
|
|
bool hasTrend = analyseCycleHelper
|
|
.HasPVDirection(trend);
|
|
bool hasBullishTrend = hasTrend &&
|
|
IsBullish(trend);
|
|
bool hasBearishTrend = hasTrend &&
|
|
IsBearish(trend);
|
|
|
|
//
|
|
// Retrieve Active Pivots ...
|
|
|
|
//
|
|
XPVPivot peakPivot;
|
|
bool hasPeakPivot = analyseCycleHelper
|
|
.GetActivePeakPivot(peakPivot);
|
|
|
|
//
|
|
XPVPivot valePivot;
|
|
bool hasValePivot = analyseCycleHelper
|
|
.GetActiveValePivot(valePivot);
|
|
|
|
//
|
|
// Check Pivot ...
|
|
bool hasPivot = conditions.HasPivot();
|
|
if (!hasPivot)
|
|
{
|
|
//
|
|
if (hasPeakPivot && !hasValePivot)
|
|
{
|
|
conditions.pivot = peakPivot;
|
|
}
|
|
else if (hasValePivot && !hasPeakPivot)
|
|
{
|
|
conditions.pivot = valePivot;
|
|
}
|
|
else if (hasPeakPivot && hasValePivot)
|
|
{
|
|
//
|
|
if (peakPivot.from > valePivot.from)
|
|
{
|
|
conditions.pivot = peakPivot;
|
|
}
|
|
else if (valePivot.from > peakPivot.from)
|
|
{
|
|
conditions.pivot = valePivot;
|
|
}
|
|
}
|
|
|
|
//
|
|
hasPivot = conditions.HasPivot();
|
|
result = hasPivot;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Update Pivot States ...
|
|
if (hasPivot)
|
|
{
|
|
//
|
|
conditions.pivot.to = cTime;
|
|
analyseCycleHelper.FillPivotState(conditions.pivot);
|
|
|
|
//
|
|
// Check Pivot Renewation ...
|
|
bool hasNewPivot =
|
|
//
|
|
(hasPeakPivot &&
|
|
peakPivot.from > conditions.pivot.from) ||
|
|
(hasValePivot &&
|
|
valePivot.from > conditions.pivot.from)
|
|
//
|
|
;
|
|
result = !hasNewPivot;
|
|
if (!result)
|
|
{
|
|
//
|
|
conditions.pivot.Clean();
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
// XOHCL Conditions ...
|
|
|
|
//
|
|
// Fibo Pressure ...
|
|
ENUM_X_DIRECTION pBarFiboPressureDir;
|
|
bool pBarHasFiboPressure = triggerCycleHelper
|
|
.mBarAnalyser
|
|
.HasFiboPressure(
|
|
pBar,
|
|
pBarFiboPressureDir //
|
|
);
|
|
bool isPBarHasBullishFiboPressure =
|
|
pBarHasFiboPressure &&
|
|
IsBullish(pBarFiboPressureDir);
|
|
bool isPBarHasBearishFiboPressure =
|
|
pBarHasFiboPressure &&
|
|
IsBearish(pBarFiboPressureDir);
|
|
|
|
//
|
|
// Rejection ...
|
|
ENUM_X_DIRECTION pBarRejectionDir;
|
|
bool isPBarRejected = triggerCycleHelper
|
|
.mBarAnalyser
|
|
.IsRejectionBar(
|
|
pBar,
|
|
pBarRejectionDir,
|
|
0 //
|
|
);
|
|
bool isPBarBullishRejected =
|
|
isPBarRejected &&
|
|
IsBullish(pBarRejectionDir);
|
|
bool isPBarBearishRejected =
|
|
isPBarRejected &&
|
|
IsBearish(pBarRejectionDir);
|
|
|
|
//
|
|
// Momentum ...
|
|
ENUM_X_DIRECTION cBarMomentumDir;
|
|
bool isCBarMomentumBar = triggerCycleHelper
|
|
.mBarAnalyser
|
|
.IsMomentumBar(
|
|
cBar,
|
|
cBarMomentumDir,
|
|
0 //
|
|
);
|
|
bool isCBarBullishMomentumBar =
|
|
isCBarMomentumBar &&
|
|
IsBullish(cBarMomentumDir);
|
|
bool isCBarBearishMomentumBar =
|
|
isCBarMomentumBar &&
|
|
IsBearish(cBarMomentumDir);
|
|
|
|
//
|
|
// Engulfing ...
|
|
ENUM_X_DIRECTION cBarEngulfDir;
|
|
bool isCBarEngulfed = triggerCycleHelper
|
|
.mBarAnalyser
|
|
.IsEngulfBar(
|
|
cBar,
|
|
cBarEngulfDir,
|
|
0 //
|
|
);
|
|
bool isCBarBullishEngulfed =
|
|
isCBarEngulfed &&
|
|
IsBullish(cBarEngulfDir);
|
|
bool isCBarBearishEngulfed =
|
|
isCBarEngulfed &&
|
|
IsBearish(cBarEngulfDir);
|
|
|
|
//
|
|
// Helper cBar Conditions ...
|
|
bool isBearishFiboPassed = bullishFib <= conditions.pivot.lower;
|
|
bool isBullishFiboPassed = bearishFib >= conditions.pivot.upper;
|
|
|
|
//
|
|
// Detect a Zone Which Price Inside it ...
|
|
// Helper (Optional) ...
|
|
conditions.CleanPriceInsideZones();
|
|
bool hasPriceInsideZones = conditions.HasPriceInsideZones();
|
|
int priceInsideZonesCount = conditions.CountPriceInsideZones();
|
|
if (!hasPriceInsideZones)
|
|
{
|
|
//
|
|
hasPriceInsideZones = DetectPriceInsideZones(
|
|
verificationState,
|
|
cBar,
|
|
priceInsideZonesCount,
|
|
conditions.hasSupportZone,
|
|
conditions.supportZone,
|
|
conditions.hasResistanceZone,
|
|
conditions.resistanceZone,
|
|
conditions.hasSupplyZone,
|
|
conditions.supplyZone,
|
|
conditions.hasDemandZone,
|
|
conditions.demandZone,
|
|
conditions.hasOrderBlock,
|
|
conditions.orderBlock,
|
|
conditions.hasFairValueGap,
|
|
conditions.fairValueGap //
|
|
);
|
|
|
|
//
|
|
priceInsideZonesCount = conditions.CountPriceInsideZones();
|
|
}
|
|
|
|
//
|
|
// Check Price Inside Consolidation Zone ...
|
|
XConsolidationZone cZone;
|
|
bool hasConsolidationZone = conditions
|
|
.HasConsolidationZone();
|
|
if (!hasConsolidationZone)
|
|
{
|
|
//
|
|
hasConsolidationZone = triggerCycleHelper
|
|
.GetLastConsolidationZone(cZone);
|
|
//
|
|
if (!hasConsolidationZone)
|
|
{
|
|
//
|
|
XConsolidationZone cZones[];
|
|
int count = triggerCycleHelper
|
|
.FillConsolidationZones(cZones);
|
|
if (IsValidSize(count))
|
|
{
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XConsolidationZone iZone = cZones[i];
|
|
|
|
//
|
|
XCZone *iCZone;
|
|
bool isInited = ToZone(iZone, iCZone);
|
|
if (!isInited)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
bool isValid = IsPriceInsideZone(
|
|
cBar,
|
|
iCZone //
|
|
);
|
|
if (isValid)
|
|
{
|
|
cZone = iZone;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
conditions.consolidationZone = cZone;
|
|
hasConsolidationZone = conditions
|
|
.HasConsolidationZone();
|
|
}
|
|
}
|
|
if (hasConsolidationZone)
|
|
{
|
|
conditions.consolidationZone = cZone;
|
|
}
|
|
|
|
//
|
|
// PV Conditions ...
|
|
|
|
//
|
|
double analysePeak = analyseConditions.x121Conditions.peaksBuffer[1];
|
|
double analysePeakPrev = analyseConditions.x121Conditions.peaksBuffer[2];
|
|
double analysePeakDiff = MathAbs(analysePeakPrev - analysePeak);
|
|
|
|
//
|
|
bool isNewAnalysePeak = analyseConditions.x121Conditions.isNewPeak;
|
|
bool isNewAnalysePeakOverLast = analyseConditions.x121Conditions.isNewPeakOverLast;
|
|
bool isNewAnalysePeakUnderLast = analyseConditions.x121Conditions.isNewPeakUnderLast;
|
|
|
|
//
|
|
double analyseVale = analyseConditions.x121Conditions.valesBuffer[1];
|
|
double analyseValePrev = analyseConditions.x121Conditions.valesBuffer[2];
|
|
double analyseValeDiff = MathAbs(analyseValePrev - analyseVale);
|
|
|
|
//
|
|
bool isNewAnalyseVale = analyseConditions.x121Conditions.isNewVale;
|
|
bool isNewAnalyseValeOverLast = analyseConditions.x121Conditions.isNewValeOverLast;
|
|
bool isNewAnalyseValeUnderLast = analyseConditions.x121Conditions.isNewValeUnderLast;
|
|
|
|
//
|
|
double triggerPeak = triggerConditions.x121Conditions.peaksBuffer[1];
|
|
double triggerVale = triggerConditions.x121Conditions.valesBuffer[1];
|
|
|
|
//
|
|
int condition2MinPVDiffPoint = 30;
|
|
bool isPeakDiffPointPassed = analysePeakDiff >= (condition2MinPVDiffPoint * points);
|
|
bool isValeDiffPointPassed = analyseValeDiff >= (condition2MinPVDiffPoint * points);
|
|
|
|
//
|
|
// DONCHAIN Conditions ...
|
|
|
|
// //
|
|
// double analyseDonCloseUpper = analyseConditions.x121Conditions.donCloseUpperBuffer[1];
|
|
// double analyseDonCloseLower = analyseConditions.x121Conditions.donCloseLowerBuffer[1];
|
|
|
|
// //
|
|
// double analyseonOpenUpper = analyseConditions.x121Conditions.donOpenUpperBuffer[1];
|
|
// double analyseonOpenLower = analyseConditions.x121Conditions.donOpenLowerBuffer[1];
|
|
|
|
//
|
|
// OPEN ...
|
|
double triggerDonOpenUpper = triggerConditions.x121Conditions.donOpenUpperBuffer[1];
|
|
double triggerDonOpenLower = triggerConditions.x121Conditions.donOpenLowerBuffer[1];
|
|
double triggerDonOpenUpperPrev = triggerConditions.x121Conditions.donOpenUpperBuffer[2];
|
|
double triggerDonOpenLowerPrev = triggerConditions.x121Conditions.donOpenLowerBuffer[2];
|
|
|
|
//
|
|
// HIGH ...
|
|
double triggerDonHighUpper = triggerConditions.x121Conditions.donHighUpperBuffer[1];
|
|
double triggerDonHighLower = triggerConditions.x121Conditions.donHighLowerBuffer[1];
|
|
double triggerDonHighUpperPrev = triggerConditions.x121Conditions.donHighUpperBuffer[2];
|
|
double triggerDonHighLowerPrev = triggerConditions.x121Conditions.donHighLowerBuffer[2];
|
|
|
|
//
|
|
// CLOSE ...
|
|
double triggerDonCloseUpper = triggerConditions.x121Conditions.donCloseUpperBuffer[1];
|
|
double triggerDonCloseLower = triggerConditions.x121Conditions.donCloseLowerBuffer[1];
|
|
double triggerDonCloseUpperPrev = triggerConditions.x121Conditions.donCloseUpperBuffer[2];
|
|
double triggerDonCloseLowerPrev = triggerConditions.x121Conditions.donCloseLowerBuffer[2];
|
|
|
|
//
|
|
// LOW ...
|
|
double triggerDonLowUpper = triggerConditions.x121Conditions.donLowUpperBuffer[1];
|
|
double triggerDonLowLower = triggerConditions.x121Conditions.donLowLowerBuffer[1];
|
|
double triggerDonLowUpperPrev = triggerConditions.x121Conditions.donLowUpperBuffer[2];
|
|
double triggerDonLowLowerPrev = triggerConditions.x121Conditions.donLowLowerBuffer[2];
|
|
|
|
//
|
|
// Calculate PBar Rejected Don Upper and Lower ...
|
|
|
|
//
|
|
bool isPBarRejectDonLowUpper = pBar.high > triggerDonLowUpperPrev;
|
|
bool isPBarRejectDonOpenUpper = pBar.high > triggerDonOpenUpperPrev;
|
|
bool isPBarRejectDonCloseUpper = pBar.high > triggerDonCloseUpperPrev;
|
|
bool isPBarRejectedDonUpper = isPBarRejectDonLowUpper ||
|
|
isPBarRejectDonOpenUpper ||
|
|
isPBarRejectDonCloseUpper;
|
|
|
|
//
|
|
bool isPBarRejectDonHighLower = pBar.low < triggerDonHighLowerPrev;
|
|
bool isPBarRejectDonOpenLower = pBar.low < triggerDonOpenLowerPrev;
|
|
bool isPBarRejectDonCloseLower = pBar.low < triggerDonCloseLowerPrev;
|
|
bool isPBarRejectedDonLower = isPBarRejectDonHighLower ||
|
|
isPBarRejectDonOpenLower ||
|
|
isPBarRejectDonCloseLower;
|
|
|
|
//
|
|
// Calculate PBar Breaked Don Upper and Lower ...
|
|
|
|
//
|
|
bool isPBarBreakdDonLowUpper = pBar.GetUp() > triggerDonLowUpperPrev &&
|
|
pBar.GetDown() < triggerDonLowUpperPrev;
|
|
bool isPBarBreakdDonOpenUpper = pBar.GetUp() > triggerDonOpenUpperPrev &&
|
|
pBar.GetDown() < triggerDonOpenUpperPrev;
|
|
bool isPBarBreakdDonCloseUpper = pBar.GetUp() > triggerDonCloseUpperPrev &&
|
|
pBar.GetDown() < triggerDonCloseUpperPrev;
|
|
bool isPBarBreakedDonUpper = isPBarBreakdDonLowUpper ||
|
|
isPBarBreakdDonOpenUpper ||
|
|
isPBarBreakdDonCloseUpper;
|
|
|
|
//
|
|
bool isPBarBreakdDonHighLower = pBar.GetUp() > triggerDonHighLowerPrev &&
|
|
pBar.GetDown() < triggerDonHighLowerPrev;
|
|
bool isPBarBreakdDonOpenLower = pBar.GetUp() > triggerDonOpenLowerPrev &&
|
|
pBar.GetDown() < triggerDonOpenLowerPrev;
|
|
bool isPBarBreakdDonCloseLower = pBar.GetUp() > triggerDonCloseLowerPrev &&
|
|
pBar.GetDown() < triggerDonCloseLowerPrev;
|
|
bool isPBarBreakedDonLower = isPBarBreakdDonHighLower ||
|
|
isPBarBreakdDonOpenLower ||
|
|
isPBarBreakdDonCloseLower;
|
|
|
|
//
|
|
bool isRejectDonUpper =
|
|
//
|
|
// PBar ...
|
|
isPBarBearishRejected &&
|
|
isPBarRejectedDonUpper &&
|
|
//
|
|
// CBar ...
|
|
isCBarBearishMomentumBar &&
|
|
cBar.close < triggerDonLowUpper &&
|
|
//
|
|
triggerPeak == triggerDonHighUpper &&
|
|
//
|
|
true
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isRejectDonLower =
|
|
//
|
|
// PBar ...
|
|
isPBarBullishRejected &&
|
|
isPBarRejectedDonLower &&
|
|
//
|
|
// CBar ...
|
|
isCBarBullishMomentumBar &&
|
|
cBar.close > triggerDonHighLower &&
|
|
//
|
|
triggerVale == triggerDonLowLower &&
|
|
//
|
|
true
|
|
//
|
|
;
|
|
|
|
// //
|
|
// if (isRejectDonUpper ||
|
|
// isRejectDonLower)
|
|
// {
|
|
// Print("Don Rejected ...");
|
|
// }
|
|
|
|
//
|
|
bool isBreakedDonUpper =
|
|
//
|
|
false
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBreakedDonLower =
|
|
//
|
|
false
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isEngulfedDonUpper =
|
|
//
|
|
false
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isEngulfedDonLower =
|
|
//
|
|
false
|
|
//
|
|
;
|
|
|
|
//
|
|
// Method 1 ...
|
|
|
|
//
|
|
// Bullish Conditions 1 ...
|
|
bool bullishConditions1 =
|
|
//
|
|
// false
|
|
hasBullishTrend &&
|
|
isBullishFiboPassed &&
|
|
analyseCBar.IsBullish() &&
|
|
isNewAnalysePeakOverLast &&
|
|
conditions.pivot.upper < analysePeak &&
|
|
conditions.pivot.upper < analyseCBar.GetUp() &&
|
|
conditions.pivot.upper > analyseCBar.GetDown()
|
|
//
|
|
;
|
|
if (bullishConditions1)
|
|
{
|
|
//
|
|
conditions.point = conditions.pivot.upper;
|
|
conditions.method = ToString(X_X121SMC_XTWPV_METHOD_1);
|
|
}
|
|
|
|
//
|
|
// Bearish Conditions 1 ...
|
|
bool bearishConditions1 =
|
|
//
|
|
// false
|
|
hasBearishTrend &&
|
|
isBearishFiboPassed &&
|
|
analyseCBar.IsBearish() &&
|
|
isNewAnalyseValeUnderLast &&
|
|
conditions.pivot.lower > analyseVale &&
|
|
conditions.pivot.lower < analyseCBar.GetUp() &&
|
|
conditions.pivot.lower > analyseCBar.GetDown()
|
|
//
|
|
;
|
|
if (bearishConditions1)
|
|
{
|
|
//
|
|
conditions.point = conditions.pivot.lower;
|
|
conditions.method = ToString(X_X121SMC_XTWPV_METHOD_1);
|
|
}
|
|
|
|
//
|
|
// Method 2 ...
|
|
|
|
//
|
|
// Bullish Conditions 2 ...
|
|
bool bullishConditions2 =
|
|
//
|
|
false
|
|
// hasBullishTrend &&
|
|
// isNewValeOverLast &&
|
|
// donCloseLower > vale &&
|
|
// isValeDiffPointPassed
|
|
//
|
|
;
|
|
if (bullishConditions2)
|
|
{
|
|
//
|
|
conditions.point = analyseVale;
|
|
conditions.method = ToString(X_X121SMC_XTWPV_METHOD_2);
|
|
}
|
|
|
|
//
|
|
// Bearish Conditions 2 ...
|
|
bool bearishConditions2 =
|
|
//
|
|
false
|
|
// hasBearishTrend &&
|
|
// isNewPeakUnderLast &&
|
|
// donCloseUpper > peak &&
|
|
// isPeakDiffPointPassed
|
|
//
|
|
;
|
|
if (bearishConditions2)
|
|
{
|
|
//
|
|
conditions.point = analysePeak;
|
|
conditions.method = ToString(X_X121SMC_XTWPV_METHOD_2);
|
|
}
|
|
|
|
//
|
|
// Method 3 ...
|
|
|
|
//
|
|
// Bullish Conditions 3 ...
|
|
bool bullishConditions3 =
|
|
//
|
|
false
|
|
//
|
|
;
|
|
if (bullishConditions3)
|
|
{
|
|
//
|
|
conditions.point = analyseVale;
|
|
conditions.method = ToString(X_X121SMC_XTWPV_METHOD_3);
|
|
}
|
|
|
|
//
|
|
// Bearish Conditions 3 ...
|
|
bool bearishConditions3 =
|
|
//
|
|
false
|
|
//
|
|
;
|
|
if (bearishConditions3)
|
|
{
|
|
//
|
|
conditions.point = analysePeak;
|
|
conditions.method = ToString(X_X121SMC_XTWPV_METHOD_3);
|
|
}
|
|
|
|
//
|
|
// Summary Conditions ...
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
bullishConditions1 ||
|
|
bullishConditions2 ||
|
|
bullishConditions3
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
bearishConditions1 ||
|
|
bearishConditions2 ||
|
|
bearishConditions3
|
|
//
|
|
;
|
|
|
|
//
|
|
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 = IsBullish(setupDir);
|
|
bool isBearish = IsBearish(setupDir);
|
|
|
|
//
|
|
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 points = GetPoints(symbol);
|
|
|
|
//
|
|
int swingLoopback = 9;
|
|
double ll = cBar.FindLowest(swingLoopback, MODE_LOW);
|
|
double hh = cBar.FindHighest(swingLoopback, MODE_HIGH);
|
|
double llDown = cBar.FindLowesttDown(swingLoopback);
|
|
double hhUp = cBar.FindHighestUp(swingLoopback);
|
|
|
|
//
|
|
// 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 ...
|
|
|
|
//
|
|
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 Pivot Point ...
|
|
XPVPivotPoint pivotPoints[];
|
|
XPVPivotPoint nearestPivotPoint;
|
|
bool hasNearestPivotPoint = false;
|
|
int pivotPointsCount = triggerCycleHelper
|
|
.FillPivotPoints(pivotPoints);
|
|
if (IsValidSize(pivotPointsCount))
|
|
{
|
|
//
|
|
for (int i = 0; i < pivotPointsCount; i++)
|
|
{
|
|
//
|
|
XPVPivotPoint iPoint = pivotPoints[i];
|
|
|
|
//
|
|
bool canSet =
|
|
(isBullish
|
|
? iPoint.value < conditions.point
|
|
: iPoint.value > conditions.point)
|
|
//
|
|
&&
|
|
//
|
|
(!nearestPivotPoint.IsValid()
|
|
? true
|
|
: isBullish
|
|
? nearestPivotPoint.value > iPoint.value
|
|
: nearestPivotPoint.value < iPoint.value);
|
|
if (canSet)
|
|
{
|
|
nearestPivotPoint = iPoint;
|
|
}
|
|
}
|
|
|
|
//
|
|
hasNearestPivotPoint = nearestPivotPoint.IsValid();
|
|
}
|
|
|
|
//
|
|
// Detect Target ...
|
|
double target = CalculateTarget(
|
|
cBar,
|
|
analyseState,
|
|
setupDir //
|
|
);
|
|
if (target == 0)
|
|
{
|
|
//
|
|
target = CalculateTarget(
|
|
cBar,
|
|
verificationState,
|
|
setupDir //
|
|
);
|
|
}
|
|
|
|
//
|
|
double oppositTarget = CalculateTarget(
|
|
cBar,
|
|
analyseState,
|
|
Opposit(setupDir) //
|
|
);
|
|
|
|
//
|
|
double entry = GetEntry(
|
|
conditions.symbol,
|
|
setupDir //
|
|
);
|
|
|
|
//
|
|
// Filling SL Candidates ...
|
|
double atr = triggerConditions.x121Conditions.atrBuffer[1];
|
|
|
|
//
|
|
double sls[];
|
|
|
|
//
|
|
bool hasConsolidationZone = conditions.HasConsolidationZone();
|
|
if (hasConsolidationZone)
|
|
{
|
|
//
|
|
if (isBullish)
|
|
{
|
|
Add(
|
|
conditions.consolidationZone.lower,
|
|
sls //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
Add(
|
|
conditions.consolidationZone.upper,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
if (hasNearestPivotPoint)
|
|
{
|
|
Add(
|
|
nearestPivotPoint.value,
|
|
sls //
|
|
);
|
|
}
|
|
if (ArraySize(sls) == 0)
|
|
{
|
|
//
|
|
double pointsDiff = (10 * points);
|
|
double pointsPlus = conditions.point + pointsDiff;
|
|
double pointsMinus = conditions.point - pointsDiff;
|
|
|
|
//
|
|
// Force SL ...
|
|
Add(
|
|
conditions.point,
|
|
sls //
|
|
);
|
|
|
|
//
|
|
Add(
|
|
pointsPlus,
|
|
sls //
|
|
);
|
|
|
|
//
|
|
Add(
|
|
pointsMinus,
|
|
sls //
|
|
);
|
|
|
|
//
|
|
Add(
|
|
oppositTarget,
|
|
sls //
|
|
);
|
|
}
|
|
|
|
//
|
|
bool hasPriceInsideZones = conditions.HasPriceInsideZones();
|
|
bool hasBullishPriceInsideZone = conditions.HasBullishPriceInsideZone();
|
|
bool hasBearishPriceInsideZone = conditions.HasBearishPriceInsideZone();
|
|
|
|
//
|
|
if (
|
|
isBullish &&
|
|
hasPriceInsideZones &&
|
|
hasBullishPriceInsideZone //
|
|
)
|
|
{
|
|
//
|
|
// Demand ...
|
|
if (conditions.hasDemandZone)
|
|
{
|
|
//
|
|
Add(
|
|
conditions.demandZone.Lower(),
|
|
sls //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Support ...
|
|
if (conditions.hasSupportZone)
|
|
{
|
|
//
|
|
Add(
|
|
conditions.supportZone.Lower(),
|
|
sls //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Order Block ...
|
|
if (conditions.hasOrderBlock)
|
|
{
|
|
//
|
|
Add(
|
|
conditions.orderBlock.Lower(),
|
|
sls //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Fair Value Gap ...
|
|
if (conditions.hasFairValueGap)
|
|
{
|
|
//
|
|
Add(
|
|
conditions.fairValueGap.Lower(),
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
if (
|
|
isBearish &&
|
|
hasPriceInsideZones &&
|
|
hasBearishPriceInsideZone //
|
|
)
|
|
{
|
|
//
|
|
// Supply ...
|
|
if (conditions.hasSupplyZone)
|
|
{
|
|
//
|
|
Add(
|
|
conditions.supplyZone.Upper(),
|
|
sls //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Resistance ...
|
|
if (conditions.hasResistanceZone)
|
|
{
|
|
//
|
|
Add(
|
|
conditions.resistanceZone.Upper(),
|
|
sls //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Order Block ...
|
|
if (conditions.hasOrderBlock)
|
|
{
|
|
//
|
|
Add(
|
|
conditions.orderBlock.Upper(),
|
|
sls //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Fair Value Gap ...
|
|
if (conditions.hasFairValueGap)
|
|
{
|
|
//
|
|
Add(
|
|
conditions.fairValueGap.Upper(),
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
double slsMin = GetMin(sls);
|
|
double slsMax = GetMax(sls);
|
|
|
|
//
|
|
double sl = isBullish
|
|
? slsMin - atr
|
|
: slsMax + atr;
|
|
double risk = MathAbs(entry - sl);
|
|
double targetDelta = 2 * (risk / 3);
|
|
if (target == 0)
|
|
{
|
|
//
|
|
int minTargetPint = 50;
|
|
double minTargetPointValue = minTargetPint * points;
|
|
if (targetDelta < minTargetPointValue)
|
|
{
|
|
targetDelta = minTargetPointValue;
|
|
}
|
|
|
|
//
|
|
// Force Target On Half Risk ...
|
|
target =
|
|
isBullish
|
|
? entry + targetDelta
|
|
: entry - targetDelta;
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
conditions.sl = sl;
|
|
conditions.target = target;
|
|
conditions.triggerTime = cTime;
|
|
conditions.type = isBullish
|
|
? X_POSITION_TYPE_LONG
|
|
: X_POSITION_TYPE_SHORT;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Draw Conditions Pivot Zone ...
|
|
*
|
|
* @param conditions: X121SMCStrategyXTWPVSignalConditions instance Reference ...
|
|
* @param drawer: XCPOIDrawer pointer ...
|
|
* @param drawnObjects: XCBaseObject instance Reference Collection ...
|
|
* @param drawState: Boolean ...
|
|
* @param drawTicksZone: Boolean ...
|
|
* @param ignoreSwingHighs: Boolean ...
|
|
* @param ignoreSwingLows: Boolean ...
|
|
* @param ignoreSupportZones: Boolean ...
|
|
* @param ignoreResistanceZones: Boolean ...
|
|
* @param ignoreSupplyZones: Boolean ...
|
|
* @param ignoreDemandZones: Boolean ...
|
|
* @param ignoreBullishOrderBlocks: Boolean ...
|
|
* @param ignoreBearishOrderBlocks: Boolean ...
|
|
* @param ignoreBullishFairValueGaps: Boolean ...
|
|
* @param ignoreBearishFairValueGaps: Boolean ...
|
|
* @param ignoreBullishRejectionBars: Boolean ...
|
|
* @param ignoreBearishRejectionBars: Boolean ...
|
|
* @param ignoreBullishMomentumBars: Boolean ...
|
|
* @param ignoreBearishMomentumBars: Boolean ...
|
|
*
|
|
* @return ( int )
|
|
*/
|
|
int DrawXTWPVPivotZone(
|
|
X121SMCStrategyXTWPVSignalConditions &conditions,
|
|
XCPOIDrawer *drawer,
|
|
XCBaseObject *&drawnObjects[],
|
|
bool drawState = false,
|
|
bool drawTicksZone = false,
|
|
bool ignoreSwingHighs = false,
|
|
bool ignoreSwingLows = false,
|
|
bool ignoreSupportZones = false,
|
|
bool ignoreResistanceZones = false,
|
|
bool ignoreSupplyZones = false,
|
|
bool ignoreDemandZones = false,
|
|
bool ignoreBullishOrderBlocks = false,
|
|
bool ignoreBearishOrderBlocks = false,
|
|
bool ignoreBullishFairValueGaps = false,
|
|
bool ignoreBearishFairValueGaps = false,
|
|
bool ignoreBullishRejectionBars = false,
|
|
bool ignoreBearishRejectionBars = false,
|
|
bool ignoreBullishMomentumBars = false,
|
|
bool ignoreBearishMomentumBars = false //
|
|
)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
Clean(drawnObjects);
|
|
|
|
//
|
|
if (drawer == NULL ||
|
|
!conditions.HasPivot())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
drawer.DrawPivot(
|
|
//
|
|
conditions.pivot,
|
|
drawnObjects,
|
|
//
|
|
drawState,
|
|
drawTicksZone,
|
|
ignoreSwingHighs,
|
|
ignoreSwingLows,
|
|
ignoreSupportZones,
|
|
ignoreResistanceZones,
|
|
ignoreSupplyZones,
|
|
ignoreDemandZones,
|
|
ignoreBullishOrderBlocks,
|
|
ignoreBearishOrderBlocks,
|
|
ignoreBullishFairValueGaps,
|
|
ignoreBearishFairValueGaps,
|
|
ignoreBullishRejectionBars,
|
|
ignoreBearishRejectionBars,
|
|
ignoreBullishMomentumBars,
|
|
ignoreBearishMomentumBars //
|
|
);
|
|
|
|
//
|
|
result = ArraySize(drawnObjects);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Drw Conditions Price Inside Zones ...
|
|
*
|
|
* @param conditions: X121SMCStrategyXTWPVSignalConditions instance Reference ...
|
|
* @param drawer: XCPOIDrawer pointer ...
|
|
* @param drawnObjects: XCBaseObject instance Reference Collection ...
|
|
*
|
|
* @return ( int )
|
|
*/
|
|
int DrawTWPVPriceInsideZones(
|
|
X121SMCStrategyXTWPVSignalConditions &conditions,
|
|
XCPOIDrawer *drawer,
|
|
XCBaseObject *&drawnObjects[] //
|
|
)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
Clean(drawnObjects);
|
|
|
|
//
|
|
if (
|
|
drawer == NULL ||
|
|
!conditions.HasPriceInsideZones())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Support ...
|
|
if (conditions.hasSupportZone)
|
|
{
|
|
//
|
|
XCSupportZoneObject *iObj;
|
|
bool isCreated = drawer.CreateSupportZone(
|
|
conditions.supportZone,
|
|
iObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Resistance ...
|
|
if (conditions.hasResistanceZone)
|
|
{
|
|
//
|
|
XCResistanceZoneObject *iObj;
|
|
bool isCreated = drawer.CreateResistanceZone(
|
|
conditions.resistanceZone,
|
|
iObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Supply ...
|
|
if (conditions.hasSupplyZone)
|
|
{
|
|
//
|
|
XCSupplyZoneObject *iObj;
|
|
bool isCreated = drawer.CreateSupplyZone(
|
|
conditions.supplyZone,
|
|
iObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Demand ...
|
|
if (conditions.hasDemandZone)
|
|
{
|
|
//
|
|
XCDemandZoneObject *iObj;
|
|
bool isCreated = drawer.CreateDemandZone(
|
|
conditions.demandZone,
|
|
iObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Order Block ...
|
|
if (conditions.hasOrderBlock)
|
|
{
|
|
//
|
|
bool isBullish = conditions.orderBlock.IsBullish();
|
|
if (isBullish)
|
|
{
|
|
//
|
|
XCBullishOrderBlockObject *iObj;
|
|
bool isCreated = drawer.CreateBullishOrderBlock(
|
|
conditions.orderBlock,
|
|
iObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
XCBearishOrderBlockObject *iObj;
|
|
bool isCreated = drawer.CreateBearishOrderBlock(
|
|
conditions.orderBlock,
|
|
iObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// FairValueGap ...
|
|
if (conditions.hasFairValueGap)
|
|
{
|
|
//
|
|
bool isBullish = conditions.fairValueGap.IsBullish();
|
|
if (isBullish)
|
|
{
|
|
//
|
|
XCBullishFairValueGapObject *iObj;
|
|
bool isCreated = drawer.CreateBullishFairValueGap(
|
|
conditions.fairValueGap,
|
|
iObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
XCBearishFairValueGapObject *iObj;
|
|
bool isCreated = drawer.CreateBearishFairValueGap(
|
|
conditions.fairValueGap,
|
|
iObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
result = ArraySize(drawnObjects);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|