2725 lines
72 KiB
Plaintext
2725 lines
72 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 X121 SMC Signal Class
|
|
// -------------------------------------------------
|
|
// Name: XWZ
|
|
// Description: provide all Signalling functions ...
|
|
//
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////
|
|
//
|
|
// Global Properties ...
|
|
#property library
|
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
#property link "https://www.saherelm.ir"
|
|
#property version "1.00"
|
|
#property strict
|
|
|
|
//
|
|
// Imports ...
|
|
#include "../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.xwz.signal.lib.mq5"
|
|
|
|
//
|
|
// Definition ...
|
|
class XCX121SMCXWZSignalDetector : public XCBase
|
|
{
|
|
//
|
|
public:
|
|
//
|
|
// Props ...
|
|
X121SMCStrategyXWZSignalConditions mConditions;
|
|
X121SMCStrategyXWZSignalConditions mConditionsCollection[];
|
|
|
|
//
|
|
// Constructor(s) ...
|
|
XCX121SMCXWZSignalDetector()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
~XCX121SMCXWZSignalDetector()
|
|
{
|
|
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)
|
|
{
|
|
//
|
|
mConditions.Clean();
|
|
|
|
//
|
|
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)
|
|
{
|
|
//
|
|
mConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Analyse ...
|
|
ENUM_XPOI_EVENTS analysePoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
|
X121SMCCycleConditions analyseConditions;
|
|
result = analyseCycleHelper.GetConditions(
|
|
analyseCycleEvents,
|
|
analysePoiEvents,
|
|
analyseConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
mConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Consolidation ...
|
|
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
|
X121SMCCycleConditions consolidationConditions;
|
|
result = consolidationCycleHelper.GetConditions(
|
|
consolidationCycleEvents,
|
|
consolidationPoiEvents,
|
|
consolidationConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
mConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Vision ...
|
|
ENUM_XPOI_EVENTS visionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
|
X121SMCCycleConditions visionConditions;
|
|
result = visionCycleHelper.GetConditions(
|
|
visionCycleEvents,
|
|
visionPoiEvents,
|
|
visionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
mConditions.Clean();
|
|
|
|
//
|
|
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 ...
|
|
|
|
//
|
|
// Check Working Zone ...
|
|
bool hasWorkingZone = mConditions.HasWorkingZone();
|
|
if (!hasWorkingZone)
|
|
{
|
|
//
|
|
hasWorkingZone = mConditions.ExtractWorkingZone(
|
|
visionState,
|
|
consolidationState,
|
|
analyseState,
|
|
zIndex //
|
|
);
|
|
}
|
|
|
|
//
|
|
result = hasWorkingZone;
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(visionCycleEvents);
|
|
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();
|
|
|
|
//
|
|
mConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mConditions.UpdateTo(cTime);
|
|
|
|
//
|
|
// Check Working Zone still Alive ...
|
|
ENUM_X_DIRECTION destroyedDir = X_DIRECTION_NONE;
|
|
bool isWorkingZoneDestroyed = mConditions
|
|
.IsWorkingZoneDestroyed(
|
|
destroyedDir,
|
|
zIndex,
|
|
decisionState.period //
|
|
);
|
|
if (isWorkingZoneDestroyed)
|
|
{
|
|
RemoveWorkingZoneDraws();
|
|
}
|
|
|
|
//
|
|
result = !isWorkingZoneDestroyed;
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(visionCycleEvents);
|
|
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();
|
|
|
|
//
|
|
mConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detecting Trend ...
|
|
ENUM_X_DIRECTION trend;
|
|
bool hasTrend = mConditions.DetectTrend(
|
|
trend,
|
|
period //
|
|
);
|
|
bool hasBullishTrend = hasTrend &&
|
|
IsBullish(trend);
|
|
bool hasBearishTrend = hasTrend &&
|
|
IsBearish(trend);
|
|
result = hasTrend;
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(visionCycleEvents);
|
|
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();
|
|
|
|
//
|
|
mConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// bool hasStartZone = mConditions.DetectStartZones(
|
|
// trend,
|
|
// consolidationState,
|
|
// analyseState,
|
|
// decisionState,
|
|
// decisionCycleHelper //
|
|
// );
|
|
|
|
//
|
|
mConditions.UpdateTo(cTime);
|
|
|
|
//
|
|
// Detect Condition Priority ...
|
|
ENUM_X121SMC_XWZ_PRIORITY bullishPriority;
|
|
ENUM_X121SMC_XWZ_PRIORITY bearishPriority;
|
|
mConditions.DetectPriority(
|
|
bullishPriority,
|
|
bearishPriority //
|
|
);
|
|
|
|
//
|
|
bool canLookupLong = bullishPriority != X121SMC_XWZ_PRIORITY_NONE &&
|
|
bullishPriority != X121SMC_XWZ_PRIORITY_WEAK;
|
|
bool canLookupShort = bearishPriority != X121SMC_XWZ_PRIORITY_NONE &&
|
|
bearishPriority != X121SMC_XWZ_PRIORITY_WEAK;
|
|
bool isPriorityPassed =
|
|
hasBullishTrend
|
|
? canLookupLong
|
|
: hasBearishTrend
|
|
? canLookupShort
|
|
: false;
|
|
|
|
//
|
|
// Here we are Make sure we have Correct:
|
|
// - WorkSpace ...
|
|
// - Trend ...
|
|
// - What we looking for: Long or Short ...
|
|
// - Priority ...
|
|
|
|
//
|
|
double pivot = 0;
|
|
double point = 0;
|
|
ENUM_X_DIRECTION conditionsDir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
// Detect Start Zone Conditions ...
|
|
bool hasConditions = mConditions
|
|
.HasConditions(
|
|
pivot,
|
|
point,
|
|
conditionsDir,
|
|
decisionState,
|
|
zIndex,
|
|
decisionState.period //
|
|
);
|
|
result = hasConditions;
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(visionCycleEvents);
|
|
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();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
isBullish = IsBullish(conditionsDir);
|
|
isBearish = IsBearish(conditionsDir);
|
|
|
|
//
|
|
double reward;
|
|
double amountPercent;
|
|
ENUM_X121SMC_XWZ_PRIORITY priority =
|
|
isBullish
|
|
? bullishPriority
|
|
: bearishPriority;
|
|
bool hasRewardAmount = CalculateRiskReward(
|
|
priority,
|
|
reward,
|
|
amountPercent //
|
|
);
|
|
|
|
//
|
|
// Apply Traget ...
|
|
switch (priority)
|
|
{
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_STRONG_HIGH:
|
|
//
|
|
target =
|
|
isBullish
|
|
? mConditions.workingZone.quarter3
|
|
: mConditions.workingZone.quarter1;
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_HIGH:
|
|
//
|
|
target =
|
|
isBullish
|
|
? mConditions.workingZone.quarter3
|
|
: mConditions.workingZone.quarter1;
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_REGULAR:
|
|
//
|
|
target =
|
|
isBullish
|
|
? mConditions.workingZone.quarter2
|
|
: mConditions.workingZone.quarter2;
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_LOW:
|
|
//
|
|
target =
|
|
isBullish
|
|
? mConditions.workingZone.quarter1
|
|
: mConditions.workingZone.quarter3;
|
|
break;
|
|
|
|
//
|
|
default:
|
|
target = 0;
|
|
break;
|
|
}
|
|
|
|
//
|
|
bool hasLastBullishConsolidationZone = false;
|
|
bool hasLastBearishConsolidationZone = false;
|
|
bool hasPrevBullishConsolidationZone = false;
|
|
bool hasPrevBearishConsolidationZone = false;
|
|
XConsolidationZone lastBullishConsolidationZone;
|
|
XConsolidationZone lastBearishConsolidationZone;
|
|
XConsolidationZone prevBullishConsolidationZone;
|
|
XConsolidationZone prevBearishConsolidationZone;
|
|
bool isLastBullishConsolidationZoneInsidePivot = false;
|
|
bool isPrevBullishConsolidationZoneInsidePivot = false;
|
|
bool isLastBearishConsolidationZoneInsidePivot = false;
|
|
bool isPrevBearishConsolidationZoneInsidePivot = false;
|
|
bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones();
|
|
if (hasConsolidationZones)
|
|
{
|
|
//
|
|
int cZCount = 0;
|
|
XConsolidationZone tmp[];
|
|
|
|
//
|
|
cZCount = decisionCycleHelper
|
|
.FillConsolidationZones(
|
|
X_DIRECTION_BULLISH,
|
|
tmp //
|
|
);
|
|
if (IsValidSize(cZCount))
|
|
{
|
|
//
|
|
lastBullishConsolidationZone = tmp[cZCount - 1];
|
|
if (cZCount >= 2)
|
|
{
|
|
prevBullishConsolidationZone = tmp[cZCount - 2];
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmp);
|
|
cZCount = decisionCycleHelper
|
|
.FillConsolidationZones(
|
|
X_DIRECTION_BEARISH,
|
|
tmp //
|
|
);
|
|
if (IsValidSize(cZCount))
|
|
{
|
|
//
|
|
lastBearishConsolidationZone = tmp[cZCount - 1];
|
|
if (cZCount >= 2)
|
|
{
|
|
prevBearishConsolidationZone = tmp[cZCount - 2];
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmp);
|
|
|
|
//
|
|
hasLastBullishConsolidationZone = lastBullishConsolidationZone.IsValid();
|
|
hasLastBearishConsolidationZone = lastBearishConsolidationZone.IsValid();
|
|
hasPrevBullishConsolidationZone = prevBullishConsolidationZone.IsValid();
|
|
hasPrevBearishConsolidationZone = prevBearishConsolidationZone.IsValid();
|
|
|
|
//
|
|
isLastBullishConsolidationZoneInsidePivot =
|
|
//
|
|
hasLastBullishConsolidationZone &&
|
|
(lastBullishConsolidationZone.lower < point &&
|
|
lastBullishConsolidationZone.upper > pivot)
|
|
//
|
|
;
|
|
isPrevBullishConsolidationZoneInsidePivot =
|
|
//
|
|
hasPrevBullishConsolidationZone &&
|
|
(prevBullishConsolidationZone.lower < point &&
|
|
prevBullishConsolidationZone.upper > pivot)
|
|
//
|
|
;
|
|
|
|
//
|
|
isLastBearishConsolidationZoneInsidePivot =
|
|
//
|
|
hasLastBearishConsolidationZone &&
|
|
(lastBearishConsolidationZone.upper > point &&
|
|
lastBearishConsolidationZone.lower < pivot)
|
|
//
|
|
;
|
|
isPrevBearishConsolidationZoneInsidePivot =
|
|
//
|
|
hasPrevBearishConsolidationZone &&
|
|
(prevBearishConsolidationZone.upper > point &&
|
|
prevBearishConsolidationZone.lower < pivot)
|
|
//
|
|
;
|
|
}
|
|
|
|
//
|
|
bool isConsolidationZonePassed =
|
|
isBullish
|
|
//
|
|
? (point > 0 &&
|
|
pivot > 0 &&
|
|
pivot < point &&
|
|
hasPrevBullishConsolidationZone &&
|
|
point > prevBullishConsolidationZone.upper &&
|
|
(isLastBullishConsolidationZoneInsidePivot ||
|
|
isPrevBullishConsolidationZoneInsidePivot))
|
|
: (point > 0 &&
|
|
pivot > 0 &&
|
|
pivot > point &&
|
|
hasPrevBearishConsolidationZone &&
|
|
point < prevBearishConsolidationZone.lower &&
|
|
(isLastBearishConsolidationZoneInsidePivot ||
|
|
isPrevBearishConsolidationZoneInsidePivot))
|
|
//
|
|
;
|
|
|
|
//
|
|
result = hasConditions &&
|
|
hasRewardAmount &&
|
|
isPriorityPassed &&
|
|
trend == conditionsDir; // &&
|
|
// isConsolidationZonePassed;
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(visionCycleEvents);
|
|
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();
|
|
|
|
//
|
|
lastBullishConsolidationZone.Clean();
|
|
lastBearishConsolidationZone.Clean();
|
|
prevBullishConsolidationZone.Clean();
|
|
prevBearishConsolidationZone.Clean();
|
|
|
|
//
|
|
mConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mConditions.pivot = pivot;
|
|
mConditions.point = point;
|
|
mConditions.reward = reward;
|
|
mConditions.target = target;
|
|
mConditions.setupTime = cTime;
|
|
mConditions.priority = priority;
|
|
mConditions.dir = conditionsDir;
|
|
mConditions.amountPercent = amountPercent;
|
|
|
|
//
|
|
mConditions.UpdateTo(cTime);
|
|
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(visionCycleEvents);
|
|
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();
|
|
|
|
//
|
|
lastBullishConsolidationZone.Clean();
|
|
lastBearishConsolidationZone.Clean();
|
|
prevBullishConsolidationZone.Clean();
|
|
prevBearishConsolidationZone.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Trigger Conditions ...
|
|
bool DetectSignalTrigger(
|
|
//
|
|
X121SMCStrategyXWZSignalConditions &conditions,
|
|
//
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
//
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper,
|
|
//
|
|
int maxAllowedSetupAge = 30
|
|
//
|
|
)
|
|
{
|
|
//
|
|
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 &&
|
|
cBar.IsBullish()
|
|
//
|
|
;
|
|
|
|
//
|
|
isBearish =
|
|
//
|
|
isBearish &&
|
|
isPointBreaked &&
|
|
cBar.IsBearish()
|
|
//
|
|
;
|
|
|
|
//
|
|
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 ...
|
|
|
|
//
|
|
double sls[];
|
|
Add(
|
|
conditions.pivot,
|
|
sls //
|
|
);
|
|
|
|
//
|
|
// TODO: Add Consolidation Zone for 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_XWZ);
|
|
|
|
//
|
|
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 ...
|
|
X121SMCStrategyXWZSignalConditions tmpItems[];
|
|
Copy(
|
|
mConditionsCollection,
|
|
tmpItems //
|
|
);
|
|
|
|
//
|
|
// Prese Item Data ...
|
|
bool isBullish = IsBullish(mConditions.dir);
|
|
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
X121SMCStrategyXWZSignalConditions 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,
|
|
bool forWorkingZone = false //
|
|
)
|
|
{
|
|
//
|
|
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)
|
|
{
|
|
//
|
|
if (forWorkingZone)
|
|
{
|
|
mWorkingZoneObjects.Add(obj);
|
|
}
|
|
else
|
|
{
|
|
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);
|
|
|
|
//
|
|
if (forWorkingZone)
|
|
{
|
|
mWorkingZoneObjects.Add(obj);
|
|
}
|
|
else
|
|
{
|
|
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);
|
|
|
|
//
|
|
if (forWorkingZone)
|
|
{
|
|
mWorkingZoneObjects.Add(startVLine);
|
|
}
|
|
else
|
|
{
|
|
mObjects.Add(startVLine);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
void DrawFairValueGap(
|
|
XCFVG *fvg,
|
|
XCPOIDrawer *drawer,
|
|
bool forWorkingZone = false //
|
|
)
|
|
{
|
|
//
|
|
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)
|
|
{
|
|
//
|
|
if (forWorkingZone)
|
|
{
|
|
mWorkingZoneObjects.Add(obj);
|
|
}
|
|
else
|
|
{
|
|
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);
|
|
|
|
//
|
|
if (forWorkingZone)
|
|
{
|
|
mWorkingZoneObjects.Add(obj);
|
|
}
|
|
else
|
|
{
|
|
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);
|
|
|
|
//
|
|
if (forWorkingZone)
|
|
{
|
|
mWorkingZoneObjects.Add(startVLine);
|
|
}
|
|
else
|
|
{
|
|
mObjects.Add(startVLine);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
void DrawWorkingZone(
|
|
X121SMCStrategyXWZSignalConditions &conditions,
|
|
XCPOIDrawer *drawer //
|
|
)
|
|
{
|
|
//
|
|
if (drawer == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
bool hasWorkingZone = conditions.HasWorkingZone();
|
|
if (!hasWorkingZone)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
string prefix = "WKZ_" + conditions.workingZone.symbol + ToString(conditions.workingZone.period) + "_";
|
|
string tag = prefix + ToString(conditions.workingZone.upper) + "_" + ToString(conditions.workingZone.lower);
|
|
string suffix = ToMD5(tag);
|
|
|
|
//
|
|
string upperName = prefix + "_Upper_" + suffix;
|
|
string lowerName = prefix + "_Lower_" + suffix;
|
|
string zoneUpperName = prefix + "_ZoneUpper_" + suffix;
|
|
string zoneLowerName = prefix + "_ZoneLower_" + suffix;
|
|
|
|
//
|
|
string q1Name = prefix + "_Q1_" + suffix;
|
|
string q2Name = prefix + "_Q2_" + suffix;
|
|
string q3Name = prefix + "_Q3_" + suffix;
|
|
|
|
//
|
|
ulong chartID = drawer.ChartIdentification();
|
|
int subWindow = drawer.SubWindowIdentification();
|
|
|
|
//
|
|
bool isCreated = false;
|
|
|
|
//
|
|
// Check For Trend Approced ...
|
|
bool isTrendApproved = conditions.HasOrderBlock() &&
|
|
conditions.HasFairValueGap();
|
|
if (isTrendApproved)
|
|
{
|
|
//
|
|
DrawOrderBlock(
|
|
conditions.orderBlock,
|
|
drawer,
|
|
true //
|
|
);
|
|
|
|
//
|
|
DrawFairValueGap(
|
|
conditions.fairValueGap,
|
|
drawer,
|
|
true //
|
|
);
|
|
}
|
|
|
|
//
|
|
XCSupplyZoneObject *iSupObj;
|
|
isCreated = drawer.CreateSupplyZone(
|
|
conditions.supplyZone,
|
|
iSupObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iSupObj);
|
|
}
|
|
|
|
//
|
|
XCDemandZoneObject *iDemObj;
|
|
isCreated = drawer.CreateDemandZone(
|
|
conditions.demandZone,
|
|
iDemObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iDemObj);
|
|
}
|
|
|
|
//
|
|
// Lower ...
|
|
CChartObjectTrend *lowerHLine;
|
|
lowerHLine = new CChartObjectTrend();
|
|
isCreated = lowerHLine.Create(
|
|
chartID,
|
|
lowerName,
|
|
subWindow,
|
|
conditions.workingZone.from,
|
|
conditions.workingZone.lower,
|
|
conditions.workingZone.to,
|
|
conditions.workingZone.lower //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
lowerHLine.Color(clrLime);
|
|
mWorkingZoneObjects.Add(lowerHLine);
|
|
}
|
|
|
|
//
|
|
CChartObjectTrend *upperHLine;
|
|
upperHLine = new CChartObjectTrend();
|
|
isCreated = upperHLine.Create(
|
|
chartID,
|
|
upperName,
|
|
subWindow,
|
|
conditions.workingZone.from,
|
|
conditions.workingZone.upper,
|
|
conditions.workingZone.to,
|
|
conditions.workingZone.upper //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
upperHLine.Color(clrLime);
|
|
mWorkingZoneObjects.Add(upperHLine);
|
|
}
|
|
|
|
//
|
|
CChartObjectTrend *zoneLowerHLine;
|
|
zoneLowerHLine = new CChartObjectTrend();
|
|
isCreated = zoneLowerHLine.Create(
|
|
chartID,
|
|
zoneLowerName,
|
|
subWindow,
|
|
conditions.workingZone.from,
|
|
conditions.workingZone.zoneLower,
|
|
conditions.workingZone.to,
|
|
conditions.workingZone.zoneLower //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
zoneLowerHLine.Color(clrRed);
|
|
mWorkingZoneObjects.Add(zoneLowerHLine);
|
|
}
|
|
|
|
//
|
|
CChartObjectTrend *zoneUpperHLine;
|
|
zoneUpperHLine = new CChartObjectTrend();
|
|
isCreated = zoneUpperHLine.Create(
|
|
chartID,
|
|
zoneUpperName,
|
|
subWindow,
|
|
conditions.workingZone.from,
|
|
conditions.workingZone.zoneUpper,
|
|
conditions.workingZone.to,
|
|
conditions.workingZone.zoneUpper //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
zoneUpperHLine.Color(clrRed);
|
|
mWorkingZoneObjects.Add(zoneUpperHLine);
|
|
}
|
|
|
|
//
|
|
CChartObjectTrend *quarter1HLine;
|
|
quarter1HLine = new CChartObjectTrend();
|
|
isCreated = quarter1HLine.Create(
|
|
chartID,
|
|
q1Name,
|
|
subWindow,
|
|
conditions.workingZone.from,
|
|
conditions.workingZone.quarter1,
|
|
conditions.workingZone.to,
|
|
conditions.workingZone.quarter1 //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
quarter1HLine.Color(clrYellow);
|
|
mWorkingZoneObjects.Add(quarter1HLine);
|
|
}
|
|
|
|
//
|
|
CChartObjectTrend *quarter2HLine;
|
|
quarter2HLine = new CChartObjectTrend();
|
|
isCreated = quarter2HLine.Create(
|
|
chartID,
|
|
q2Name,
|
|
subWindow,
|
|
conditions.workingZone.from,
|
|
conditions.workingZone.quarter2,
|
|
conditions.workingZone.to,
|
|
conditions.workingZone.quarter2 //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
quarter2HLine.Color(clrYellow);
|
|
mWorkingZoneObjects.Add(quarter2HLine);
|
|
}
|
|
|
|
//
|
|
CChartObjectTrend *quarter3HLine;
|
|
quarter3HLine = new CChartObjectTrend();
|
|
isCreated = quarter3HLine.Create(
|
|
chartID,
|
|
q3Name,
|
|
subWindow,
|
|
conditions.workingZone.from,
|
|
conditions.workingZone.quarter3,
|
|
conditions.workingZone.to,
|
|
conditions.workingZone.quarter3 //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
quarter3HLine.Color(clrYellow);
|
|
mWorkingZoneObjects.Add(quarter3HLine);
|
|
}
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
void DrawConditions(
|
|
X121SMCStrategyXWZSignalConditions &conditions,
|
|
XCPOIDrawer *drawer,
|
|
bool forceClean = false //
|
|
)
|
|
{
|
|
//
|
|
if (drawer == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
if (forceClean)
|
|
{
|
|
mObjects.Clear();
|
|
}
|
|
|
|
//
|
|
bool isCreated = false;
|
|
|
|
//
|
|
ulong chartID = drawer.ChartIdentification();
|
|
int subWindow = drawer.SubWindowIdentification();
|
|
color bullishColor = drawer.BarBullishColor();
|
|
color bearishColor = drawer.BarBearishColor();
|
|
|
|
//
|
|
// Start Zones ...
|
|
bool hasStartZones = conditions.HasStartZones();
|
|
if (hasStartZones)
|
|
{
|
|
//
|
|
int count = conditions.CountStartZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
bool isBullish = conditions.startZones[i].IsBullish();
|
|
|
|
//
|
|
bool hasOB = conditions.startZones[i].HasOB();
|
|
if (hasOB)
|
|
{
|
|
// //
|
|
// XCBaseObject *iObj;
|
|
// isCreated = drawer.CreateOrderBlock(
|
|
// conditions.startZones[i].ob,
|
|
// iObj //
|
|
// );
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// mObjects.Add(iObj);
|
|
// }
|
|
|
|
//
|
|
DrawOrderBlock(
|
|
conditions.startZones[i].ob,
|
|
drawer //
|
|
);
|
|
}
|
|
|
|
//
|
|
bool hasFVG = conditions.startZones[i].HasFVG();
|
|
if (hasFVG)
|
|
{
|
|
// //
|
|
// XCBaseObject *iObj;
|
|
// isCreated = drawer.CreateFairValueGap(
|
|
// conditions.startZones[i].fvg,
|
|
// iObj //
|
|
// );
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// mObjects.Add(iObj);
|
|
// }
|
|
|
|
//
|
|
DrawFairValueGap(
|
|
conditions.startZones[i].fvg,
|
|
drawer //
|
|
);
|
|
}
|
|
|
|
// //
|
|
// bool hasSupply = conditions.startZones[i].HasSupply();
|
|
// if (hasSupply)
|
|
// {
|
|
// //
|
|
// XCSupplyZoneObject *iObj;
|
|
// isCreated = drawer.CreateSupplyZone(
|
|
// conditions.startZones[i].supply,
|
|
// iObj //
|
|
// );
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// mObjects.Add(iObj);
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// bool hasDemand = conditions.startZones[i].HasDemand();
|
|
// if (hasDemand)
|
|
// {
|
|
// //
|
|
// XCDemandZoneObject *iObj;
|
|
// isCreated = drawer.CreateDemandZone(
|
|
// conditions.startZones[i].demand,
|
|
// iObj //
|
|
// );
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// mObjects.Add(iObj);
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// bool hasSupport = conditions.startZones[i].HasSupport();
|
|
// if (hasSupport)
|
|
// {
|
|
// //
|
|
// XCSupportZoneObject *iObj;
|
|
// isCreated = drawer.CreateSupportZone(
|
|
// conditions.startZones[i].support,
|
|
// iObj //
|
|
// );
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// mObjects.Add(iObj);
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// bool hasResistance = conditions.startZones[i].HasResistance();
|
|
// if (hasResistance)
|
|
// {
|
|
// //
|
|
// XCResistanceZoneObject *iObj;
|
|
// isCreated = drawer.CreateResistanceZone(
|
|
// conditions.startZones[i].resistance,
|
|
// iObj //
|
|
// );
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// mObjects.Add(iObj);
|
|
// }
|
|
// }
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
string bName = "";
|
|
int arrowCode = 0;
|
|
string bSuffix = "";
|
|
color arrowColor = clrNONE;
|
|
ENUM_X_PRICE bPrice = X_PRICE_CLOSE;
|
|
|
|
//
|
|
bool hasSwingBar = conditions.startZones[i].swingBar.IsValid();
|
|
if (hasSwingBar)
|
|
{
|
|
//
|
|
bSuffix = ToMD5(conditions.startZones[i].swingBar.GetTag());
|
|
bName =
|
|
(isBullish
|
|
? "SWING_LOW"
|
|
: "SWING_HIGH") +
|
|
"_" + bSuffix;
|
|
arrowCode = 159;
|
|
arrowColor =
|
|
isBullish
|
|
? bullishColor
|
|
: bearishColor;
|
|
bPrice =
|
|
isBullish
|
|
? X_PRICE_LOW
|
|
: X_PRICE_HIGH;
|
|
|
|
//
|
|
XCBarArrowObject *iObj;
|
|
iObj = new XCBarArrowObject();
|
|
isCreated = iObj.CreateByBar(
|
|
chartID,
|
|
bName,
|
|
subWindow,
|
|
arrowCode,
|
|
conditions.startZones[i].swingBar,
|
|
bPrice //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
iObj.ArrowColor(arrowColor);
|
|
|
|
//
|
|
mObjects.Add(iObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasBreakerBar = conditions.startZones[i].breakerBar.IsValid();
|
|
if (hasBreakerBar)
|
|
{
|
|
//
|
|
bSuffix = ToMD5(conditions.startZones[i].breakerBar.GetTag());
|
|
bName =
|
|
(isBullish
|
|
? "BULL_BREAKER"
|
|
: "BEAR_BREAKER") +
|
|
"_" + bSuffix;
|
|
arrowCode =
|
|
isBullish
|
|
? 71
|
|
: 72;
|
|
arrowColor =
|
|
isBullish
|
|
? bullishColor
|
|
: bearishColor;
|
|
bPrice =
|
|
isBullish
|
|
? X_PRICE_LOW
|
|
: X_PRICE_HIGH;
|
|
|
|
//
|
|
XCBarArrowObject *iObj;
|
|
iObj = new XCBarArrowObject();
|
|
isCreated = iObj.CreateByBar(
|
|
chartID,
|
|
bName,
|
|
subWindow,
|
|
arrowCode,
|
|
conditions.startZones[i].breakerBar,
|
|
bPrice //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
iObj.ArrowColor(arrowColor);
|
|
|
|
//
|
|
mObjects.Add(iObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasMomentumBar = conditions.startZones[i].momentumBar.IsValid();
|
|
if (hasMomentumBar)
|
|
{
|
|
//
|
|
bSuffix = ToMD5(conditions.startZones[i].momentumBar.GetTag());
|
|
bName =
|
|
(isBullish
|
|
? "BULL_MOMENTUM"
|
|
: "BEAR_MOMENTUM") +
|
|
"_" + bSuffix;
|
|
arrowCode =
|
|
isBullish
|
|
? 233
|
|
: 234;
|
|
arrowColor =
|
|
isBullish
|
|
? bullishColor
|
|
: bearishColor;
|
|
bPrice =
|
|
isBullish
|
|
? X_PRICE_LOW
|
|
: X_PRICE_HIGH;
|
|
|
|
//
|
|
XCBarArrowObject *iObj;
|
|
iObj = new XCBarArrowObject();
|
|
isCreated = iObj.CreateByBar(
|
|
chartID,
|
|
bName,
|
|
subWindow,
|
|
arrowCode,
|
|
conditions.startZones[i].momentumBar,
|
|
bPrice //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
iObj.ArrowColor(arrowColor);
|
|
|
|
//
|
|
mObjects.Add(iObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasRejectionBar = conditions.startZones[i].rejectionBar.IsValid();
|
|
if (hasRejectionBar)
|
|
{
|
|
//
|
|
bSuffix = ToMD5(conditions.startZones[i].rejectionBar.GetTag());
|
|
bName =
|
|
(isBullish
|
|
? "BULL_REJECTION"
|
|
: "BEAR_REJECTION") +
|
|
"_" + bSuffix;
|
|
arrowCode =
|
|
isBullish
|
|
? 241
|
|
: 242;
|
|
arrowColor =
|
|
isBullish
|
|
? bullishColor
|
|
: bearishColor;
|
|
bPrice =
|
|
isBullish
|
|
? X_PRICE_LOW
|
|
: X_PRICE_HIGH;
|
|
|
|
//
|
|
XCBarArrowObject *iObj;
|
|
iObj = new XCBarArrowObject();
|
|
isCreated = iObj.CreateByBar(
|
|
chartID,
|
|
bName,
|
|
subWindow,
|
|
arrowCode,
|
|
conditions.startZones[i].rejectionBar,
|
|
bPrice //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
iObj.ArrowColor(arrowColor);
|
|
|
|
//
|
|
mObjects.Add(iObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasAppliedBox = conditions.startZones[i].appliedBox.IsValid();
|
|
if (hasAppliedBox)
|
|
{
|
|
//
|
|
arrowColor =
|
|
IsBullish(conditions.startZones[i].appliedBox.dir)
|
|
? bullishColor
|
|
: bearishColor;
|
|
|
|
//
|
|
XCBoxObject *iObj;
|
|
isCreated = drawer.CreateBox(
|
|
conditions.startZones[i].appliedBox,
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
//
|
|
iObj.BoxWidth(2);
|
|
iObj.BoxColor(arrowColor);
|
|
|
|
//
|
|
mObjects.Add(iObj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
protected:
|
|
//
|
|
|
|
//
|
|
private:
|
|
//
|
|
// Props ...
|
|
CArrayObj mObjects;
|
|
CArrayObj mWorkingZoneObjects;
|
|
|
|
/**
|
|
* Initialize ...
|
|
*/
|
|
void Init()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* DeInitialize ...
|
|
*/
|
|
void DeInit()
|
|
{
|
|
//
|
|
RemoveDraws();
|
|
mConditions.Clean();
|
|
RemoveWorkingZoneDraws();
|
|
Clean(mConditionsCollection);
|
|
}
|
|
|
|
//
|
|
// Helpers ...
|
|
|
|
//
|
|
bool CalculateRiskReward(
|
|
ENUM_X121SMC_XWZ_PRIORITY priority,
|
|
double &reward,
|
|
double &amountPercent //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
reward = 0;
|
|
amountPercent = 0;
|
|
|
|
//
|
|
result = priority != X121SMC_XWZ_PRIORITY_NONE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
switch (priority)
|
|
{
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_STRONG_HIGH:
|
|
//
|
|
reward = 6;
|
|
amountPercent = 2;
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_HIGH:
|
|
//
|
|
reward = 4;
|
|
amountPercent = 2;
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_REGULAR:
|
|
//
|
|
reward = 3;
|
|
amountPercent = 1.5;
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_LOW:
|
|
//
|
|
reward = 2;
|
|
amountPercent = 1;
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_WEAK:
|
|
//
|
|
reward = 1;
|
|
amountPercent = 0.5;
|
|
break;
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
reward > 0 &&
|
|
amountPercent > 0
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
// |