2124 lines
55 KiB
Plaintext
2124 lines
55 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 ...
|
|
X121SMCStrategyXWZWorkingZone workingZone;
|
|
X121SMCStrategyXWZSignalConditions mConditions;
|
|
X121SMCStrategyXWZSignalConditions mConditionsCollection[];
|
|
|
|
//
|
|
// Constructor(s) ...
|
|
XCX121SMCXWZSignalDetector(
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period //
|
|
)
|
|
{
|
|
//
|
|
symbol = _symbol;
|
|
period = _period;
|
|
Init();
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
~XCX121SMCXWZSignalDetector()
|
|
{
|
|
DeInit();
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Detect Setup Conditions ...
|
|
bool DetectSignalSetup(
|
|
//
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper,
|
|
//
|
|
double maxAllowedSLDistanceInPoint = 300
|
|
//
|
|
)
|
|
{
|
|
//
|
|
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;
|
|
|
|
//
|
|
mConditions.symbol = symbol;
|
|
mConditions.period = period;
|
|
|
|
//
|
|
double ask = GetAsk(symbol);
|
|
double bid = GetBid(symbol);
|
|
datetime cTime = TimeCurrent();
|
|
double points = GetPoints(symbol);
|
|
|
|
//
|
|
// Cycles Conditions ...
|
|
|
|
//
|
|
XOHCL consolidationZBar;
|
|
result = consolidationCycleHelper.GetBar(
|
|
consolidationZBar,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
consolidationZBar.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool drawBar = false;
|
|
if (drawBar)
|
|
{
|
|
//
|
|
DrawBar(
|
|
consolidationZBar,
|
|
decisionCycleHelper.mPOIDrawer //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
|
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
|
X121SMCCycleConditions decisionConditions;
|
|
result = decisionCycleHelper.GetConditions(
|
|
decisionCycleEvents,
|
|
decisionPoiEvents,
|
|
decisionConditions,
|
|
zIndex,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(decisionPoiEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
decisionConditions.Clean();
|
|
|
|
//
|
|
mConditions.Clean();
|
|
consolidationZBar.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)
|
|
{
|
|
//
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
|
|
//
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
analyseConditions.Clean();
|
|
decisionConditions.Clean();
|
|
|
|
//
|
|
mConditions.Clean();
|
|
consolidationZBar.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)
|
|
{
|
|
//
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(consolidationPoiEvents);
|
|
|
|
//
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
analyseConditions.Clean();
|
|
decisionConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
|
|
//
|
|
mConditions.Clean();
|
|
consolidationZBar.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)
|
|
{
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(consolidationPoiEvents);
|
|
|
|
//
|
|
Clean(visionCycleEvents);
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
visionConditions.Clean();
|
|
analyseConditions.Clean();
|
|
decisionConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
|
|
//
|
|
mConditions.Clean();
|
|
consolidationZBar.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;
|
|
|
|
//
|
|
// Select Drawer Class ...
|
|
XCPOIDrawer *drawer = visionCycleHelper.mPOIDrawer;
|
|
|
|
//
|
|
// Setup Conditions ...
|
|
double sls[];
|
|
double pivot = 0;
|
|
double point = 0;
|
|
double targets[];
|
|
double reward = 0;
|
|
XBoxZone signalBox;
|
|
XOBFVG selectedZone;
|
|
double amountPercent = 0;
|
|
bool hasPriority = false;
|
|
bool hasSignalBox = false;
|
|
bool hasRewardAmount = false;
|
|
bool hasSelectedZone = false;
|
|
bool isSignalBoxReversal = false;
|
|
bool isSelectedZoneReversal = false;
|
|
bool hasSelectedConsolidationZone = false;
|
|
XConsolidationZone selectedConsolidationZone;
|
|
ENUM_X_DIRECTION selectedZoneDir = X_DIRECTION_NONE;
|
|
ENUM_X121SMC_XWZ_PRIORITY priority = X121SMC_XWZ_PRIORITY_NONE;
|
|
ENUM_X121SMC_XWZ_PROVIDERS provider = X121SMC_XWZ_PROVIDER_NONE;
|
|
|
|
//
|
|
// First We Have to Has Working Zone ...
|
|
bool hasWorkingZone = workingZone.IsValid();
|
|
if (!hasWorkingZone)
|
|
{
|
|
//
|
|
hasWorkingZone = workingZone.Init(
|
|
symbol,
|
|
period,
|
|
zIndex,
|
|
visionState,
|
|
consolidationState,
|
|
analyseState,
|
|
decisionState //
|
|
);
|
|
}
|
|
|
|
//
|
|
if (hasWorkingZone)
|
|
{
|
|
//
|
|
visionCycleHelper.mPOIDetector.MaxRequiredPOIs(50);
|
|
analyseCycleHelper.mPOIDetector.MaxRequiredPOIs(50);
|
|
decisionCycleHelper.mPOIDetector.MaxRequiredPOIs(50);
|
|
consolidationCycleHelper.mPOIDetector.MaxRequiredPOIs(50);
|
|
|
|
//
|
|
visionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578);
|
|
analyseCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578);
|
|
decisionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578);
|
|
consolidationCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578);
|
|
|
|
//
|
|
workingZone.Update(
|
|
zIndex,
|
|
visionState,
|
|
consolidationState,
|
|
analyseState,
|
|
decisionState //
|
|
);
|
|
}
|
|
|
|
//
|
|
bool hasWaitingZones = hasWorkingZone &&
|
|
workingZone.HasWaitingZones();
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Check Conditions if Has Inside Zones ...
|
|
bool hasInsideZones = hasWorkingZone &&
|
|
workingZone.HasInsideZones();
|
|
if (hasInsideZones)
|
|
{
|
|
//
|
|
int selectedIDX = -1;
|
|
int count = workingZone.CountInsideZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
bool has = DetectSelectedZoneConditions(
|
|
isSelectedZoneReversal,
|
|
workingZone.insideZones[i],
|
|
decisionState,
|
|
decisionXConditions //
|
|
);
|
|
|
|
//
|
|
if (has)
|
|
{
|
|
//
|
|
selectedIDX = i;
|
|
selectedZone = workingZone.insideZones[i];
|
|
|
|
//
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
if (IsValidIndex(selectedIDX))
|
|
{
|
|
//
|
|
ArrayRemove(
|
|
workingZone.insideZones,
|
|
selectedIDX,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
hasSelectedZone = selectedZone.IsValid();
|
|
provider = X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Check Conditions if Has Breaked Zones ...
|
|
// bool hasBreakedZones = hasWorkingZone &&
|
|
// workingZone.HasBreakedZones();
|
|
// if (hasBreakedZones)
|
|
// {
|
|
// //
|
|
// if (!hasSelectedZone)
|
|
// {
|
|
// //
|
|
// int selectedIDX = -1;
|
|
// int count = workingZone.CountBreakedZones();
|
|
// for (int i = 0; i < count; i++)
|
|
// {
|
|
// //
|
|
// bool has = DetectSelectedZoneConditions(
|
|
// isSelectedZoneReversal,
|
|
// workingZone.breakedZones[i],
|
|
// decisionState,
|
|
// decisionXConditions //
|
|
// );
|
|
|
|
// //
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// selectedIDX = i;
|
|
// selectedZone = workingZone.breakedZones[i];
|
|
|
|
// //
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// if (IsValidIndex(selectedIDX))
|
|
// {
|
|
// //
|
|
// ArrayRemove(
|
|
// workingZone.breakedZones,
|
|
// selectedIDX,
|
|
// 1 //
|
|
// );
|
|
|
|
// //
|
|
// hasSelectedZone = selectedZone.IsValid();
|
|
// provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
bool hasInsideBoxes = hasWorkingZone &&
|
|
workingZone.HasInsideBoxes();
|
|
if (hasInsideBoxes)
|
|
{
|
|
//
|
|
XOHCL zBar;
|
|
XOHCL cBar;
|
|
int count = 0;
|
|
bool has = false;
|
|
XBoxZone tmpSelectedBox;
|
|
int tmpSelectedBoxIDX = -1;
|
|
|
|
//
|
|
has = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
has = has &&
|
|
zBar.GetPreviousBar(cBar);
|
|
if (has)
|
|
{
|
|
//
|
|
count = workingZone.CountInsideBoxes();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
tmpSelectedBox = workingZone.insideBoxes[i];
|
|
|
|
//
|
|
bool isBullish = tmpSelectedBox.IsBullish();
|
|
bool isBearish = tmpSelectedBox.IsBearish();
|
|
|
|
//
|
|
bool hasFiboPressure =
|
|
visionCycleHelper
|
|
.mBarAnalyser
|
|
.HasFiboPressure(
|
|
cBar,
|
|
tmpSelectedBox.dir,
|
|
X_FIBO_LEVEL_382 //
|
|
);
|
|
|
|
//
|
|
bool isBullishRejectedUpper =
|
|
cBar.low < tmpSelectedBox.upper &&
|
|
cBar.GetDown() > tmpSelectedBox.upper;
|
|
|
|
//
|
|
bool isBullishRejectedLower =
|
|
cBar.low < tmpSelectedBox.lower &&
|
|
cBar.GetDown() > tmpSelectedBox.lower;
|
|
|
|
//
|
|
bool isBearishRejectedUpper =
|
|
cBar.high > tmpSelectedBox.upper &&
|
|
cBar.GetUp() < tmpSelectedBox.upper;
|
|
|
|
//
|
|
bool isBearishRejectedLower =
|
|
cBar.high > tmpSelectedBox.lower &&
|
|
cBar.GetUp() < tmpSelectedBox.lower;
|
|
|
|
//
|
|
bool isBullishRejected =
|
|
// isBullishRejectedUpper ||
|
|
isBullishRejectedLower;
|
|
|
|
//
|
|
bool isBearishRejected =
|
|
isBearishRejectedUpper
|
|
// || isBearishRejectedLower
|
|
;
|
|
|
|
//
|
|
bool isMaWapBullish =
|
|
//
|
|
(decisionXConditions.isX3MaBullishState &&
|
|
decisionXConditions.isX3MaBullishOrdered)
|
|
//
|
|
&&
|
|
//
|
|
(decisionXConditions.isVWapBullishState &&
|
|
decisionXConditions.isVWapBullishOrdered)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isMaWapBearish =
|
|
//
|
|
(decisionXConditions.isX3MaBearishState &&
|
|
decisionXConditions.isX3MaBearishOrdered)
|
|
//
|
|
&&
|
|
//
|
|
(decisionXConditions.isVWapBearishState &&
|
|
decisionXConditions.isVWapBearishOrdered)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isX2MaWapInside =
|
|
//
|
|
(decisionXConditions.x3maFastBuffer[cIndex] < tmpSelectedBox.upper &&
|
|
decisionXConditions.x3maMidBuffer[cIndex] < tmpSelectedBox.upper &&
|
|
decisionXConditions.x3maFastBuffer[cIndex] > tmpSelectedBox.lower &&
|
|
decisionXConditions.x3maMidBuffer[cIndex] > tmpSelectedBox.lower)
|
|
//
|
|
&&
|
|
//
|
|
(decisionXConditions.vwapFastBuffer[cIndex] < tmpSelectedBox.upper &&
|
|
decisionXConditions.vwapMidBuffer[cIndex] < tmpSelectedBox.upper &&
|
|
decisionXConditions.vwapFastBuffer[cIndex] > tmpSelectedBox.lower &&
|
|
decisionXConditions.vwapMidBuffer[cIndex] > tmpSelectedBox.lower)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBullishConditions =
|
|
//
|
|
isBullish &&
|
|
isMaWapBearish &&
|
|
isX2MaWapInside &&
|
|
hasFiboPressure &&
|
|
isBullishRejected &&
|
|
cBar.low < cBar.GetDown()
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBearishConditions =
|
|
//
|
|
isBearish &&
|
|
isMaWapBullish &&
|
|
isX2MaWapInside &&
|
|
hasFiboPressure &&
|
|
isBearishRejected &&
|
|
cBar.high > cBar.GetUp()
|
|
//
|
|
;
|
|
|
|
//
|
|
has = isBullishConditions ||
|
|
isBearishConditions;
|
|
if (!has)
|
|
{
|
|
//
|
|
tmpSelectedBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
tmpSelectedBoxIDX = i;
|
|
signalBox = tmpSelectedBox;
|
|
|
|
//
|
|
tmpSelectedBox.Clean();
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
isSignalBoxReversal = false;
|
|
hasSignalBox = signalBox.IsValid();
|
|
if (hasSignalBox)
|
|
{
|
|
//
|
|
ArrayRemove(
|
|
workingZone.insideBoxes,
|
|
tmpSelectedBoxIDX,
|
|
1 //
|
|
);
|
|
}
|
|
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
tmpSelectedBox.Clean();
|
|
}
|
|
|
|
//
|
|
bool hasBreakedBoxes = hasWorkingZone &&
|
|
workingZone.HasBreakedBoxes();
|
|
if (hasBreakedBoxes)
|
|
{
|
|
}
|
|
|
|
//
|
|
if (!hasSignalBox)
|
|
{
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Double Check and Prepare Signal Conditions ...
|
|
// including Targets and SLs ...
|
|
|
|
//
|
|
if (hasSelectedZone)
|
|
{
|
|
//
|
|
int idx = -1;
|
|
bool has = false;
|
|
|
|
//
|
|
// Check Consolidation Zones for SL Handling ...
|
|
selectedZoneDir =
|
|
!isSelectedZoneReversal
|
|
? selectedZone.GetDirection()
|
|
: Opposit(selectedZone.GetDirection());
|
|
bool isSelectedZonDirBullish = IsBullish(selectedZoneDir);
|
|
|
|
//
|
|
if (isSelectedZoneReversal)
|
|
{
|
|
provider = X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH;
|
|
}
|
|
|
|
//
|
|
// Calculate Priority ...
|
|
hasPriority =
|
|
hasWorkingZone &&
|
|
workingZone
|
|
.DetectPriority(
|
|
priority,
|
|
selectedZoneDir,
|
|
zIndex,
|
|
period //
|
|
);
|
|
|
|
//
|
|
// Calculate Risk Reward Ration based on Priority ...
|
|
hasRewardAmount = CalculateRiskReward(
|
|
priority,
|
|
reward,
|
|
amountPercent //
|
|
);
|
|
|
|
//
|
|
// Calculate Pivot and Point ...
|
|
|
|
//
|
|
pivot =
|
|
isSelectedZonDirBullish
|
|
? selectedZone.ob.Lower()
|
|
: selectedZone.ob.Upper();
|
|
|
|
//
|
|
point =
|
|
isSelectedZonDirBullish
|
|
? selectedZone.ob.Upper()
|
|
: selectedZone.ob.Lower();
|
|
|
|
//
|
|
// Detect Targets ...
|
|
DetectSelectedZonesTargets(
|
|
targets,
|
|
selectedZone,
|
|
selectedZoneDir,
|
|
priority,
|
|
workingZone,
|
|
zIndex //
|
|
);
|
|
|
|
//
|
|
// Detect SLs ...
|
|
double iAtr = decisionXConditions.atrBuffer[0];
|
|
iAtr *= 1.5;
|
|
|
|
//
|
|
// Default SL is Pivot ...
|
|
if (pivot > 0)
|
|
{
|
|
//
|
|
Add(
|
|
pivot,
|
|
sls //
|
|
);
|
|
|
|
//
|
|
double iSL = iAtr * pivot;
|
|
Add(
|
|
iSL,
|
|
sls //
|
|
);
|
|
}
|
|
|
|
//
|
|
DetectSelectedZoneSLCandidates(
|
|
sls,
|
|
selectedZone,
|
|
selectedZoneDir,
|
|
workingZone,
|
|
decisionXConditions,
|
|
zIndex,
|
|
maxAllowedSLDistanceInPoint //
|
|
);
|
|
|
|
//
|
|
// Summaries Conditions ...
|
|
result =
|
|
pivot > 0 &&
|
|
point > 0 &&
|
|
hasPriority &&
|
|
hasRewardAmount &&
|
|
HasDirection(selectedZoneDir);
|
|
if (result)
|
|
{
|
|
//
|
|
isBullish = IsBullish(selectedZoneDir);
|
|
isBearish = IsBearish(selectedZoneDir);
|
|
|
|
//
|
|
Copy(
|
|
sls,
|
|
mConditions.sls //
|
|
);
|
|
Copy(
|
|
targets,
|
|
mConditions.targets //
|
|
);
|
|
|
|
//
|
|
mConditions.pivot = pivot;
|
|
mConditions.point = point;
|
|
mConditions.reward = reward;
|
|
mConditions.setupTime = cTime;
|
|
mConditions.priority = priority;
|
|
mConditions.provider = provider;
|
|
mConditions.dir = selectedZoneDir;
|
|
mConditions.signalBox = signalBox;
|
|
mConditions.amountPercent = amountPercent;
|
|
}
|
|
|
|
//
|
|
// Cleanup Resources ...
|
|
|
|
//
|
|
Clean(sls);
|
|
Clean(targets);
|
|
selectedZone.Clean();
|
|
selectedConsolidationZone.Clean();
|
|
}
|
|
|
|
//
|
|
if (hasSignalBox)
|
|
{
|
|
// //
|
|
// workingZone.mInsideZoneObjects.Clear();
|
|
// workingZone.mBreakedZoneObjects.Clear();
|
|
// workingZone.mWaitingZoneObjects.Clear();
|
|
// workingZone.mWorkingZoneObjects.Clear();
|
|
|
|
// //
|
|
// XCBoxObject *iObj;
|
|
// signalBox.to = cTime;
|
|
// bool isCreated = drawer.CreateBox(
|
|
// signalBox,
|
|
// iObj //
|
|
// );
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// //
|
|
// iObj.BoxWidth(2);
|
|
// iObj.BoxColor(clrYellow);
|
|
// iObj.BoxStyle(STYLE_SOLID);
|
|
// }
|
|
|
|
// //
|
|
// bool isSignalBoxBullishDir = signalBox.IsBullish();
|
|
|
|
// //
|
|
// // Calculate Priority ...
|
|
// hasPriority =
|
|
// hasWorkingZone &&
|
|
// workingZone
|
|
// .DetectPriority(
|
|
// priority,
|
|
// signalBox.dir,
|
|
// zIndex,
|
|
// period //
|
|
// );
|
|
|
|
// //
|
|
// // Calculate Risk Reward Ration based on Priority ...
|
|
// hasRewardAmount = CalculateRiskReward(
|
|
// priority,
|
|
// reward,
|
|
// amountPercent //
|
|
// );
|
|
|
|
// //
|
|
// // Calculate Pivot and Point ...
|
|
|
|
// //
|
|
// pivot =
|
|
// isSignalBoxBullishDir
|
|
// ? signalBox.lower
|
|
// : signalBox.upper;
|
|
|
|
// //
|
|
// point =
|
|
// isSignalBoxBullishDir
|
|
// ? signalBox.upper
|
|
// : signalBox.lower;
|
|
|
|
// //
|
|
// double defaultTarget =
|
|
// isSignalBoxBullishDir
|
|
// ? signalBox.upper
|
|
// : signalBox.lower;
|
|
// Add(
|
|
// defaultTarget,
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Detect SLs ...
|
|
// double iAtr = decisionXConditions.atrBuffer[0];
|
|
// iAtr *= 1.5;
|
|
|
|
// //
|
|
// double defaultSL =
|
|
// isSignalBoxBullishDir
|
|
// ? decisionXConditions.valesBuffer[0] - iAtr
|
|
// : decisionXConditions.peaksBuffer[0] + iAtr;
|
|
|
|
// //
|
|
// Add(
|
|
// defaultSL,
|
|
// sls //
|
|
// );
|
|
|
|
// //
|
|
// // Summaries Conditions ...
|
|
// result =
|
|
// pivot > 0 &&
|
|
// point > 0 &&
|
|
// hasPriority &&
|
|
// hasRewardAmount;
|
|
// if (result)
|
|
// {
|
|
// //
|
|
// isBullish = signalBox.IsBullish();
|
|
// isBearish = signalBox.IsBearish();
|
|
|
|
// //
|
|
// Copy(
|
|
// sls,
|
|
// mConditions.sls //
|
|
// );
|
|
// Copy(
|
|
// targets,
|
|
// mConditions.targets //
|
|
// );
|
|
|
|
// //
|
|
// mConditions.pivot = pivot;
|
|
// mConditions.point = point;
|
|
// mConditions.reward = reward;
|
|
// mConditions.setupTime = cTime;
|
|
// mConditions.priority = priority;
|
|
// mConditions.provider = provider;
|
|
// mConditions.dir = signalBox.dir;
|
|
// mConditions.signalBox = signalBox;
|
|
// mConditions.amountPercent = amountPercent;
|
|
// }
|
|
|
|
// //
|
|
// signalBox.Clean();
|
|
// hasSignalBox = false;
|
|
}
|
|
|
|
//
|
|
UpdateTo(cTime);
|
|
|
|
//
|
|
// Draw Working Zone ...
|
|
if (hasWorkingZone)
|
|
{
|
|
//
|
|
workingZone.Draw(
|
|
drawer,
|
|
true, // Draw Waiting Zones ...
|
|
true, // Draw Inside Zones ...
|
|
true, // Draw Breaked Zones ...
|
|
true, // Draw Supply Zone ...
|
|
true, // Draw Demand Zone ...
|
|
false, // Draw Supply Zones ...
|
|
false, // Draw Demand Zones ...
|
|
false, // Draw Support Zones ...
|
|
false // Draw Resistance Zones ...
|
|
);
|
|
|
|
//
|
|
// XCBaseObject *objects[];
|
|
// drawer.DrawState(
|
|
// decisionState,
|
|
// objects,
|
|
// false, // DrawT icksZone ...
|
|
// true, // Ignore SwingHighs ...
|
|
// true, // Ignore SwingLows ...
|
|
// true, // Ignore SupportZones ...
|
|
// true, // Ignore ResistanceZones ...
|
|
// true, // Ignore SupplyZones ...
|
|
// true, // Ignore DemandZones ...
|
|
// true, // Ignore BullishOrderBlocks ...
|
|
// true, // Ignore BearishOrderBlocks ...
|
|
// true, // Ignore BullishFairValueGaps ...
|
|
// true, // Ignore BearishFairValueGaps ...
|
|
// true, // Ignore BullishRejectionBars ...
|
|
// true, // Ignore BearishRejectionBars ...
|
|
// true, // Ignore BullishMomentumBars ...
|
|
// true, // Ignore BearishMomentumBars ...
|
|
// true, // Ignore BullishConsolidationZones ...
|
|
// true // Ignore BearishConsolidationZones ...
|
|
// );
|
|
|
|
// //
|
|
// int count = 0;
|
|
// bool has = false;
|
|
|
|
// //
|
|
// has = workingZone.HasSupplyZones();
|
|
// if (has)
|
|
// {
|
|
// }
|
|
|
|
// //
|
|
// has = workingZone.HasDemandZones();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// count = workingZone.CountDemandZones();
|
|
// for (int i = 0; i < count; i++)
|
|
// {
|
|
// //
|
|
// XCDemandZone *iZone = workingZone.demandZones[i];
|
|
|
|
// //
|
|
// XCDemandZoneObject *iObj;
|
|
// bool isCreated = drawer.CreateDemandZone(
|
|
// iZone,
|
|
// iObj //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// Print("");
|
|
}
|
|
|
|
//
|
|
// Cleanup Resources ...
|
|
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(consolidationPoiEvents);
|
|
|
|
//
|
|
Clean(visionCycleEvents);
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
visionState.Clean();
|
|
analyseState.Clean();
|
|
decisionState.Clean();
|
|
consolidationState.Clean();
|
|
|
|
//
|
|
visionConditions.Clean();
|
|
analyseConditions.Clean();
|
|
decisionConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
|
|
//
|
|
visionXConditions.Clean();
|
|
analyseXConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
consolidationXConditions.Clean();
|
|
|
|
//
|
|
consolidationZBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Trigger Conditions ...
|
|
bool DetectSignalTrigger(
|
|
//
|
|
X121SMCStrategyXWZSignalConditions &conditions,
|
|
//
|
|
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;
|
|
|
|
//
|
|
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)
|
|
{
|
|
//
|
|
// Cleanup ...
|
|
|
|
//
|
|
Clean(decisionPoiEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
decisionConditions.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)
|
|
{
|
|
//
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
|
|
//
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
analyseConditions.Clean();
|
|
decisionConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
|
|
//
|
|
// Cycle X121Conditions ...
|
|
X121Conditions decisionXConditions = decisionConditions.x121Conditions;
|
|
X121Conditions analyseXConditions = analyseConditions.x121Conditions;
|
|
|
|
//
|
|
double iAtr = decisionXConditions.atrBuffer[1];
|
|
iAtr *= 1.5;
|
|
|
|
//
|
|
// Check Signal Validation ...
|
|
// IMPORTANT: since all Validations done in SetUp Process ...
|
|
// here we only Execute Signal ...
|
|
|
|
//
|
|
result = isBullish ||
|
|
isBearish;
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
//
|
|
// Retrieve Entry Price ...
|
|
double entry = GetEntry(
|
|
conditions.symbol,
|
|
setupDir //
|
|
);
|
|
|
|
//
|
|
// Select and Apply SL ...
|
|
|
|
//
|
|
double slsMin = GetMin(conditions.sls);
|
|
double slsMax = GetMax(conditions.sls);
|
|
|
|
//
|
|
double longSL = slsMin;
|
|
double shortSL = slsMax;
|
|
|
|
//
|
|
double sl = isBullish
|
|
? longSL
|
|
: shortSL;
|
|
|
|
//
|
|
conditions.sl = sl;
|
|
conditions.triggerTime = cTime;
|
|
conditions.type = isBullish
|
|
? X_POSITION_TYPE_LONG
|
|
: X_POSITION_TYPE_SHORT;
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
// Cleanup ...
|
|
|
|
//
|
|
Clean(decisionPoiEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
decisionState.Clean();
|
|
decisionConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
|
|
//
|
|
Clean(analysePoiEvents);
|
|
Clean(analyseCycleEvents);
|
|
|
|
//
|
|
analyseState.Clean();
|
|
analyseConditions.Clean();
|
|
analyseXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Guards ...
|
|
bool DetectGuards(
|
|
//
|
|
X121SMCGuard &guards[],
|
|
const XPosition &positions[],
|
|
//
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XC121SMCCycleHelper *analyseCycleHelper,
|
|
XC121SMCCycleHelper *consolidationCycleHelper,
|
|
XC121SMCCycleHelper *visionCycleHelper
|
|
//
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
return false;
|
|
|
|
//
|
|
Clean(guards);
|
|
|
|
//
|
|
bool isCycleHelpersValid =
|
|
//
|
|
visionCycleHelper != NULL &&
|
|
analyseCycleHelper != NULL &&
|
|
decisionCycleHelper != NULL &&
|
|
consolidationCycleHelper != NULL
|
|
//
|
|
;
|
|
|
|
//
|
|
// Set Provider for Common Guards ...
|
|
string provider = ToString(X_121_SMC_PROVIDER_XWZ);
|
|
|
|
//
|
|
// Check Cycle Helpers Validation ...
|
|
result = isCycleHelpersValid;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Select Own Positions ...
|
|
int count = ArraySize(positions);
|
|
result = IsValidSize(count);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
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 //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Check Extracted Positions ...
|
|
|
|
//
|
|
count = ArraySize(ownPositions);
|
|
|
|
//
|
|
int longsCount = ArraySize(ownLongPositions);
|
|
bool hasLongs = IsValidSize(longsCount);
|
|
|
|
//
|
|
int shortsCount = ArraySize(ownShortPositions);
|
|
bool hasShorts = IsValidSize(shortsCount);
|
|
|
|
//
|
|
// Validate Own Positions ...
|
|
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
|
|
//
|
|
);
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Implement 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;
|
|
|
|
//
|
|
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)
|
|
{
|
|
//
|
|
Clean(decisionPoiEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
decisionConditions.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)
|
|
{
|
|
//
|
|
Clean(decisionPoiEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
decisionConditions.Clean();
|
|
|
|
//
|
|
Clean(analysePoiEvents);
|
|
Clean(analyseCycleEvents);
|
|
|
|
//
|
|
analyseConditions.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)
|
|
{
|
|
//
|
|
Clean(decisionPoiEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
decisionConditions.Clean();
|
|
|
|
//
|
|
Clean(analysePoiEvents);
|
|
Clean(analyseCycleEvents);
|
|
|
|
//
|
|
analyseConditions.Clean();
|
|
|
|
//
|
|
Clean(consolidationPoiEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
consolidationConditions.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)
|
|
{
|
|
//
|
|
Clean(decisionPoiEvents);
|
|
Clean(decisionCycleEvents);
|
|
|
|
//
|
|
decisionConditions.Clean();
|
|
|
|
//
|
|
Clean(analysePoiEvents);
|
|
Clean(analyseCycleEvents);
|
|
|
|
//
|
|
analyseConditions.Clean();
|
|
|
|
//
|
|
Clean(consolidationPoiEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
consolidationConditions.Clean();
|
|
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(visionCycleEvents);
|
|
|
|
//
|
|
visionConditions.Clean();
|
|
|
|
//
|
|
result = HasChild(guards);
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Cycles POI States ...
|
|
XPOIState visionState = visionConditions.state;
|
|
XPOIState analyseState = analyseConditions.state;
|
|
XPOIState decisionState = decisionConditions.state;
|
|
XPOIState consolidationState = consolidationConditions.state;
|
|
|
|
//
|
|
// Cycle X121Conditions ...
|
|
X121Conditions visionXConditions = visionConditions.x121Conditions;
|
|
X121Conditions analyseXConditions = analyseConditions.x121Conditions;
|
|
X121Conditions decisionXConditions = decisionConditions.x121Conditions;
|
|
X121Conditions consolidationXConditions = consolidationConditions.x121Conditions;
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Selected Consolidation Zones ...
|
|
|
|
//
|
|
int idx = -1;
|
|
bool has = false;
|
|
|
|
//
|
|
bool hasBullishConsolidationZone = false;
|
|
XConsolidationZone bullishConsolidationZone;
|
|
has = decisionState.HasBullishConsolidationZones();
|
|
if (has)
|
|
{
|
|
//
|
|
idx = GetYoungest(decisionState.bullishConsolidationZones);
|
|
hasBullishConsolidationZone = IsValidIndex(idx);
|
|
if (hasBullishConsolidationZone)
|
|
{
|
|
bullishConsolidationZone = decisionState.bullishConsolidationZones[idx];
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasBearishConsolidationZone = false;
|
|
XConsolidationZone bearishConsolidationZone;
|
|
has = decisionState.HasBearishConsolidationZones();
|
|
if (has)
|
|
{
|
|
//
|
|
idx = GetYoungest(decisionState.bearishConsolidationZones);
|
|
hasBearishConsolidationZone = IsValidIndex(idx);
|
|
if (hasBearishConsolidationZone)
|
|
{
|
|
bearishConsolidationZone = decisionState.bearishConsolidationZones[idx];
|
|
}
|
|
}
|
|
|
|
//
|
|
// 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 ...
|
|
bool handleStoptrailingBasedOnConsolidationZones = true;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XPosition iPosition = ownPositions[i];
|
|
|
|
//
|
|
bool isLong = IsLong(iPosition.type);
|
|
bool isInProfit = iPosition.profit > 0;
|
|
|
|
//
|
|
double sl = iPosition.sl;
|
|
double tp = iPosition.tp;
|
|
|
|
//
|
|
// Trail Stops Using Consolidation Zones ...
|
|
|
|
//
|
|
bool canTraiLonglUsingCZone =
|
|
//
|
|
handleStoptrailingBasedOnConsolidationZones &&
|
|
//
|
|
(isLong &&
|
|
isInProfit &&
|
|
hasBullishConsolidationZone &&
|
|
bullishConsolidationZone.lower > iPosition.sl &&
|
|
bullishConsolidationZone.lower > iPosition.entry)
|
|
//
|
|
;
|
|
if (canTraiLonglUsingCZone)
|
|
{
|
|
sl = bullishConsolidationZone.lower;
|
|
}
|
|
|
|
//
|
|
bool canTraiShortlUsingCZone =
|
|
//
|
|
handleStoptrailingBasedOnConsolidationZones &&
|
|
//
|
|
(!isLong &&
|
|
isInProfit &&
|
|
hasBearishConsolidationZone &&
|
|
bearishConsolidationZone.upper < iPosition.sl &&
|
|
bearishConsolidationZone.upper < iPosition.entry)
|
|
//
|
|
;
|
|
if (canTraiShortlUsingCZone)
|
|
{
|
|
sl = bearishConsolidationZone.upper;
|
|
}
|
|
|
|
//
|
|
bool canTrailUsingCZone =
|
|
canTraiLonglUsingCZone ||
|
|
canTraiShortlUsingCZone;
|
|
|
|
//
|
|
bool isSLPassed =
|
|
sl > 0 &&
|
|
(isLong
|
|
? iPosition.price - sl >= points * 15
|
|
: sl - iPosition.price >= points * 15);
|
|
|
|
//
|
|
bool canTrail =
|
|
isSLPassed &&
|
|
canTrailUsingCZone;
|
|
if (canTrail)
|
|
{
|
|
//
|
|
X121SMCGuard iGuard;
|
|
|
|
//
|
|
iGuard.time = cTime;
|
|
iGuard.symbol = symbol;
|
|
iGuard.provider = provider;
|
|
iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP;
|
|
|
|
//
|
|
iGuard.ticket = iPosition.ticket;
|
|
|
|
//
|
|
iGuard.sl = sl;
|
|
|
|
//
|
|
AddGuard(
|
|
iGuard,
|
|
guards //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
// 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);
|
|
|
|
//
|
|
visionState.Clean();
|
|
analyseState.Clean();
|
|
decisionState.Clean();
|
|
consolidationState.Clean();
|
|
|
|
//
|
|
visionConditions.Clean();
|
|
analyseConditions.Clean();
|
|
decisionConditions.Clean();
|
|
consolidationConditions.Clean();
|
|
|
|
//
|
|
visionXConditions.Clean();
|
|
analyseXConditions.Clean();
|
|
decisionXConditions.Clean();
|
|
consolidationXConditions.Clean();
|
|
|
|
//
|
|
Clean(visionPoiEvents);
|
|
Clean(analysePoiEvents);
|
|
Clean(decisionPoiEvents);
|
|
Clean(consolidationPoiEvents);
|
|
|
|
//
|
|
Clean(visionCycleEvents);
|
|
Clean(analyseCycleEvents);
|
|
Clean(decisionCycleEvents);
|
|
Clean(consolidationCycleEvents);
|
|
|
|
//
|
|
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 DrawBar(
|
|
XOHCL &bar,
|
|
XCPOIDrawer *drawer,
|
|
bool forceClean = true //
|
|
)
|
|
{
|
|
//
|
|
if (forceClean)
|
|
{
|
|
mBarObjects.Clear();
|
|
}
|
|
|
|
//
|
|
if (drawer == NULL ||
|
|
!bar.IsValid())
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
bool isBullish = bar.IsBullish();
|
|
|
|
//
|
|
int widthBar = 2;
|
|
bool fillShadowsBar = true;
|
|
ENUM_LINE_STYLE styleBar = STYLE_SOLID;
|
|
color clrBar =
|
|
isBullish
|
|
? clrAqua
|
|
: clrMagenta;
|
|
|
|
//
|
|
datetime to = bar.NextAt();
|
|
|
|
//
|
|
XCOHCLObject *iObj;
|
|
bool isCreated = drawer
|
|
.CreateBar(
|
|
bar,
|
|
iObj,
|
|
to //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
iObj.BarSpes(
|
|
widthBar,
|
|
clrBar,
|
|
styleBar //
|
|
);
|
|
|
|
//
|
|
iObj.LowShadowFill(fillShadowsBar);
|
|
iObj.HighShadowFill(fillShadowsBar);
|
|
|
|
//
|
|
mBarObjects.Add(iObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
protected:
|
|
//
|
|
|
|
//
|
|
private:
|
|
//
|
|
// Props ...
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
CArrayObj mObjects;
|
|
CArrayObj mBarObjects;
|
|
CArrayObj mWorkingZoneObjects;
|
|
|
|
/**
|
|
* Initialize ...
|
|
*/
|
|
void Init()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* DeInitialize ...
|
|
*/
|
|
void DeInit()
|
|
{
|
|
//
|
|
mConditions.Clean();
|
|
workingZone.Clean();
|
|
Clean(mConditionsCollection);
|
|
|
|
//
|
|
mBarObjects.Clear();
|
|
}
|
|
|
|
/**
|
|
* Update To Time of Exists Components ...
|
|
*
|
|
* @param value: updated time ...
|
|
*/
|
|
void UpdateTo(
|
|
datetime value = NULL //
|
|
)
|
|
{
|
|
//
|
|
value = NormalizeTime(value);
|
|
|
|
//
|
|
workingZone.UpdateTo(value);
|
|
}
|
|
|
|
//
|
|
// 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;
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
// |