3699 lines
101 KiB
Plaintext
3699 lines
101 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 X121 SMC Signal Class
|
|
// -------------------------------------------------
|
|
// Name: XSupDemOBS
|
|
// 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.guard.lib.mq5"
|
|
#include "../Libraries/x-121.smc.lib.mq5"
|
|
#include "./x-121.smc.xsupdemobs.signal.lib.mq5"
|
|
|
|
//
|
|
// Definition ...
|
|
class XCX121SMCXSupDemOBSSignalDetector : public XCBase
|
|
{
|
|
//
|
|
public:
|
|
//
|
|
// Props ...
|
|
X121SMCStrategyXSupDemOBSSignalConditions mConditions;
|
|
X121SMCStrategyXSupDemOBSSignalConditions mConditionsCollection[];
|
|
|
|
//
|
|
// Constructor(s) ...
|
|
XCX121SMCXSupDemOBSSignalDetector()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
~XCX121SMCXSupDemOBSSignalDetector()
|
|
{
|
|
DeInit();
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Detect Setup Conditions ...
|
|
bool DetectSignalSetup(
|
|
//
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate Cycle Helpers ...
|
|
result =
|
|
//
|
|
visionCycleHelper != NULL &&
|
|
analyseCycleHelper != NULL &&
|
|
decisionCycleHelper != NULL &&
|
|
consolidationCycleHelper != NULL
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
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;
|
|
|
|
//
|
|
mConditions.symbol = symbol;
|
|
mConditions.period = period;
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
double points = GetPoints(symbol);
|
|
|
|
//
|
|
double target = 0;
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// 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;
|
|
}
|
|
|
|
//
|
|
// 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 decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Cycle X121Conditions ...
|
|
X121Conditions decisionXConditions = decisionConditions.x121Conditions;
|
|
X121Conditions analyseXConditions = analyseConditions.x121Conditions;
|
|
X121Conditions consolidationXConditions = consolidationConditions.x121Conditions;
|
|
X121Conditions visionXConditions = visionConditions.x121Conditions;
|
|
|
|
//
|
|
// Setup Conditions ...
|
|
|
|
//
|
|
XOHCL decisionZBar;
|
|
XOHCL decisionCBar;
|
|
XOHCL decisionPBar;
|
|
double decisionCBarBullishZoneChechValue = 0;
|
|
double decisionCBarBearishZoneChechValue = 0;
|
|
|
|
//
|
|
result = decisionZBar.Init(
|
|
decisionState.symbol,
|
|
decisionState.period,
|
|
0 //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(visionCycleEvents);
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationPoiEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
visionState.Clean();
|
|
analyseState.Clean();
|
|
decisionZBar.Clean();
|
|
decisionCBar.Clean();
|
|
decisionPBar.Clean();
|
|
decisionState.Clean();
|
|
visionConditions.Clean();
|
|
analyseConditions.Clean();
|
|
visionXConditions.Clean();
|
|
consolidationState.Clean();
|
|
decisionConditions.Clean();
|
|
analyseXConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
consolidationXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = decisionZBar
|
|
.GetPreviousBar(decisionCBar);
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(visionCycleEvents);
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationPoiEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
visionState.Clean();
|
|
analyseState.Clean();
|
|
decisionZBar.Clean();
|
|
decisionCBar.Clean();
|
|
decisionPBar.Clean();
|
|
decisionState.Clean();
|
|
visionConditions.Clean();
|
|
analyseConditions.Clean();
|
|
visionXConditions.Clean();
|
|
consolidationState.Clean();
|
|
decisionConditions.Clean();
|
|
analyseXConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
consolidationXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = decisionCBar
|
|
.GetPreviousBar(decisionPBar);
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(visionCycleEvents);
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationPoiEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
visionState.Clean();
|
|
analyseState.Clean();
|
|
decisionZBar.Clean();
|
|
decisionCBar.Clean();
|
|
decisionPBar.Clean();
|
|
decisionState.Clean();
|
|
visionConditions.Clean();
|
|
analyseConditions.Clean();
|
|
visionXConditions.Clean();
|
|
consolidationState.Clean();
|
|
decisionConditions.Clean();
|
|
analyseXConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
consolidationXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
decisionCBarBullishZoneChechValue = decisionCBar
|
|
.GetZoneCheckValue(X_DIRECTION_BULLISH);
|
|
decisionCBarBearishZoneChechValue = decisionCBar
|
|
.GetZoneCheckValue(X_DIRECTION_BEARISH);
|
|
|
|
//
|
|
mConditions.UpdateTo();
|
|
|
|
//
|
|
// 1- Detect Valid Working Area ...
|
|
|
|
//
|
|
bool hasVisionHighestSupplyZone = mConditions.HasVisionHighestSupplyZone();
|
|
bool hasConsolidationHighestSupplyZone = mConditions.HasConsolidationHighestSupplyZone();
|
|
|
|
//
|
|
bool hasVisionLowestDemandZone = mConditions.HasVisionLowestDemandZone();
|
|
bool hasConsolidationLowestDemandZone = mConditions.HasConsolidationLowestDemandZone();
|
|
|
|
//
|
|
bool hasWorkingZone = mConditions.workingZone.IsValid();
|
|
|
|
//
|
|
bool isDestroyed = false;
|
|
ENUM_X_DIRECTION destroyedDir;
|
|
|
|
//
|
|
XOHCL trendStartBar;
|
|
ENUM_X_DIRECTION trendDir;
|
|
bool hasTrend = false;
|
|
bool hasBullishTrend = false;
|
|
bool hasBearishTrend = false;
|
|
|
|
//
|
|
if (!hasVisionHighestSupplyZone)
|
|
{
|
|
//
|
|
int hasZones = visionState.HasSupplyZones();
|
|
int zonesCount = visionState.HasSupplyZones();
|
|
|
|
//
|
|
if (hasZones)
|
|
{
|
|
//
|
|
int idx = GetHighest(visionState.supplyZones);
|
|
hasVisionHighestSupplyZone = IsValidIndex(idx);
|
|
if (hasVisionHighestSupplyZone)
|
|
{
|
|
//
|
|
// Validate Zone ...
|
|
XCSupplyZone *zone = visionState.supplyZones[idx];
|
|
bool isBelow = IsBelow(
|
|
decisionCBarBearishZoneChechValue,
|
|
zone //
|
|
);
|
|
if (isBelow)
|
|
{
|
|
mConditions.visionHighestSupplyZone = zone;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
hasVisionHighestSupplyZone = mConditions.HasVisionHighestSupplyZone();
|
|
}
|
|
|
|
//
|
|
if (!hasVisionLowestDemandZone)
|
|
{
|
|
//
|
|
int hasZones = visionState.HasDemandZones();
|
|
int zonesCount = visionState.HasDemandZones();
|
|
|
|
//
|
|
if (hasZones)
|
|
{
|
|
//
|
|
int idx = GetLowest(visionState.demandZones);
|
|
hasVisionLowestDemandZone = IsValidIndex(idx);
|
|
if (hasVisionLowestDemandZone)
|
|
{
|
|
//
|
|
// Validate Zone ...
|
|
XCDemandZone *zone = visionState.demandZones[idx];
|
|
bool isAbove = IsAbove(
|
|
decisionCBarBullishZoneChechValue,
|
|
zone //
|
|
);
|
|
if (isAbove)
|
|
{
|
|
mConditions.visionLowestDemandZone = zone;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
hasVisionLowestDemandZone = mConditions.HasVisionLowestDemandZone();
|
|
}
|
|
|
|
//
|
|
if (!hasConsolidationHighestSupplyZone)
|
|
{
|
|
//
|
|
int hasZones = consolidationState.HasSupplyZones();
|
|
int zonesCount = consolidationState.HasSupplyZones();
|
|
|
|
//
|
|
if (hasZones)
|
|
{
|
|
//
|
|
int idx = GetHighest(consolidationState.supplyZones);
|
|
hasConsolidationHighestSupplyZone = IsValidIndex(idx);
|
|
if (hasConsolidationHighestSupplyZone)
|
|
{
|
|
//
|
|
// Validate Zone ...
|
|
XCSupplyZone *zone = consolidationState.supplyZones[idx];
|
|
bool isBelow = IsBelow(
|
|
decisionCBarBearishZoneChechValue,
|
|
zone //
|
|
);
|
|
if (isBelow)
|
|
{
|
|
//
|
|
if (mConditions.workingZone.IsValid())
|
|
{
|
|
//
|
|
RemoveDraws();
|
|
result = false;
|
|
mConditions.Clean();
|
|
RemoveWorkingZoneDraws();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mConditions.consolidationHighestSupplyZone = zone;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
hasConsolidationHighestSupplyZone = mConditions.HasConsolidationHighestSupplyZone();
|
|
}
|
|
|
|
//
|
|
if (!hasConsolidationLowestDemandZone)
|
|
{
|
|
//
|
|
int hasZones = consolidationState.HasDemandZones();
|
|
int zonesCount = consolidationState.HasDemandZones();
|
|
|
|
//
|
|
if (hasZones)
|
|
{
|
|
//
|
|
int idx = GetLowest(consolidationState.demandZones);
|
|
hasConsolidationLowestDemandZone = IsValidIndex(idx);
|
|
if (hasConsolidationLowestDemandZone)
|
|
{
|
|
//
|
|
// Validate Zone ...
|
|
XCDemandZone *zone = consolidationState.demandZones[idx];
|
|
bool isAbove = IsAbove(
|
|
decisionCBarBullishZoneChechValue,
|
|
zone //
|
|
);
|
|
if (isAbove)
|
|
{
|
|
//
|
|
if (mConditions.workingZone.IsValid())
|
|
{
|
|
//
|
|
RemoveDraws();
|
|
result = false;
|
|
mConditions.Clean();
|
|
RemoveWorkingZoneDraws();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mConditions.consolidationLowestDemandZone = zone;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
hasConsolidationLowestDemandZone = mConditions.HasConsolidationLowestDemandZone();
|
|
}
|
|
|
|
//
|
|
// 2- Detect Working Zone ...
|
|
if (!hasWorkingZone)
|
|
{
|
|
hasWorkingZone = mConditions.ExtractWorkingZone();
|
|
}
|
|
|
|
//
|
|
// Here we Can Detect Price Inside SupDem Zones ...
|
|
|
|
//
|
|
bool isPriceInsideSupplyZone = false;
|
|
bool isPriceInsideDemandZone = false;
|
|
bool isPriceInsideVisionSupplyZone = false;
|
|
bool isPriceInsideVisionDemandZone = false;
|
|
bool isPriceInsideConsolidationSupplyZone = false;
|
|
bool isPriceInsideConsolidationDemandZone = false;
|
|
if (hasVisionLowestDemandZone)
|
|
{
|
|
//
|
|
double iUpper = mConditions.visionLowestDemandZone.Upper();
|
|
double iLower = mConditions.visionLowestDemandZone.Lower();
|
|
|
|
//
|
|
isPriceInsideVisionDemandZone =
|
|
//
|
|
decisionZBar.high < iUpper &&
|
|
decisionCBar.high < iUpper &&
|
|
//
|
|
decisionZBar.low > iLower &&
|
|
decisionCBar.low > iLower
|
|
//
|
|
;
|
|
}
|
|
if (hasVisionHighestSupplyZone)
|
|
{
|
|
//
|
|
double iUpper = mConditions.visionHighestSupplyZone.Upper();
|
|
double iLower = mConditions.visionHighestSupplyZone.Lower();
|
|
|
|
//
|
|
isPriceInsideVisionSupplyZone =
|
|
//
|
|
decisionZBar.high < iUpper &&
|
|
decisionCBar.high < iUpper &&
|
|
//
|
|
decisionZBar.low > iLower &&
|
|
decisionCBar.low > iLower
|
|
//
|
|
;
|
|
}
|
|
if (hasConsolidationLowestDemandZone)
|
|
{
|
|
//
|
|
double iUpper = mConditions.consolidationLowestDemandZone.Upper();
|
|
double iLower = mConditions.consolidationLowestDemandZone.Lower();
|
|
|
|
//
|
|
isPriceInsideConsolidationDemandZone =
|
|
//
|
|
decisionZBar.high < iUpper &&
|
|
decisionCBar.high < iUpper &&
|
|
//
|
|
decisionZBar.low > iLower &&
|
|
decisionCBar.low > iLower
|
|
//
|
|
;
|
|
}
|
|
if (hasConsolidationHighestSupplyZone)
|
|
{
|
|
//
|
|
double iUpper = mConditions.consolidationHighestSupplyZone.Upper();
|
|
double iLower = mConditions.consolidationHighestSupplyZone.Lower();
|
|
|
|
//
|
|
isPriceInsideConsolidationSupplyZone =
|
|
//
|
|
decisionZBar.high < iUpper &&
|
|
decisionCBar.high < iUpper &&
|
|
//
|
|
decisionZBar.low > iLower &&
|
|
decisionCBar.low > iLower
|
|
//
|
|
;
|
|
}
|
|
|
|
//
|
|
isPriceInsideSupplyZone = isPriceInsideVisionSupplyZone ||
|
|
isPriceInsideConsolidationSupplyZone;
|
|
if (isPriceInsideSupplyZone)
|
|
{
|
|
//
|
|
if (isPriceInsideVisionSupplyZone)
|
|
{
|
|
mConditions.insideSupplyZone = mConditions.visionHighestSupplyZone;
|
|
}
|
|
else if (isPriceInsideConsolidationSupplyZone)
|
|
{
|
|
mConditions.insideSupplyZone = mConditions.consolidationHighestSupplyZone;
|
|
}
|
|
}
|
|
|
|
//
|
|
isPriceInsideDemandZone = isPriceInsideVisionDemandZone ||
|
|
isPriceInsideConsolidationDemandZone;
|
|
if (isPriceInsideDemandZone)
|
|
{
|
|
//
|
|
if (isPriceInsideVisionDemandZone)
|
|
{
|
|
mConditions.insideDemandZone = mConditions.visionLowestDemandZone;
|
|
}
|
|
else if (isPriceInsideConsolidationDemandZone)
|
|
{
|
|
mConditions.insideDemandZone = mConditions.consolidationLowestDemandZone;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Check Working Zone Destroy ...
|
|
isDestroyed = mConditions.IsWorkingZoneDestroyed(
|
|
destroyedDir, // Direction ...
|
|
0, // Bar Index ...
|
|
decisionState.period // Period ...
|
|
);
|
|
if (isDestroyed)
|
|
{
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(visionCycleEvents);
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationPoiEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
visionState.Clean();
|
|
analyseState.Clean();
|
|
decisionZBar.Clean();
|
|
decisionCBar.Clean();
|
|
decisionPBar.Clean();
|
|
decisionState.Clean();
|
|
visionConditions.Clean();
|
|
analyseConditions.Clean();
|
|
visionXConditions.Clean();
|
|
consolidationState.Clean();
|
|
decisionConditions.Clean();
|
|
analyseXConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
consolidationXConditions.Clean();
|
|
|
|
//
|
|
result = false;
|
|
mConditions.Clean();
|
|
RemoveDraws();
|
|
RemoveWorkingZoneDraws();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// 2- Detect Market Trend Based On Nearest Zone Hunting ...
|
|
hasTrend = mConditions.DetectOveralTrend(
|
|
trendStartBar,
|
|
trendDir,
|
|
0 //
|
|
);
|
|
hasBullishTrend = IsBullish(trendDir);
|
|
hasBearishTrend = IsBearish(trendDir);
|
|
|
|
//
|
|
result = hasTrend;
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(visionCycleEvents);
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationPoiEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
visionState.Clean();
|
|
analyseState.Clean();
|
|
decisionZBar.Clean();
|
|
decisionCBar.Clean();
|
|
decisionPBar.Clean();
|
|
decisionState.Clean();
|
|
visionConditions.Clean();
|
|
analyseConditions.Clean();
|
|
visionXConditions.Clean();
|
|
consolidationState.Clean();
|
|
decisionConditions.Clean();
|
|
analyseXConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
consolidationXConditions.Clean();
|
|
|
|
//
|
|
RemoveDraws();
|
|
RemoveWorkingZoneDraws();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// 3- Checking Price Inside Valid Quarters Based on Trend ...
|
|
|
|
//
|
|
// in Bullish Trend:
|
|
// -----------------------------
|
|
// - if Price Under Lower: HIGH;
|
|
// - if Price Under Quarter 3 and Above Lower: REGULAR;
|
|
// - if Price Under Quarter 2 and Above Quarter 3: LOW;
|
|
// - if Price Above Quarter 2: NONE;
|
|
|
|
//
|
|
// in Bearish Trend:
|
|
// -----------------------------
|
|
// - if Price Above Upper: HIGH;
|
|
// - if Price Above Quarter 1 and Below Upper: REGULAR;
|
|
// - if Price Above Quarter 2 and Below Quarter 1: LOW;
|
|
// - if Price Below Quarter 2: NONE;
|
|
|
|
//
|
|
ENUM_X121SMC_XSUPDEMOBS_PRIORITY bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE;
|
|
ENUM_X121SMC_XSUPDEMOBS_PRIORITY bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE;
|
|
|
|
//
|
|
bool isInQuarter0 = CheckPriceInside(
|
|
decisionZBar,
|
|
decisionCBar,
|
|
mConditions.workingZone.zoneUpper,
|
|
mConditions.workingZone.upper //
|
|
);
|
|
bool isInQuarter1 = CheckPriceInside(
|
|
decisionZBar,
|
|
decisionCBar,
|
|
mConditions.workingZone.upper,
|
|
mConditions.workingZone.quarter1 //
|
|
);
|
|
bool isInQuarter2 = CheckPriceInside(
|
|
decisionZBar,
|
|
decisionCBar,
|
|
mConditions.workingZone.quarter1,
|
|
mConditions.workingZone.quarter2 //
|
|
);
|
|
bool isInQuarter3 = CheckPriceInside(
|
|
decisionZBar,
|
|
decisionCBar,
|
|
mConditions.workingZone.quarter2,
|
|
mConditions.workingZone.quarter3 //
|
|
);
|
|
bool isInQuarter4 = CheckPriceInside(
|
|
decisionZBar,
|
|
decisionCBar,
|
|
mConditions.workingZone.quarter3,
|
|
mConditions.workingZone.lower //
|
|
);
|
|
bool isInQuarter5 = CheckPriceInside(
|
|
decisionZBar,
|
|
decisionCBar,
|
|
mConditions.workingZone.lower,
|
|
mConditions.workingZone.zoneLower //
|
|
);
|
|
|
|
//
|
|
if (isInQuarter0)
|
|
{
|
|
//
|
|
bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE;
|
|
bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_HIGH;
|
|
}
|
|
else if (isInQuarter1)
|
|
{
|
|
//
|
|
bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE;
|
|
bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_REGULAR;
|
|
}
|
|
else if (isInQuarter2)
|
|
{
|
|
//
|
|
bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_WEAK;
|
|
bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_LOW;
|
|
}
|
|
else if (isInQuarter3)
|
|
{
|
|
//
|
|
bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_LOW;
|
|
bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_WEAK;
|
|
}
|
|
else if (isInQuarter4)
|
|
{
|
|
//
|
|
bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_REGULAR;
|
|
bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE;
|
|
}
|
|
else if (isInQuarter5)
|
|
{
|
|
//
|
|
bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_HIGH;
|
|
bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE;
|
|
}
|
|
|
|
//
|
|
bool lookingForLong = bullishPriority != X121SMC_XSUPDEMOBS_PRIORITY_NONE;
|
|
bool lookingForShort = bearishPriority != X121SMC_XSUPDEMOBS_PRIORITY_NONE;
|
|
|
|
//
|
|
result = lookingForLong ||
|
|
lookingForShort;
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(visionCycleEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationPoiEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
visionState.Clean();
|
|
analyseState.Clean();
|
|
decisionZBar.Clean();
|
|
decisionCBar.Clean();
|
|
decisionPBar.Clean();
|
|
decisionState.Clean();
|
|
visionConditions.Clean();
|
|
analyseConditions.Clean();
|
|
visionXConditions.Clean();
|
|
consolidationState.Clean();
|
|
decisionConditions.Clean();
|
|
analyseXConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
consolidationXConditions.Clean();
|
|
|
|
//
|
|
RemoveDraws();
|
|
RemoveWorkingZoneDraws();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Order Blocks in Direction of Trend ...
|
|
XCOrderBlock *obs[];
|
|
Copy(
|
|
consolidationState.bullishOrderBlocks,
|
|
obs //
|
|
);
|
|
Copy(
|
|
consolidationState.bearishOrderBlocks,
|
|
obs //
|
|
);
|
|
|
|
//
|
|
// Validate OB FVG ...
|
|
XCFVG *fvgs[];
|
|
Copy(
|
|
analyseState.bullishFairValueGaps,
|
|
fvgs //
|
|
);
|
|
Copy(
|
|
analyseState.bearishFairValueGaps,
|
|
fvgs //
|
|
);
|
|
|
|
//
|
|
int obsCount = ArraySize(obs);
|
|
bool hasOBs = IsValidSize(obsCount);
|
|
|
|
//
|
|
int fvgsCount = ArraySize(fvgs);
|
|
bool hasFVGs = IsValidSize(fvgsCount);
|
|
|
|
//
|
|
bool hasOBFVGs = mConditions.HasOBFVGs();
|
|
int obFVGsCount = mConditions.CountOBFVGs();
|
|
|
|
//
|
|
if (hasOBs &&
|
|
hasFVGs &&
|
|
!hasOBFVGs)
|
|
{
|
|
//
|
|
for (int i = 0; i < obsCount; i++)
|
|
{
|
|
//
|
|
XCOrderBlock *iOB = obs[i];
|
|
|
|
//
|
|
// Check Ob Index inside OB FVGS ...
|
|
bool isOBFVGExists = false;
|
|
hasOBFVGs = mConditions.HasOBFVGs();
|
|
obFVGsCount = mConditions.CountOBFVGs();
|
|
if (hasOBFVGs)
|
|
{
|
|
//
|
|
for (int j = 0; j < obFVGsCount; j++)
|
|
{
|
|
//
|
|
bool isSame = IsSame(
|
|
mConditions.obFVGs[j].ob,
|
|
iOB //
|
|
);
|
|
|
|
//
|
|
if (isSame)
|
|
{
|
|
//
|
|
isOBFVGExists = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (isOBFVGExists)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
for (int j = 0; j < fvgsCount; j++)
|
|
{
|
|
//
|
|
XCFVG *jFVG = fvgs[j];
|
|
|
|
//
|
|
ENUM_TIMEFRAMES jPeriod = jFVG.GetPeriod();
|
|
if (jPeriod != PERIOD_M15)
|
|
{
|
|
Print(ToString(jPeriod));
|
|
}
|
|
|
|
//
|
|
XOBFVG iOBFVG;
|
|
|
|
//
|
|
iOBFVG.time = cTime;
|
|
iOBFVG.symbol = iOB.GetSymbol();
|
|
iOBFVG.period = iOB.GetPeriod();
|
|
|
|
//
|
|
iOBFVG.ob = iOB;
|
|
iOBFVG.fvg = jFVG;
|
|
|
|
//
|
|
bool isValidOBFVG = iOBFVG.IsValid();
|
|
if (isValidOBFVG)
|
|
{
|
|
//
|
|
AddRef(
|
|
iOBFVG,
|
|
mConditions.obFVGs //
|
|
);
|
|
|
|
//
|
|
iOBFVG.Clean();
|
|
|
|
//
|
|
break;
|
|
}
|
|
|
|
//
|
|
iOBFVG.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
hasOBFVGs = mConditions.HasOBFVGs();
|
|
obFVGsCount = mConditions.CountOBFVGs();
|
|
}
|
|
|
|
//
|
|
// Now We Have to Check OBFVGs ...
|
|
result = hasOBFVGs;
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(obs);
|
|
Clean(fvgs);
|
|
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(visionCycleEvents);
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationPoiEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
visionState.Clean();
|
|
analyseState.Clean();
|
|
decisionZBar.Clean();
|
|
decisionCBar.Clean();
|
|
decisionPBar.Clean();
|
|
decisionState.Clean();
|
|
visionConditions.Clean();
|
|
analyseConditions.Clean();
|
|
visionXConditions.Clean();
|
|
consolidationState.Clean();
|
|
decisionConditions.Clean();
|
|
analyseXConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
consolidationXConditions.Clean();
|
|
|
|
//
|
|
RemoveDraws();
|
|
RemoveWorkingZoneDraws();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Un Activated POI(s) ...
|
|
// including:
|
|
// - Order Blocks;
|
|
// - Fair Value Gaps;
|
|
|
|
//
|
|
bool hasUnActivatedOBs = false;
|
|
bool hasUnActivatedFVGs = false;
|
|
for (int i = 0; i < obFVGsCount; i++)
|
|
{
|
|
//
|
|
bool iHasUnActivatedOBs = mConditions.obFVGs[i].HasUnActivatedOBs();
|
|
bool iHasUnActivatedFVGs = mConditions.obFVGs[i].HasUnActivatedFVGs();
|
|
|
|
//
|
|
if (hasOBs)
|
|
{
|
|
//
|
|
for (int j = 0; j < obsCount; j++)
|
|
{
|
|
mConditions.obFVGs[i].AddUnActivatedOB(
|
|
obs[j],
|
|
decisionZBar //
|
|
);
|
|
}
|
|
|
|
//
|
|
iHasUnActivatedOBs = mConditions.obFVGs[i].HasUnActivatedOBs();
|
|
}
|
|
|
|
//
|
|
if (hasFVGs)
|
|
{
|
|
//
|
|
for (int j = 0; j < fvgsCount; j++)
|
|
{
|
|
mConditions.obFVGs[i].AddUnActivatedFVG(
|
|
fvgs[j],
|
|
decisionZBar //
|
|
);
|
|
}
|
|
|
|
//
|
|
iHasUnActivatedFVGs = mConditions.obFVGs[i].HasUnActivatedFVGs();
|
|
}
|
|
|
|
//
|
|
if (iHasUnActivatedOBs &&
|
|
!hasUnActivatedOBs)
|
|
{
|
|
hasUnActivatedOBs = iHasUnActivatedOBs;
|
|
}
|
|
|
|
//
|
|
if (iHasUnActivatedFVGs &&
|
|
!hasUnActivatedFVGs)
|
|
{
|
|
hasUnActivatedFVGs = iHasUnActivatedFVGs;
|
|
}
|
|
}
|
|
|
|
//
|
|
result =
|
|
(isPriceInsideSupplyZone ||
|
|
isPriceInsideDemandZone)
|
|
? true
|
|
: (hasUnActivatedOBs ||
|
|
hasUnActivatedFVGs);
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(obs);
|
|
Clean(fvgs);
|
|
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(visionCycleEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationPoiEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
visionState.Clean();
|
|
analyseState.Clean();
|
|
decisionZBar.Clean();
|
|
decisionCBar.Clean();
|
|
decisionPBar.Clean();
|
|
decisionState.Clean();
|
|
visionConditions.Clean();
|
|
analyseConditions.Clean();
|
|
visionXConditions.Clean();
|
|
consolidationState.Clean();
|
|
decisionConditions.Clean();
|
|
analyseXConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
consolidationXConditions.Clean();
|
|
|
|
//
|
|
RemoveDraws();
|
|
RemoveWorkingZoneDraws();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Now We Have to Wait for Price Inside Box ...
|
|
|
|
//
|
|
XOHCL swingBar;
|
|
XOHCL rejectBar;
|
|
XOHCL breakerBar;
|
|
XOHCL momentumBar;
|
|
bool isPriceRejected = false;
|
|
XCFVG *insideFVG = mConditions.insideFVG;
|
|
XCFVG *rejectedFVG = mConditions.rejectedFVG;
|
|
XCOrderBlock *insideOB = mConditions.insideOB;
|
|
XCOrderBlock *rejectedOB = mConditions.rejectedOB;
|
|
XCSupplyZone *insideSupplyZone = mConditions.insideSupplyZone;
|
|
XCDemandZone *insideDemandZone = mConditions.insideDemandZone;
|
|
|
|
//
|
|
bool hasInsideOB = insideOB != NULL &&
|
|
insideOB.IsValid();
|
|
bool hasInsideFVG = insideFVG != NULL &&
|
|
insideFVG.IsValid();
|
|
bool hasInsideZone = hasInsideOB ||
|
|
hasInsideFVG;
|
|
bool hasRejectedOB = rejectedOB != NULL &&
|
|
rejectedOB.IsValid();
|
|
bool hasRejectedFVG = rejectedFVG != NULL &&
|
|
rejectedFVG.IsValid();
|
|
bool hasRejectedZone = hasRejectedOB ||
|
|
hasRejectedFVG;
|
|
bool hasInsideSupplyZone = insideSupplyZone != NULL &&
|
|
insideSupplyZone.IsValid();
|
|
bool hasInsideDemandZone = insideDemandZone != NULL &&
|
|
insideDemandZone.IsValid();
|
|
bool hasInsideSupDemZone = hasInsideSupplyZone ||
|
|
hasInsideDemandZone;
|
|
if (!hasInsideZone)
|
|
{
|
|
//
|
|
for (int i = 0; i < obFVGsCount; i++)
|
|
{
|
|
//
|
|
bool iOBFVGHasUnActivatedOBs = mConditions.obFVGs[i].HasUnActivatedOBs();
|
|
int iOBFVGUnActivatedOBsCount = mConditions.obFVGs[i].CountUnActivatedOBs();
|
|
|
|
//
|
|
bool iOBFVGHasUnActivatedFVGs = mConditions.obFVGs[i].HasUnActivatedFVGs();
|
|
int iOBFVGUnActivatedFVGsCount = mConditions.obFVGs[i].CountUnActivatedFVGs();
|
|
|
|
//
|
|
// Detect Inside Zones ...
|
|
|
|
//
|
|
if (!hasInsideOB &&
|
|
iOBFVGHasUnActivatedOBs)
|
|
{
|
|
//
|
|
int idx = -1;
|
|
for (int j = 0; j < iOBFVGUnActivatedOBsCount; j++)
|
|
{
|
|
//
|
|
ENUM_X_DIRECTION iForDir = mConditions.obFVGs[i].unActivatedOBs[j].GetDirection();
|
|
bool isIBullish = IsBullish(iForDir);
|
|
|
|
//
|
|
bool isInsideFromUpper = IsInside(
|
|
decisionZBar.low,
|
|
mConditions.obFVGs[i].unActivatedOBs[j] //
|
|
);
|
|
bool isInsideFromLower = IsInside(
|
|
decisionZBar.high,
|
|
mConditions.obFVGs[i].unActivatedOBs[j] //
|
|
);
|
|
|
|
//
|
|
bool isInside =
|
|
isBullish
|
|
? isInsideFromUpper
|
|
: isInsideFromLower;
|
|
if (isInside)
|
|
{
|
|
//
|
|
idx = j;
|
|
insideOB = mConditions.obFVGs[i].unActivatedOBs[j];
|
|
mConditions.insideOB = insideOB;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
if (IsValidIndex(idx))
|
|
{
|
|
//
|
|
ArrayRemove(
|
|
mConditions.obFVGs[i].unActivatedOBs,
|
|
idx,
|
|
1 //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
if (insideOB == NULL &&
|
|
!hasInsideFVG &&
|
|
iOBFVGHasUnActivatedFVGs)
|
|
{
|
|
//
|
|
int idx = -1;
|
|
for (int j = 0; j < iOBFVGUnActivatedFVGsCount; j++)
|
|
{
|
|
//
|
|
ENUM_X_DIRECTION iForDir = mConditions.obFVGs[i].unActivatedFVGs[j].GetDirection();
|
|
bool isIBullish = IsBullish(iForDir);
|
|
|
|
//
|
|
bool isInsideFromUpper = IsInside(
|
|
decisionZBar.low,
|
|
mConditions.obFVGs[i].unActivatedFVGs[j] //
|
|
);
|
|
bool isInsideFromLower = IsInside(
|
|
decisionZBar.high,
|
|
mConditions.obFVGs[i].unActivatedFVGs[j] //
|
|
);
|
|
|
|
//
|
|
bool isInside =
|
|
isBullish
|
|
? isInsideFromUpper
|
|
: isInsideFromLower;
|
|
if (isInside)
|
|
{
|
|
//
|
|
idx = j;
|
|
insideFVG = mConditions.obFVGs[i].unActivatedFVGs[j];
|
|
mConditions.insideFVG = insideFVG;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
if (IsValidIndex(idx))
|
|
{
|
|
//
|
|
ArrayRemove(
|
|
mConditions.obFVGs[i].unActivatedFVGs,
|
|
idx,
|
|
1 //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
hasInsideOB = insideOB != NULL &&
|
|
insideOB.IsValid();
|
|
hasInsideFVG = insideFVG != NULL &&
|
|
insideFVG.IsValid();
|
|
hasInsideZone = hasInsideOB ||
|
|
hasInsideFVG;
|
|
|
|
//
|
|
// Here Detect Inside or Rejected Zones inside Supply and Demand Zones ...
|
|
// For Using them for Positions ...
|
|
if (!hasInsideZone &&
|
|
hasInsideSupDemZone)
|
|
{
|
|
//
|
|
ENUM_X_DIRECTION forDir =
|
|
hasInsideSupplyZone
|
|
? X_DIRECTION_BEARISH
|
|
: X_DIRECTION_BULLISH;
|
|
|
|
//
|
|
bool isLookingForBullish = IsBullish(forDir);
|
|
|
|
//
|
|
XCFVG *fvgs[];
|
|
XCOrderBlock *obs[];
|
|
int obsCount = 0;
|
|
int fvgsCount = 0;
|
|
bool hasOBs = false;
|
|
bool hasFVGs = false;
|
|
|
|
//
|
|
if (isLookingForBullish)
|
|
{
|
|
//
|
|
Copy(
|
|
analyseState.bullishOrderBlocks,
|
|
obs //
|
|
);
|
|
FilterZones(
|
|
insideDemandZone,
|
|
obs,
|
|
true, // Filter Direction ...
|
|
true, // Filter From ...
|
|
true, // Filter Price ...
|
|
true, // Ignore Out of Box ...
|
|
true, // Apply Sort ...
|
|
true // Ignore Inside ...
|
|
);
|
|
|
|
//
|
|
Copy(
|
|
analyseState.bullishFairValueGaps,
|
|
fvgs //
|
|
);
|
|
FilterZones(
|
|
insideDemandZone,
|
|
fvgs,
|
|
true, // Filter Direction ...
|
|
true, // Filter From ...
|
|
true, // Filter Price ...
|
|
true, // Ignore Out of Box ...
|
|
true, // Apply Sort ...
|
|
true // Ignore Inside ...
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
Copy(
|
|
analyseState.bearishOrderBlocks,
|
|
obs //
|
|
);
|
|
FilterZones(
|
|
insideSupplyZone,
|
|
obs,
|
|
true, // Filter Direction ...
|
|
true, // Filter From ...
|
|
true, // Filter Price ...
|
|
false, // Ignore Out of Box ...
|
|
true, // Apply Sort ...
|
|
true // Ignore Inside ...
|
|
);
|
|
|
|
//
|
|
Copy(
|
|
analyseState.bearishFairValueGaps,
|
|
fvgs //
|
|
);
|
|
FilterZones(
|
|
insideSupplyZone,
|
|
fvgs,
|
|
true, // Filter Direction ...
|
|
true, // Filter From ...
|
|
true, // Filter Price ...
|
|
false, // Ignore Out of Box ...
|
|
true, // Apply Sort ...
|
|
true // Ignore Inside ...
|
|
);
|
|
}
|
|
|
|
//
|
|
obsCount = ArraySize(obs);
|
|
fvgsCount = ArraySize(fvgs);
|
|
|
|
//
|
|
hasOBs = IsValidSize(obsCount);
|
|
hasFVGs = IsValidSize(fvgsCount);
|
|
|
|
//
|
|
if (hasOBs ||
|
|
hasFVGs)
|
|
{
|
|
//
|
|
if (hasOBs)
|
|
{
|
|
//
|
|
for (int i = 0; i < obsCount; i++)
|
|
{
|
|
//
|
|
ENUM_X_DIRECTION iForDir = obs[i].GetDirection();
|
|
bool isIBullish = IsBullish(iForDir);
|
|
|
|
//
|
|
isPriceRejected = false;
|
|
// IsReject(
|
|
// iForDir,
|
|
// decisionZBar,
|
|
// obs[i],
|
|
// decisionState,
|
|
// swingBar,
|
|
// rejectBar,
|
|
// breakerBar,
|
|
// momentumBar,
|
|
// false //
|
|
// );
|
|
if (isPriceRejected)
|
|
{
|
|
//
|
|
rejectedOB = obs[i];
|
|
mConditions.rejectedOB = rejectedOB;
|
|
}
|
|
|
|
//
|
|
bool isInsideFromUpper = IsInside(
|
|
decisionZBar.low,
|
|
obs[i] //
|
|
);
|
|
bool isInsideFromLower = IsInside(
|
|
decisionZBar.high,
|
|
obs[i] //
|
|
);
|
|
|
|
//
|
|
bool isInside =
|
|
isBullish
|
|
? isInsideFromUpper
|
|
: isInsideFromLower;
|
|
if (isInside)
|
|
{
|
|
//
|
|
insideOB = obs[i];
|
|
mConditions.insideOB = obs[i];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
hasInsideOB = insideOB != NULL &&
|
|
insideOB.IsValid();
|
|
//
|
|
hasRejectedOB = rejectedOB != NULL &&
|
|
rejectedOB.IsValid();
|
|
|
|
//
|
|
if (hasFVGs &&
|
|
!hasInsideOB &&
|
|
!hasRejectedOB)
|
|
{
|
|
//
|
|
for (int i = 0; i < fvgsCount; i++)
|
|
{
|
|
//
|
|
ENUM_X_DIRECTION iForDir = fvgs[i].GetDirection();
|
|
bool isIBullish = IsBullish(iForDir);
|
|
|
|
//
|
|
isPriceRejected = false;
|
|
// IsReject(
|
|
// iForDir,
|
|
// decisionZBar,
|
|
// fvgs[i],
|
|
// decisionState,
|
|
// swingBar,
|
|
// rejectBar,
|
|
// breakerBar,
|
|
// momentumBar,
|
|
// false //
|
|
// );
|
|
if (isPriceRejected)
|
|
{
|
|
//
|
|
rejectedFVG = fvgs[i];
|
|
mConditions.rejectedFVG = rejectedFVG;
|
|
}
|
|
|
|
//
|
|
bool isInsideFromUpper = IsInside(
|
|
decisionZBar.low,
|
|
fvgs[i] //
|
|
);
|
|
bool isInsideFromLower = IsInside(
|
|
decisionZBar.high,
|
|
fvgs[i] //
|
|
);
|
|
|
|
//
|
|
bool isInside =
|
|
isBullish
|
|
? isInsideFromUpper
|
|
: isInsideFromLower;
|
|
if (isInside)
|
|
{
|
|
//
|
|
insideFVG = fvgs[i];
|
|
mConditions.insideFVG = fvgs[i];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(obs);
|
|
Clean(fvgs);
|
|
}
|
|
|
|
//
|
|
mConditions.UpdateTo(cTime);
|
|
|
|
//
|
|
hasInsideOB = insideOB != NULL &&
|
|
insideOB.IsValid();
|
|
hasInsideFVG = insideFVG != NULL &&
|
|
insideFVG.IsValid();
|
|
hasInsideZone = hasInsideOB ||
|
|
hasInsideFVG;
|
|
|
|
//
|
|
hasRejectedOB = rejectedOB != NULL &&
|
|
rejectedOB.IsValid();
|
|
hasRejectedFVG = rejectedFVG != NULL &&
|
|
rejectedFVG.IsValid();
|
|
hasRejectedZone = hasRejectedOB ||
|
|
hasRejectedFVG;
|
|
|
|
//
|
|
if (hasInsideSupDemZone &&
|
|
(hasInsideZone ||
|
|
hasRejectedZone))
|
|
{
|
|
//
|
|
RemoveDraws();
|
|
RemoveWorkingZoneDraws();
|
|
|
|
//
|
|
// Set Target Based On Supply or Demand Zone ...
|
|
|
|
//
|
|
// Supply Zone ...
|
|
if (isPriceInsideSupplyZone)
|
|
{
|
|
target = mConditions.workingZone.quarter1;
|
|
}
|
|
|
|
//
|
|
// Demand Zone ...
|
|
if (isPriceInsideDemandZone)
|
|
{
|
|
target = mConditions.workingZone.quarter3;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
result = hasInsideZone ||
|
|
hasRejectedZone;
|
|
if (!result)
|
|
{
|
|
//
|
|
decisionZBar.Clean();
|
|
decisionCBar.Clean();
|
|
decisionPBar.Clean();
|
|
|
|
//
|
|
swingBar.Clean();
|
|
rejectBar.Clean();
|
|
breakerBar.Clean();
|
|
momentumBar.Clean();
|
|
|
|
//
|
|
Clean(obs);
|
|
Clean(fvgs);
|
|
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(visionCycleEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationPoiEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
visionState.Clean();
|
|
analyseState.Clean();
|
|
decisionState.Clean();
|
|
visionConditions.Clean();
|
|
analyseConditions.Clean();
|
|
visionXConditions.Clean();
|
|
consolidationState.Clean();
|
|
decisionConditions.Clean();
|
|
analyseXConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
consolidationXConditions.Clean();
|
|
|
|
//
|
|
ZeroMemory(insideOB);
|
|
ZeroMemory(insideFVG);
|
|
ZeroMemory(rejectedOB);
|
|
ZeroMemory(rejectedFVG);
|
|
ZeroMemory(insideSupplyZone);
|
|
ZeroMemory(insideDemandZone);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Waiting for Price Breakes Inside Zone ...
|
|
|
|
//
|
|
double upper = 0;
|
|
double lower = 0;
|
|
bool isInsideZoneDirectionBullish = false;
|
|
bool isInsideZoneDirectionBearish = false;
|
|
|
|
//
|
|
if (hasInsideOB)
|
|
{
|
|
//
|
|
upper = insideOB.Upper();
|
|
lower = insideOB.Lower();
|
|
|
|
//
|
|
isInsideZoneDirectionBullish = insideOB.IsBullish();
|
|
isInsideZoneDirectionBearish = insideOB.IsBearish();
|
|
}
|
|
else if (hasInsideFVG)
|
|
{
|
|
//
|
|
upper = insideFVG.Upper();
|
|
lower = insideFVG.Lower();
|
|
|
|
//
|
|
isInsideZoneDirectionBullish = insideFVG.IsBullish();
|
|
isInsideZoneDirectionBearish = insideFVG.IsBearish();
|
|
}
|
|
|
|
//
|
|
// Cleanup Unused Objects ...
|
|
//
|
|
decisionZBar.Clean();
|
|
decisionCBar.Clean();
|
|
decisionPBar.Clean();
|
|
|
|
//
|
|
ZeroMemory(insideOB);
|
|
ZeroMemory(insideFVG);
|
|
ZeroMemory(rejectedOB);
|
|
ZeroMemory(rejectedFVG);
|
|
ZeroMemory(insideSupplyZone);
|
|
ZeroMemory(insideDemandZone);
|
|
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(visionCycleEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationPoiEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
visionState.Clean();
|
|
analyseState.Clean();
|
|
decisionZBar.Clean();
|
|
decisionCBar.Clean();
|
|
decisionPBar.Clean();
|
|
decisionState.Clean();
|
|
visionConditions.Clean();
|
|
analyseConditions.Clean();
|
|
visionXConditions.Clean();
|
|
consolidationState.Clean();
|
|
decisionConditions.Clean();
|
|
analyseXConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
consolidationXConditions.Clean();
|
|
|
|
//
|
|
// Summarize Conditions ...
|
|
|
|
//
|
|
bool isCondition1Bullish =
|
|
//
|
|
hasBullishTrend &&
|
|
isInsideZoneDirectionBullish &&
|
|
bullishPriority != X121SMC_XSUPDEMOBS_PRIORITY_NONE
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCondition1Bearish =
|
|
//
|
|
hasBearishTrend &&
|
|
isInsideZoneDirectionBearish &&
|
|
bearishPriority != X121SMC_XSUPDEMOBS_PRIORITY_NONE
|
|
//
|
|
;
|
|
|
|
//
|
|
bool hasCondition1 = isCondition1Bullish ||
|
|
isCondition1Bearish;
|
|
if (hasCondition1)
|
|
{
|
|
//
|
|
ENUM_X_DIRECTION pzDir =
|
|
isCondition1Bullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
double point = GetEntry(
|
|
mConditions.symbol,
|
|
pzDir //
|
|
);
|
|
|
|
//
|
|
double longPivot = lower; // triggerXConditions.valesBuffer[1];
|
|
double shortPivot = upper; // triggerXConditions.peaksBuffer[1];
|
|
|
|
//
|
|
// Manipulate Conditions Point ...
|
|
|
|
//
|
|
mConditions.point =
|
|
isCondition1Bullish
|
|
? shortPivot
|
|
: longPivot;
|
|
|
|
//
|
|
// Manipulate Conditions Pivot ...
|
|
|
|
//
|
|
mConditions.pivot =
|
|
isCondition1Bullish
|
|
? longPivot
|
|
: shortPivot;
|
|
}
|
|
|
|
//
|
|
// Summarize Conditions ...
|
|
//
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
isCondition1Bullish
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
isCondition1Bearish
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double reward;
|
|
double amountPercent;
|
|
ENUM_X121SMC_XSUPDEMOBS_PRIORITY priority =
|
|
isBullish
|
|
? bullishPriority
|
|
: bearishPriority;
|
|
bool hasRewardAmount = CalculateRiskReward(
|
|
priority,
|
|
reward,
|
|
amountPercent //
|
|
);
|
|
result = hasRewardAmount;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mConditions.setupTime = cTime;
|
|
mConditions.dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
mConditions.reward = reward;
|
|
mConditions.target = target;
|
|
mConditions.priority = priority;
|
|
mConditions.amountPercent = amountPercent;
|
|
|
|
//
|
|
swingBar.Clean();
|
|
rejectBar.Clean();
|
|
breakerBar.Clean();
|
|
momentumBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Trigger Conditions ...
|
|
bool DetectSignalTrigger(
|
|
//
|
|
X121SMCStrategyXSupDemOBSSignalConditions &conditions,
|
|
//
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper,
|
|
//
|
|
int maxAllowedSetupAge = 60
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
visionCycleHelper != NULL &&
|
|
analyseCycleHelper != NULL &&
|
|
decisionCycleHelper != NULL &&
|
|
consolidationCycleHelper != NULL
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
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 = decisionCycleHelper.GetBar(
|
|
zBar,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = decisionCycleHelper.GetBar(
|
|
cBar,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL pBar;
|
|
result = decisionCycleHelper.GetBar(
|
|
pBar,
|
|
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 ...
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
// Cleanup ...
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
|
|
//
|
|
Clean(decisionPoiEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
decisionConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState decisionState = decisionConditions.state;
|
|
|
|
//
|
|
// Cycle X121Conditions ...
|
|
X121Conditions decisionXConditions = decisionConditions.x121Conditions;
|
|
|
|
//
|
|
// Trigger Conditions ...
|
|
|
|
//
|
|
double point = conditions.point;
|
|
bool isPointBreaked = IsBarBreak(
|
|
point,
|
|
setupDir,
|
|
cBar //
|
|
);
|
|
|
|
//
|
|
// Summary ...
|
|
|
|
//
|
|
isBullish =
|
|
//
|
|
isBullish &&
|
|
isPointBreaked
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
isBearish &&
|
|
isPointBreaked
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Cleanup Setup Conditions ...
|
|
int setupAge = conditions.GetSetupAge();
|
|
if (IsValidSize(setupAge) &&
|
|
IsValidSize(maxAllowedSetupAge) &&
|
|
setupAge >= maxAllowedSetupAge)
|
|
{
|
|
conditions.Clean();
|
|
}
|
|
|
|
//
|
|
// Cleanup ...
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
|
|
//
|
|
Clean(decisionPoiEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
decisionState.Clean();
|
|
decisionConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Nearest Pivot Point ...
|
|
|
|
//
|
|
double entry = GetEntry(
|
|
conditions.symbol,
|
|
setupDir //
|
|
);
|
|
|
|
//
|
|
// Manipulate SL Based on Consolidation Zones ...
|
|
XConsolidationZone cZone;
|
|
bool hasCZone = decisionCycleHelper.GetActiveConsolidationZone(cZone);
|
|
bool hasCZones = decisionCycleHelper.HasConsolidationZones();
|
|
int cZonesCount = decisionCycleHelper.CountConsolidationZones();
|
|
if (!hasCZone &&
|
|
hasCZones)
|
|
{
|
|
//
|
|
hasCZone = decisionCycleHelper.GetLastDirectionalConsolidationZone(
|
|
conditions.dir,
|
|
cZone //
|
|
);
|
|
}
|
|
|
|
//
|
|
double sls[];
|
|
Add(
|
|
conditions.pivot,
|
|
sls //
|
|
);
|
|
|
|
//
|
|
if (hasCZone)
|
|
{
|
|
//
|
|
conditions.consolidationZone = cZone;
|
|
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
Add(
|
|
cZone.lower,
|
|
sls //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
Add(
|
|
cZone.upper,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
double iAtr = decisionXConditions.atrBuffer[1];
|
|
iAtr *= 2;
|
|
|
|
//
|
|
double slsMin = GetMin(sls);
|
|
double slsMax = GetMax(sls);
|
|
|
|
//
|
|
double sl = isBullish
|
|
? slsMin - iAtr
|
|
: slsMax + iAtr;
|
|
double risk = MathAbs(entry - sl);
|
|
|
|
//
|
|
// Filling Conditions Props ...
|
|
conditions.sl = sl;
|
|
conditions.triggerTime = cTime;
|
|
conditions.type = isBullish
|
|
? X_POSITION_TYPE_LONG
|
|
: X_POSITION_TYPE_SHORT;
|
|
|
|
//
|
|
// Cleanup ...
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
|
|
//
|
|
Clean(decisionPoiEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
decisionState.Clean();
|
|
decisionConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Guards ...
|
|
bool DetectGuards(
|
|
//
|
|
X121SMCGuard &guards[],
|
|
const XPosition &positions[],
|
|
//
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
Clean(guards);
|
|
|
|
//
|
|
bool isCycleHelpersValid =
|
|
//
|
|
visionCycleHelper != NULL &&
|
|
analyseCycleHelper != NULL &&
|
|
decisionCycleHelper != NULL &&
|
|
consolidationCycleHelper != NULL
|
|
//
|
|
;
|
|
|
|
//
|
|
result = isCycleHelpersValid;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int count = ArraySize(positions);
|
|
result = IsValidSize(count);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
string symbol = decisionCycleHelper.GetSymbol();
|
|
ENUM_TIMEFRAMES period = decisionCycleHelper.GetPeriod();
|
|
string provider = ToString(X_121_SMC_PROVIDER_XSUPDEMOBS);
|
|
|
|
//
|
|
XPosition ownPositions[];
|
|
XPosition ownLongPositions[];
|
|
XPosition ownShortPositions[];
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XPosition iPosition = positions[i];
|
|
bool isOwn = iPosition
|
|
.IsFiltersPassed(
|
|
symbol,
|
|
provider,
|
|
NULL,
|
|
X_POSITION_TYPE_ALL,
|
|
iPosition.magic //
|
|
);
|
|
if (isOwn)
|
|
{
|
|
//
|
|
AddRef(
|
|
iPosition,
|
|
ownPositions //
|
|
);
|
|
|
|
//
|
|
bool isLong = IsLong(positions[i].type);
|
|
if (isLong)
|
|
{
|
|
//
|
|
AddRef(
|
|
iPosition,
|
|
ownLongPositions //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
AddRef(
|
|
iPosition,
|
|
ownShortPositions //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
count = ArraySize(ownPositions);
|
|
|
|
//
|
|
int longsCount = ArraySize(ownLongPositions);
|
|
bool hasLongs = IsValidSize(longsCount);
|
|
|
|
//
|
|
int shortsCount = ArraySize(ownShortPositions);
|
|
bool hasShorts = IsValidSize(shortsCount);
|
|
|
|
//
|
|
result = IsValidSize(count);
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(ownPositions);
|
|
Clean(ownLongPositions);
|
|
Clean(ownShortPositions);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Get Global and Common Guards ...
|
|
|
|
//
|
|
ENUM_X_121_SMC_GUARD_ACTIONS ignoreGuards[1] = {
|
|
X_121_SMC_GUARD_ACTION_TRAIL_STOP};
|
|
result = DetectX121SMCGuards(
|
|
provider,
|
|
guards,
|
|
positions,
|
|
decisionCycleHelper,
|
|
analyseCycleHelper,
|
|
consolidationCycleHelper,
|
|
visionCycleHelper,
|
|
//
|
|
ignoreGuards
|
|
//
|
|
);
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Get Custom Implemented Guards ...
|
|
|
|
//
|
|
// Here we Are Sure there is Positions to Guard ...
|
|
// based on Current Provider ...
|
|
|
|
//
|
|
// Detect Required Data for Analyse Market to Guard Positions ...
|
|
|
|
//
|
|
int zIndex = 0;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
int loopback = 10;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
result = HasChild(guards);
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
symbol,
|
|
period,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
result = HasChild(guards);
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL pBar;
|
|
result = pBar.Init(
|
|
symbol,
|
|
period,
|
|
pIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
result = HasChild(guards);
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL ppBar;
|
|
result = ppBar.Init(
|
|
symbol,
|
|
period,
|
|
ppIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
result = HasChild(guards);
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
double points = GetPoints(symbol);
|
|
|
|
//
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
ppBar.Clean();
|
|
result = HasChild(guards);
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
ppBar.Clean();
|
|
|
|
//
|
|
Clean(decisionPoiEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
decisionConditions.Clean();
|
|
|
|
//
|
|
result = HasChild(guards);
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
ppBar.Clean();
|
|
|
|
//
|
|
Clean(decisionPoiEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
decisionConditions.Clean();
|
|
|
|
//
|
|
Clean(analysePoiEvents);
|
|
Clean(analyseCycleEvents);
|
|
|
|
//
|
|
analyseConditions.Clean();
|
|
|
|
//
|
|
result = HasChild(guards);
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
ppBar.Clean();
|
|
|
|
//
|
|
Clean(decisionPoiEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
decisionConditions.Clean();
|
|
|
|
//
|
|
Clean(analysePoiEvents);
|
|
Clean(analyseCycleEvents);
|
|
|
|
//
|
|
analyseConditions.Clean();
|
|
|
|
//
|
|
Clean(consolidationPoiEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
consolidationConditions.Clean();
|
|
|
|
//
|
|
result = HasChild(guards);
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
XPOIState visionState = visionConditions.state;
|
|
|
|
//
|
|
// Cycle X121Conditions ...
|
|
X121Conditions decisionXConditions = decisionConditions.x121Conditions;
|
|
X121Conditions analyseXConditions = analyseConditions.x121Conditions;
|
|
X121Conditions consolidationXConditions = consolidationConditions.x121Conditions;
|
|
X121Conditions visionXConditions = visionConditions.x121Conditions;
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Detect Consolidation Zone ...
|
|
|
|
//
|
|
XBoxZone lastBullishBox;
|
|
XBoxZone prevLastBullishBox;
|
|
bool hasLastBullishBox = false;
|
|
bool hasPrevLastBullishBox = false;
|
|
XConsolidationZone lastBullishZone;
|
|
bool isLastBullishAbovePrev = false;
|
|
bool isLastBullishBelowPrev = false;
|
|
XConsolidationZone prevLastBullishZone;
|
|
|
|
//
|
|
XBoxZone lastBearishBox;
|
|
XBoxZone prevLastBearishBox;
|
|
bool hasLastBearishBox = false;
|
|
bool hasPrevLastBearishBox = false;
|
|
XConsolidationZone lastBearishZone;
|
|
bool isLastBearishAbovePrev = false;
|
|
bool isLastBearishBelowPrev = false;
|
|
XConsolidationZone prevLastBearishZone;
|
|
|
|
//
|
|
int bullishConsolidationZonesCount = 0;
|
|
int bearishConsolidationZonesCount = 0;
|
|
bool hasBullishConsolidationZones = false;
|
|
bool hasBearishConsolidationZones = false;
|
|
XConsolidationZone bullishConsolidationZones[];
|
|
XConsolidationZone bearishConsolidationZones[];
|
|
bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones();
|
|
int consolidationZonesCount = decisionCycleHelper.CountConsolidationZones();
|
|
if (hasConsolidationZones)
|
|
{
|
|
//
|
|
bullishConsolidationZonesCount = decisionCycleHelper
|
|
.FillConsolidationZones(
|
|
X_DIRECTION_BULLISH,
|
|
bullishConsolidationZones //
|
|
);
|
|
hasBullishConsolidationZones = IsValidSize(bullishConsolidationZonesCount);
|
|
|
|
//
|
|
bearishConsolidationZonesCount = decisionCycleHelper
|
|
.FillConsolidationZones(
|
|
X_DIRECTION_BEARISH,
|
|
bearishConsolidationZones //
|
|
);
|
|
hasBearishConsolidationZones = IsValidSize(bearishConsolidationZonesCount);
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
if (hasBullishConsolidationZones &&
|
|
bullishConsolidationZonesCount >= 2)
|
|
{
|
|
//
|
|
lastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 1];
|
|
prevLastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 2];
|
|
|
|
//
|
|
hasLastBullishBox = ToBox(
|
|
lastBullishBox,
|
|
lastBullishZone //
|
|
);
|
|
hasPrevLastBullishBox = ToBox(
|
|
prevLastBullishBox,
|
|
prevLastBullishZone //
|
|
);
|
|
|
|
//
|
|
isLastBullishAbovePrev = hasLastBullishBox &&
|
|
hasPrevLastBullishBox &&
|
|
IsBoxAbove(
|
|
lastBullishBox,
|
|
prevLastBullishBox //
|
|
);
|
|
|
|
//
|
|
isLastBullishBelowPrev = hasLastBullishBox &&
|
|
hasPrevLastBullishBox &&
|
|
IsBoxBelow(
|
|
lastBullishBox,
|
|
prevLastBullishBox //
|
|
);
|
|
}
|
|
|
|
//
|
|
if (hasBearishConsolidationZones &&
|
|
bearishConsolidationZonesCount >= 2)
|
|
{
|
|
//
|
|
lastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 1];
|
|
prevLastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 2];
|
|
|
|
//
|
|
hasLastBearishBox = ToBox(
|
|
lastBearishBox,
|
|
lastBearishZone //
|
|
);
|
|
hasPrevLastBearishBox = ToBox(
|
|
prevLastBearishBox,
|
|
prevLastBearishZone //
|
|
);
|
|
|
|
//
|
|
isLastBearishAbovePrev = hasLastBearishBox &&
|
|
hasPrevLastBearishBox &&
|
|
IsBoxAbove(
|
|
lastBearishBox,
|
|
prevLastBearishBox //
|
|
);
|
|
|
|
//
|
|
isLastBearishBelowPrev = hasLastBearishBox &&
|
|
hasPrevLastBearishBox &&
|
|
IsBoxBelow(
|
|
lastBearishBox,
|
|
prevLastBearishBox //
|
|
);
|
|
}
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
// Detect High Probability Swings ...
|
|
bool isSwingLow =
|
|
//
|
|
cBar.low > pBar.low &&
|
|
ppBar.low > pBar.low &&
|
|
//
|
|
zBar.low > pBar.low
|
|
//
|
|
;
|
|
bool isSwingHigh =
|
|
//
|
|
cBar.high < pBar.high &&
|
|
ppBar.high < pBar.high &&
|
|
//
|
|
zBar.high < pBar.high
|
|
//
|
|
;
|
|
bool isStrongSwingLow =
|
|
pBar.IsBullish() &&
|
|
pBar.GetLowShadow() >= pBar.GetBody() * 2;
|
|
bool isStrongSwingHigh =
|
|
pBar.IsBearish() &&
|
|
pBar.GetHighShadow() >= pBar.GetBody() * 2;
|
|
|
|
//
|
|
bool isStrongSwingLowAboveLastBullishBox =
|
|
isStrongSwingLow &&
|
|
hasLastBullishBox &&
|
|
pBar.low > lastBullishBox.upper;
|
|
|
|
//
|
|
bool isStrongSwingHighBelowLastBearishBox =
|
|
isStrongSwingHigh &&
|
|
hasLastBearishBox &&
|
|
pBar.high < lastBearishBox.lower;
|
|
|
|
//
|
|
// Here We Have all Requirements for Guarding Positions ...
|
|
|
|
//
|
|
// Available Guards:
|
|
// X_121_SMC_GUARD_ACTION_NONE
|
|
// X_121_SMC_GUARD_ACTION_CLOSE
|
|
// X_121_SMC_GUARD_ACTION_CLOSE_ALL
|
|
// X_121_SMC_GUARD_ACTION_CLOSE_LONGS
|
|
// X_121_SMC_GUARD_ACTION_CLOSE_SHORTS
|
|
// X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE
|
|
// X_121_SMC_GUARD_ACTION_TRAIL_STOP
|
|
// X_121_SMC_GUARD_ACTION_TRAIL_TARGET
|
|
// X_121_SMC_GUARD_ACTION_HEDGE
|
|
|
|
//
|
|
// X_121_SMC_GUARD_ACTION_CLOSE:
|
|
// Close Specified Position on Specified Conditions ...
|
|
|
|
//
|
|
// X_121_SMC_GUARD_ACTION_CLOSE_ALL:
|
|
// Close All Positions on Specified Conditions ...
|
|
|
|
//
|
|
// X_121_SMC_GUARD_ACTION_CLOSE_LONGS:
|
|
// Close All Long Positions on Specified Conditions ...
|
|
|
|
//
|
|
// X_121_SMC_GUARD_ACTION_CLOSE_SHORTS:
|
|
// Close All Short Positions on Specified Conditions ...
|
|
|
|
//
|
|
// X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE:
|
|
// Partial Close Specified Position on Specified Conditions ...
|
|
|
|
//
|
|
// X_121_SMC_GUARD_ACTION_TRAIL_STOP:
|
|
// Trail Stop Specified Position on Specified Conditions ...
|
|
|
|
//
|
|
// X_121_SMC_GUARD_ACTION_TRAIL_TARGET:
|
|
// Trail Target Specified Position on Specified Conditions ...
|
|
|
|
//
|
|
// X_121_SMC_GUARD_ACTION_HEDGE:
|
|
// Hedge all Positions on Specified Conditions ...
|
|
|
|
//
|
|
// Cleanup Collections ...
|
|
|
|
//
|
|
Clean(ownPositions);
|
|
Clean(ownLongPositions);
|
|
Clean(ownShortPositions);
|
|
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
ppBar.Clean();
|
|
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(visionCycleEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationPoiEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
visionState.Clean();
|
|
analyseState.Clean();
|
|
decisionState.Clean();
|
|
visionConditions.Clean();
|
|
analyseConditions.Clean();
|
|
visionXConditions.Clean();
|
|
decisionConditions.Clean();
|
|
consolidationState.Clean();
|
|
analyseXConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
consolidationXConditions.Clean();
|
|
|
|
//
|
|
lastBullishBox.Clean();
|
|
lastBearishBox.Clean();
|
|
lastBullishZone.Clean();
|
|
lastBearishZone.Clean();
|
|
prevLastBullishBox.Clean();
|
|
prevLastBearishBox.Clean();
|
|
prevLastBullishZone.Clean();
|
|
prevLastBearishZone.Clean();
|
|
|
|
//
|
|
count = ArraySize(guards);
|
|
result = IsValidSize(count);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Add Conditions to Conditions Collection ...
|
|
int AddConditionsIfNotExists(
|
|
int maxAllowed = 10 //
|
|
)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
bool isSetuped = IsValid(mConditions.setupTime) &&
|
|
HasDirection(mConditions.dir);
|
|
if (!isSetuped)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int count = ArraySize(mConditionsCollection);
|
|
if (IsValidSize(count))
|
|
{
|
|
//
|
|
// Copy Original Items ...
|
|
X121SMCStrategyXSupDemOBSSignalConditions tmpItems[];
|
|
Copy(
|
|
mConditionsCollection,
|
|
tmpItems //
|
|
);
|
|
|
|
//
|
|
// Prese Item Data ...
|
|
bool isBullish = IsBullish(mConditions.dir);
|
|
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
X121SMCStrategyXSupDemOBSSignalConditions iItem = tmpItems[i];
|
|
|
|
//
|
|
bool canRemove = mConditions.dir == iItem.dir &&
|
|
mConditions.pivot == iItem.pivot;
|
|
if (canRemove)
|
|
{
|
|
//
|
|
ArrayRemove(
|
|
mConditionsCollection,
|
|
i,
|
|
1 //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmpItems);
|
|
}
|
|
|
|
//
|
|
AddRef(
|
|
mConditions,
|
|
mConditionsCollection //
|
|
);
|
|
|
|
//
|
|
// Remove Olds ...
|
|
CleanupArray(
|
|
mConditionsCollection,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
result = ArraySize(mConditionsCollection);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Draw Functions ...
|
|
//
|
|
|
|
//
|
|
void RemoveDraws()
|
|
{
|
|
mObjects.Clear();
|
|
}
|
|
|
|
//
|
|
void RemoveWorkingZoneDraws()
|
|
{
|
|
mWorkingZoneObjects.Clear();
|
|
}
|
|
|
|
//
|
|
void DrawOrderBlock(
|
|
XCOrderBlock *ob,
|
|
XCPOIDrawer *drawer //
|
|
)
|
|
{
|
|
//
|
|
if (ob == NULL ||
|
|
drawer == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
ENUM_X_DIRECTION forDir = ob.GetDirection();
|
|
|
|
//
|
|
color bullishColor = drawer.BarBullishColor();
|
|
color bearishColor = drawer.BarBearishColor();
|
|
color forColor = IsBullish(forDir)
|
|
? bullishColor
|
|
: bearishColor;
|
|
|
|
//
|
|
// Draw Order Block ...
|
|
XCBaseObject *obj;
|
|
bool isCreated = drawer.CreateOrderBlock(
|
|
ob,
|
|
obj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
mObjects.Add(obj);
|
|
}
|
|
|
|
//
|
|
ulong chartID = drawer.ChartIdentification();
|
|
int subWindow = drawer.SubWindowIdentification();
|
|
|
|
//
|
|
XOHCL startedBar;
|
|
ENUM_X_DIRECTION startedDir;
|
|
bool isStarted = ob.IsStarted(
|
|
forDir,
|
|
startedBar,
|
|
startedDir //
|
|
);
|
|
if (isStarted)
|
|
{
|
|
//
|
|
datetime to = startedBar.time + (PeriodSeconds(startedBar.period));
|
|
|
|
//
|
|
XCOHCLObject *obj;
|
|
bool isCreated = drawer.CreateBar(
|
|
startedBar,
|
|
obj,
|
|
to //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
obj.BodyColor(clrYellow);
|
|
obj.HighShadowColor(clrYellow);
|
|
obj.LowShadowColor(clrYellow);
|
|
|
|
//
|
|
obj.BodyStyle(STYLE_SOLID);
|
|
obj.HighShadowStyle(STYLE_SOLID);
|
|
obj.LowShadowStyle(STYLE_SOLID);
|
|
|
|
//
|
|
mObjects.Add(obj);
|
|
}
|
|
|
|
//
|
|
string startVLineName = "Start_" + ob.GetTag();
|
|
|
|
//
|
|
CChartObjectVLine *startVLine;
|
|
startVLine = new CChartObjectVLine();
|
|
isCreated = startVLine.Create(
|
|
chartID,
|
|
startVLineName,
|
|
subWindow,
|
|
startedBar.time //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
startVLine.Color(forColor);
|
|
|
|
//
|
|
mObjects.Add(startVLine);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
void DrawFairValueGap(
|
|
XCFVG *fvg,
|
|
XCPOIDrawer *drawer //
|
|
)
|
|
{
|
|
//
|
|
if (fvg == NULL ||
|
|
drawer == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
ENUM_X_DIRECTION forDir = fvg.GetDirection();
|
|
|
|
//
|
|
color bullishColor = drawer.BarBullishColor();
|
|
color bearishColor = drawer.BarBearishColor();
|
|
color forColor = IsBullish(forDir)
|
|
? bullishColor
|
|
: bearishColor;
|
|
|
|
//
|
|
// Draw Order Block ...
|
|
XCBaseObject *obj;
|
|
bool isCreated = drawer.CreateFairValueGap(
|
|
fvg,
|
|
obj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
mObjects.Add(obj);
|
|
}
|
|
|
|
//
|
|
ulong chartID = drawer.ChartIdentification();
|
|
int subWindow = drawer.SubWindowIdentification();
|
|
|
|
//
|
|
XOHCL startedBar;
|
|
ENUM_X_DIRECTION startedDir;
|
|
bool isStarted = fvg.IsStarted(
|
|
forDir,
|
|
startedBar,
|
|
startedDir //
|
|
);
|
|
if (isStarted)
|
|
{
|
|
//
|
|
datetime to = startedBar.time + (PeriodSeconds(startedBar.period));
|
|
|
|
//
|
|
XCOHCLObject *obj;
|
|
bool isCreated = drawer.CreateBar(
|
|
startedBar,
|
|
obj,
|
|
to //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
obj.BodyColor(clrYellow);
|
|
obj.HighShadowColor(clrYellow);
|
|
obj.LowShadowColor(clrYellow);
|
|
|
|
//
|
|
obj.BodyStyle(STYLE_SOLID);
|
|
obj.HighShadowStyle(STYLE_SOLID);
|
|
obj.LowShadowStyle(STYLE_SOLID);
|
|
|
|
//
|
|
mObjects.Add(obj);
|
|
}
|
|
|
|
//
|
|
string startVLineName = "Start_" + fvg.GetTag();
|
|
|
|
//
|
|
CChartObjectVLine *startVLine;
|
|
startVLine = new CChartObjectVLine();
|
|
isCreated = startVLine.Create(
|
|
chartID,
|
|
startVLineName,
|
|
subWindow,
|
|
startedBar.time //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
startVLine.Color(forColor);
|
|
|
|
//
|
|
mObjects.Add(startVLine);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
void DrawWorkingZone(
|
|
X121SMCStrategyXSupDemOBSSignalConditions &conditions,
|
|
XCPOIDrawer *drawer //
|
|
)
|
|
{
|
|
//
|
|
if (drawer == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
bool isCreated = false;
|
|
|
|
//
|
|
bool hasVisionHighestSupplyZone = conditions.HasVisionHighestSupplyZone();
|
|
if (hasVisionHighestSupplyZone)
|
|
{
|
|
//
|
|
XCSupplyZoneObject *ivhSupObj;
|
|
isCreated = drawer.CreateSupplyZone(
|
|
conditions.visionHighestSupplyZone,
|
|
ivhSupObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(ivhSupObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasConsolidationHighestSupplyZone = conditions.HasConsolidationHighestSupplyZone();
|
|
if (hasConsolidationHighestSupplyZone)
|
|
{
|
|
//
|
|
XCSupplyZoneObject *ichSupObj;
|
|
isCreated = drawer.CreateSupplyZone(
|
|
conditions.consolidationHighestSupplyZone,
|
|
ichSupObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(ichSupObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasVisionLowestDemandZone = conditions.HasVisionLowestDemandZone();
|
|
if (hasVisionLowestDemandZone)
|
|
{
|
|
//
|
|
XCDemandZoneObject *ivlSupObj;
|
|
isCreated = drawer.CreateDemandZone(
|
|
conditions.visionLowestDemandZone,
|
|
ivlSupObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(ivlSupObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasConsolidationLowestDemandZone = conditions.HasConsolidationLowestDemandZone();
|
|
if (hasConsolidationLowestDemandZone)
|
|
{
|
|
//
|
|
XCDemandZoneObject *iclSupObj;
|
|
isCreated = drawer.CreateDemandZone(
|
|
conditions.consolidationLowestDemandZone,
|
|
iclSupObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iclSupObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasWorkingZone = conditions.workingZone.IsValid();
|
|
if (hasWorkingZone)
|
|
{
|
|
//
|
|
string zonePrefix = "X121_WZ_" + conditions.workingZone.symbol + "_" + ToString(conditions.workingZone.period);
|
|
string fromStr = ToFormatString(conditions.workingZone.from);
|
|
string fromMD5 = ToMD5(fromStr);
|
|
|
|
//
|
|
string upperName = zonePrefix + "_Upper_" + fromMD5;
|
|
string lowerName = zonePrefix + "_Lower_" + fromMD5;
|
|
string zoneUpperName = zonePrefix + "_ZoneUpper_" + fromMD5;
|
|
string zoneLowerName = zonePrefix + "_ZoneLower_" + fromMD5;
|
|
|
|
//
|
|
string q1Name = zonePrefix + "_Q1_" + fromMD5;
|
|
string q2Name = zonePrefix + "_Q2_" + fromMD5;
|
|
string q3Name = zonePrefix + "_Q3_" + fromMD5;
|
|
|
|
//
|
|
ulong chartID = drawer.ChartIdentification();
|
|
int subWindow = drawer.SubWindowIdentification();
|
|
|
|
//
|
|
bool isCreated = false;
|
|
|
|
//
|
|
// Lower ...
|
|
CChartObjectHLine *lowerHLine;
|
|
lowerHLine = new CChartObjectHLine();
|
|
isCreated = lowerHLine.Create(
|
|
chartID,
|
|
lowerName,
|
|
subWindow,
|
|
conditions.workingZone.lower //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
lowerHLine.Color(clrLime);
|
|
mWorkingZoneObjects.Add(lowerHLine);
|
|
}
|
|
|
|
//
|
|
CChartObjectHLine *upperHLine;
|
|
upperHLine = new CChartObjectHLine();
|
|
isCreated = upperHLine.Create(
|
|
chartID,
|
|
upperName,
|
|
subWindow,
|
|
conditions.workingZone.upper //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
upperHLine.Color(clrLime);
|
|
mWorkingZoneObjects.Add(upperHLine);
|
|
}
|
|
|
|
//
|
|
CChartObjectHLine *zoneLowerHLine;
|
|
zoneLowerHLine = new CChartObjectHLine();
|
|
isCreated = zoneLowerHLine.Create(
|
|
chartID,
|
|
zoneLowerName,
|
|
subWindow,
|
|
conditions.workingZone.zoneLower //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
zoneLowerHLine.Color(clrRed);
|
|
mWorkingZoneObjects.Add(zoneLowerHLine);
|
|
}
|
|
|
|
//
|
|
CChartObjectHLine *zoneUpperHLine;
|
|
zoneUpperHLine = new CChartObjectHLine();
|
|
isCreated = zoneUpperHLine.Create(
|
|
chartID,
|
|
zoneUpperName,
|
|
subWindow,
|
|
conditions.workingZone.zoneUpper //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
zoneUpperHLine.Color(clrRed);
|
|
mWorkingZoneObjects.Add(zoneUpperHLine);
|
|
}
|
|
|
|
//
|
|
CChartObjectHLine *quarter1HLine;
|
|
quarter1HLine = new CChartObjectHLine();
|
|
isCreated = quarter1HLine.Create(
|
|
chartID,
|
|
q1Name,
|
|
subWindow,
|
|
conditions.workingZone.quarter1 //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
quarter1HLine.Color(clrYellow);
|
|
mWorkingZoneObjects.Add(quarter1HLine);
|
|
}
|
|
|
|
//
|
|
CChartObjectHLine *quarter2HLine;
|
|
quarter2HLine = new CChartObjectHLine();
|
|
isCreated = quarter2HLine.Create(
|
|
chartID,
|
|
q2Name,
|
|
subWindow,
|
|
conditions.workingZone.quarter2 //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
quarter2HLine.Color(clrYellow);
|
|
mWorkingZoneObjects.Add(quarter2HLine);
|
|
}
|
|
|
|
//
|
|
CChartObjectHLine *quarter3HLine;
|
|
quarter3HLine = new CChartObjectHLine();
|
|
isCreated = quarter3HLine.Create(
|
|
chartID,
|
|
q3Name,
|
|
subWindow,
|
|
conditions.workingZone.quarter3 //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
quarter3HLine.Color(clrYellow);
|
|
mWorkingZoneObjects.Add(quarter3HLine);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
void DrawConditions(
|
|
X121SMCStrategyXSupDemOBSSignalConditions &conditions,
|
|
XCPOIDrawer *drawer,
|
|
bool forceClean = false //
|
|
)
|
|
{
|
|
//
|
|
if (drawer == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
if (forceClean)
|
|
{
|
|
mObjects.Clear();
|
|
}
|
|
|
|
//
|
|
bool isCreated = false;
|
|
|
|
//
|
|
int obFVGsCount = ArraySize(conditions.obFVGs);
|
|
bool hasOBFVGs = IsValidSize(obFVGsCount);
|
|
if (hasOBFVGs)
|
|
{
|
|
//
|
|
for (int i = 0; i < obFVGsCount; i++)
|
|
{
|
|
//
|
|
XOBFVG iOBFVG = conditions.obFVGs[i];
|
|
|
|
//
|
|
DrawOrderBlock(
|
|
iOBFVG.ob,
|
|
drawer //
|
|
);
|
|
|
|
//
|
|
DrawFairValueGap(
|
|
iOBFVG.fvg,
|
|
drawer //
|
|
);
|
|
|
|
//
|
|
int hasUnActivatedOBs = iOBFVG.HasUnActivatedOBs();
|
|
int unActivatedOBsCount = iOBFVG.CountUnActivatedOBs();
|
|
if (hasUnActivatedOBs)
|
|
{
|
|
//
|
|
for (int j = 0; j < unActivatedOBsCount; j++)
|
|
{
|
|
//
|
|
DrawOrderBlock(
|
|
iOBFVG.unActivatedOBs[j],
|
|
drawer //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
int hasUnActivatedFVGs = iOBFVG.HasUnActivatedFVGs();
|
|
int unActivatedFVGsCount = iOBFVG.CountUnActivatedFVGs();
|
|
if (hasUnActivatedFVGs)
|
|
{
|
|
//
|
|
for (int j = 0; j < unActivatedFVGsCount; j++)
|
|
{
|
|
//
|
|
DrawFairValueGap(
|
|
iOBFVG.unActivatedFVGs[j],
|
|
drawer //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
int insideZoneWidth = 1;
|
|
color insideZoneColor = clrYellow;
|
|
bool hasInsideOB = conditions.insideOB != NULL &&
|
|
conditions.insideOB.IsValid();
|
|
if (hasInsideOB)
|
|
{
|
|
//
|
|
bool isBullish = conditions.insideOB.IsBullish();
|
|
|
|
//
|
|
XCBaseObject *iObj = NULL;
|
|
isCreated = false;
|
|
if (isBullish)
|
|
{
|
|
//
|
|
XCBullishOrderBlockObject *iiObj;
|
|
isCreated = drawer.CreateBullishOrderBlock(
|
|
conditions.insideOB,
|
|
iiObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
//
|
|
iiObj.ZoneColor(insideZoneColor);
|
|
iiObj.ZoneWidth(insideZoneWidth);
|
|
|
|
//
|
|
iObj = (XCBaseObject *)iiObj;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
XCBearishOrderBlockObject *iiObj;
|
|
isCreated = drawer.CreateBearishOrderBlock(
|
|
conditions.insideOB,
|
|
iiObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
//
|
|
iiObj.ZoneColor(insideZoneColor);
|
|
iiObj.ZoneWidth(insideZoneWidth);
|
|
|
|
//
|
|
iObj = (XCBaseObject *)iiObj;
|
|
}
|
|
}
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mObjects.Add(iObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasInsideFVG = conditions.insideFVG != NULL &&
|
|
conditions.insideFVG.IsValid();
|
|
if (hasInsideFVG)
|
|
{
|
|
//
|
|
bool isBullish = conditions.insideFVG.IsBullish();
|
|
|
|
//
|
|
XCBaseObject *iObj = NULL;
|
|
isCreated = false;
|
|
if (isBullish)
|
|
{
|
|
//
|
|
XCBullishFairValueGapObject *iiObj;
|
|
isCreated = drawer.CreateBullishFairValueGap(
|
|
conditions.insideFVG,
|
|
iiObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
//
|
|
iiObj.ZoneColor(insideZoneColor);
|
|
iiObj.ZoneWidth(insideZoneWidth);
|
|
|
|
//
|
|
iObj = (XCBaseObject *)iiObj;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
XCBearishFairValueGapObject *iiObj;
|
|
isCreated = drawer.CreateBearishFairValueGap(
|
|
conditions.insideFVG,
|
|
iiObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
//
|
|
iiObj.ZoneColor(insideZoneColor);
|
|
iiObj.ZoneWidth(insideZoneWidth);
|
|
|
|
//
|
|
iObj = (XCBaseObject *)iiObj;
|
|
}
|
|
}
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mObjects.Add(iObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasConsolidationZone = conditions.consolidationZone.IsValid();
|
|
if (hasConsolidationZone)
|
|
{
|
|
//
|
|
XCConsolidationZoneObject *iObj;
|
|
isCreated = drawer.CreateConsolidationZone(
|
|
conditions.consolidationZone,
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mObjects.Add(iObj);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
protected:
|
|
//
|
|
|
|
//
|
|
private:
|
|
//
|
|
// Props ...
|
|
CArrayObj mObjects;
|
|
CArrayObj mWorkingZoneObjects;
|
|
|
|
/**
|
|
* Initialize ...
|
|
*/
|
|
void Init()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* DeInitialize ...
|
|
*/
|
|
void DeInit()
|
|
{
|
|
//
|
|
RemoveDraws();
|
|
mConditions.Clean();
|
|
RemoveWorkingZoneDraws();
|
|
Clean(mConditionsCollection);
|
|
}
|
|
|
|
//
|
|
// Helpers ...
|
|
|
|
//
|
|
bool CheckPriceInside(
|
|
XOHCL &zBar,
|
|
XOHCL &cBar,
|
|
double upper,
|
|
double lower //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = zBar.IsValid() &&
|
|
cBar.IsValid() &&
|
|
upper > 0 &&
|
|
lower > 0 &&
|
|
upper > lower &&
|
|
zBar.time > cBar.time;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
zBar.high < upper &&
|
|
cBar.high < upper &&
|
|
//
|
|
zBar.low > lower &&
|
|
cBar.low > lower
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool CalculateRiskReward(
|
|
ENUM_X121SMC_XSUPDEMOBS_PRIORITY priority,
|
|
double &reward,
|
|
double &amountPercent //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
reward = 0;
|
|
amountPercent = 0;
|
|
|
|
//
|
|
result = priority != X121SMC_XSUPDEMOBS_PRIORITY_NONE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
switch (priority)
|
|
{
|
|
//
|
|
case X121SMC_XSUPDEMOBS_PRIORITY_HIGH:
|
|
//
|
|
reward = 6;
|
|
amountPercent = 2;
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XSUPDEMOBS_PRIORITY_REGULAR:
|
|
//
|
|
reward = 6;
|
|
amountPercent = 1.5;
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XSUPDEMOBS_PRIORITY_LOW:
|
|
//
|
|
reward = 4;
|
|
amountPercent = 1;
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XSUPDEMOBS_PRIORITY_WEAK:
|
|
//
|
|
reward = 2;
|
|
amountPercent = 0.5;
|
|
break;
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
reward > 0 &&
|
|
amountPercent > 0
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
// |