This commit is contained in:
2025-01-26 20:10:44 +03:30
parent fdbc2e9361
commit 974a516bec
10 changed files with 4144 additions and 161 deletions
@@ -572,7 +572,7 @@ class XC121SMCCycleHelper : public XCBase
/**
* Detect Order Blocks ...
*
* @return ( int )
* @return ( bool )
*/
bool DetectOrderBlocks(
XCOrderBlock *&bullishOrderBlocks[],
@@ -597,14 +597,14 @@ class XC121SMCCycleHelper : public XCBase
}
//
int bullOBsCount = DetectDirectionOrderBlocks(
int bullOBsCount = DetectValidOrderBlocks(
X_DIRECTION_BULLISH,
state,
bullishOrderBlocks //
);
//
int bearOBsCount = DetectDirectionOrderBlocks(
int bearOBsCount = DetectValidOrderBlocks(
X_DIRECTION_BEARISH,
state,
bearishOrderBlocks //
@@ -618,6 +618,611 @@ class XC121SMCCycleHelper : public XCBase
return result;
}
/**
* Detect Fair Value Gaps ...
*
* @return ( bool )
*/
bool DetectFairValueGaps(
XCFVG *&bullishFairValueGaps[],
XCFVG *&bearishFairValueGaps[] //
)
{
//
bool result = false;
//
Clean(bullishFairValueGaps);
Clean(bearishFairValueGaps);
//
XPOIState state;
mPOIDetector.GetState(state);
bool isValid = state.IsValid() &&
state.HasChild();
if (!isValid)
{
return result;
}
//
int bullFVGsCount = DetectValidFairValueGaps(
X_DIRECTION_BULLISH,
state,
bullishFairValueGaps //
);
//
int bearFVGsCount = DetectValidFairValueGaps(
X_DIRECTION_BEARISH,
state,
bearishFairValueGaps //
);
//
result = IsValidSize(bullFVGsCount +
bearFVGsCount);
//
return result;
}
/**
* Detect Support Zones ...
*
* @return ( bool )
*/
bool DetectSupportZones(
XCOrderBlock *&bullishOrderBlocks[],
XCFVG *&bullishFairValueGaps[],
XCSupportZone *&supportZones[] //
)
{
//
bool result = false;
//
Clean(supportZones);
//
int obsCount = ArraySize(bullishOrderBlocks);
int fvgsCount = ArraySize(bullishFairValueGaps);
//
XPOIState state;
mPOIDetector.GetState(state);
bool isValid = state.IsValid() &&
state.HasChild() &&
IsValidSize(obsCount + fvgsCount);
if (!isValid)
{
return result;
}
//
int supportZonesCount = DetectValidSupportZones(
state,
bullishOrderBlocks,
bullishFairValueGaps,
supportZones //
);
//
result = IsValidSize(supportZonesCount);
//
return result;
}
/**
* Detect Resistance Zones ...
*
* @return ( bool )
*/
bool DetectResistanceZones(
XCOrderBlock *&bearishOrderBlocks[],
XCFVG *&bearishFairValueGaps[],
XCResistanceZone *&resistanceZones[] //
)
{
//
bool result = false;
//
Clean(resistanceZones);
//
int obsCount = ArraySize(bearishOrderBlocks);
int fvgsCount = ArraySize(bearishFairValueGaps);
//
XPOIState state;
mPOIDetector.GetState(state);
bool isValid = state.IsValid() &&
state.HasChild() &&
IsValidSize(obsCount + fvgsCount);
if (!isValid)
{
return result;
}
//
int resistanceZonesCount = DetectValidResistanceZones(
state,
bearishOrderBlocks,
bearishFairValueGaps,
resistanceZones //
);
//
result = IsValidSize(resistanceZonesCount);
//
return result;
}
/**
* Detect Demand Zones ...
*
* @return ( bool )
*/
bool DetectDemandZones(
XCOrderBlock *&bullishOrderBlocks[],
XCFVG *&bullishFairValueGaps[],
XCDemandZone *&demandZones[] //
)
{
//
bool result = false;
//
Clean(demandZones);
//
int obsCount = ArraySize(bullishOrderBlocks);
int fvgsCount = ArraySize(bullishFairValueGaps);
//
XPOIState state;
mPOIDetector.GetState(state);
bool isValid = state.IsValid() &&
state.HasChild() &&
IsValidSize(obsCount + fvgsCount);
if (!isValid)
{
return result;
}
//
int demandZonesCount = DetectValidDemandZones(
state,
bullishOrderBlocks,
bullishFairValueGaps,
demandZones //
);
//
result = IsValidSize(demandZonesCount);
//
return result;
}
/**
* Detect Supply Zones ...
*
* @return ( bool )
*/
bool DetectSupplyZones(
XCOrderBlock *&bearishOrderBlocks[],
XCFVG *&bearishFairValueGaps[],
XCSupplyZone *&supplyZones[] //
)
{
//
bool result = false;
//
Clean(supplyZones);
//
int obsCount = ArraySize(bearishOrderBlocks);
int fvgsCount = ArraySize(bearishFairValueGaps);
//
XPOIState state;
mPOIDetector.GetState(state);
bool isValid = state.IsValid() &&
state.HasChild() &&
IsValidSize(obsCount + fvgsCount);
if (!isValid)
{
return result;
}
//
int supplyZonesCount = DetectValidSupplyZones(
state,
bearishOrderBlocks,
bearishFairValueGaps,
supplyZones //
);
//
result = IsValidSize(supplyZonesCount);
//
return result;
}
/**
* Get Cycle State and Update it ...
*
* @param state: X121SMCCycleState instance Reference ...
*
* @return ( bool )
*/
bool GetCycleState(X121SMCCycleState &state)
{
//
bool result = false;
//
string symbol = GetSymbol();
ENUM_TIMEFRAMES period = GetPeriod();
//
state.symbol = symbol;
state.period = period;
//
datetime cTime = TimeCurrent();
//
// Detect Order Block ...
//
bool hasBullishOBs = state.HasBullishOBs();
int bullishOBsCount = state.CountBullishOBs();
//
bool hasBearishOBs = state.HasBearishOBs();
int bearishOBsCount = state.CountBearishOBs();
//
bool hasOBs = hasBullishOBs &&
hasBearishOBs;
if (!hasOBs)
{
//
XCOrderBlock *bullishOBs[];
XCOrderBlock *bearishOBs[];
hasOBs = DetectOrderBlocks(
bullishOBs,
bearishOBs //
);
//
if (hasOBs &&
!hasBullishOBs)
{
//
Copy(
bullishOBs,
state.bullishOBs //
);
}
//
if (hasOBs &&
!hasBearishOBs)
{
//
Copy(
bearishOBs,
state.bearishOBs //
);
}
//
hasBullishOBs = state.HasBullishOBs();
bullishOBsCount = state.CountBullishOBs();
//
hasBearishOBs = state.HasBearishOBs();
bearishOBsCount = state.CountBearishOBs();
}
//
// Update Order Blocks Time ...
if (hasOBs)
{
//
if (hasBullishOBs)
{
//
for (int i = 0; i < bullishOBsCount; i++)
{
state.bullishOBs[i].To(cTime);
}
}
//
if (hasBearishOBs)
{
//
for (int i = 0; i < bearishOBsCount; i++)
{
state.bearishOBs[i].To(cTime);
}
}
}
//
// Detect Fair Value Gap ...
//
bool hasBullishFVGs = state.HasBullishFVGs();
int bullishFVGsCount = state.CountBullishFVGs();
//
bool hasBearishFVGs = state.HasBearishFVGs();
int bearishFVGsCount = state.CountBearishFVGs();
//
bool hasFVGs = hasBullishFVGs &&
hasBearishFVGs;
if (!hasFVGs)
{
//
XCFVG *bullishFVGs[];
XCFVG *bearishFVGs[];
hasFVGs = DetectFairValueGaps(
bullishFVGs,
bearishFVGs //
);
//
if (hasFVGs &&
!hasBullishFVGs)
{
//
Copy(
bullishFVGs,
state.bullishFVGs //
);
}
//
if (hasFVGs &&
!hasBearishFVGs)
{
//
Copy(
bearishFVGs,
state.bearishFVGs //
);
}
//
hasBullishFVGs = state.HasBullishFVGs();
bullishFVGsCount = state.CountBullishFVGs();
//
hasBearishFVGs = state.HasBearishFVGs();
bearishFVGsCount = state.CountBearishFVGs();
}
//
// Update Fair Value Gaps Time ...
if (hasFVGs)
{
//
if (hasBullishFVGs)
{
//
for (int i = 0; i < bullishFVGsCount; i++)
{
state.bullishFVGs[i].To(cTime);
}
}
//
if (hasBearishFVGs)
{
//
for (int i = 0; i < bearishFVGsCount; i++)
{
state.bearishFVGs[i].To(cTime);
}
}
}
//
// Detect Support Zones ...
//
bool hasSupportZones = state.HasSupportZones();
int supportZonesCount = state.CountSupportZones();
//
if (!hasSupportZones)
{
//
XCSupportZone *supportZones[];
hasSupportZones = DetectSupportZones(
state.bullishOBs,
state.bullishFVGs,
supportZones //
);
//
if (hasSupportZones)
{
//
Copy(
supportZones,
state.supportZones //
);
//
supportZonesCount = state.CountSupportZones();
}
}
//
// Update Support Zones Time ...
if (hasSupportZones)
{
//
for (int i = 0; i < supportZonesCount; i++)
{
state.supportZones[i].To(cTime);
}
}
//
// Detect Demand Zones ...
//
bool hasDemandZones = state.HasDemandZones();
int demandZonesCount = state.CountDemandZones();
//
if (!hasDemandZones)
{
//
XCDemandZone *demandZones[];
hasDemandZones = DetectDemandZones(
state.bullishOBs,
state.bullishFVGs,
demandZones //
);
//
if (hasDemandZones)
{
//
Copy(
demandZones,
state.demandZones //
);
//
demandZonesCount = state.CountDemandZones();
}
}
//
// Update Support Zones Time ...
if (hasDemandZones)
{
//
for (int i = 0; i < demandZonesCount; i++)
{
state.demandZones[i].To(cTime);
}
}
//
// Detect Resistance Zones ...
//
bool hasResistanceZones = state.HasResistanceZones();
int resistanceZonesCount = state.CountResistanceZones();
//
if (!hasResistanceZones)
{
//
XCResistanceZone *resistanceZones[];
hasResistanceZones = DetectResistanceZones(
state.bearishOBs,
state.bearishFVGs,
resistanceZones //
);
//
if (hasResistanceZones)
{
//
for (int i = 0; i < ArraySize(resistanceZones); i++)
{
resistanceZones[i].To(cTime);
}
//
Copy(
resistanceZones,
state.resistanceZones //
);
//
resistanceZonesCount = state.CountResistanceZones();
}
}
//
// Update Resistance Zones Time ...
if (hasResistanceZones)
{
//
for (int i = 0; i < resistanceZonesCount; i++)
{
state.resistanceZones[i].To(cTime);
}
}
//
// Detect Supply Zones ...
//
bool hasSupplyZones = state.HasSupplyZones();
int supplyZonesCount = state.CountSupplyZones();
//
if (!hasSupplyZones)
{
//
XCSupplyZone *supplyZones[];
hasSupplyZones = DetectSupplyZones(
state.bearishOBs,
state.bearishFVGs,
supplyZones //
);
//
if (hasSupplyZones)
{
//
Copy(
supplyZones,
state.supplyZones //
);
//
supplyZonesCount = state.CountSupplyZones();
}
}
//
// Update Resistance Zones Time ...
if (hasSupplyZones)
{
//
for (int i = 0; i < supplyZonesCount; i++)
{
state.supplyZones[i].To(cTime);
}
}
//
result = state.IsValid();
//
return result;
}
/**
* Retrieve Cycle Conditions ...
*
@@ -688,6 +1293,288 @@ class XC121SMCCycleHelper : public XCBase
//
// Tools ...
/**
* Draw Cycle State ...
*
* @param state: X121SMCCyleState instance Reference ...
*
* @return ( int )
*/
int DrawCycleState(
X121SMCCycleState &state,
XCBaseObject *&drawnObjects[] //
)
{
//
int result = 0;
//
// Order Blocks ...
//
// Bullish ...
bool hasBullishOBs = state.HasBullishOBs();
int bullishOBsCount = state.CountBullishOBs();
if (hasBullishOBs)
{
//
for (int i = 0; i < bullishOBsCount; i++)
{
//
XCOrderBlock *iOb = state.bullishOBs[i];
//
XCBullishOrderBlockObject *iObObj;
bool isCreated = mPOIDrawer
.CreateBullishOrderBlock(
iOb,
iObObj //
);
if (isCreated)
{
//
Add(
(XCBaseObject *)iObObj,
drawnObjects //
);
}
}
}
//
// Bearish ...
bool hasBearishOBs = state.HasBearishOBs();
int bearishOBsCount = state.CountBearishOBs();
if (hasBearishOBs)
{
//
for (int i = 0; i < bearishOBsCount; i++)
{
//
XCOrderBlock *iOb = state.bearishOBs[i];
//
XCBearishOrderBlockObject *iObObj;
bool isCreated = mPOIDrawer
.CreateBearishOrderBlock(
iOb,
iObObj //
);
if (isCreated)
{
//
Add(
(XCBaseObject *)iObObj,
drawnObjects //
);
}
}
}
//
// Fair Value Gaps ...
//
// Bullish ...
bool hasBullishFVGs = state.HasBullishFVGs();
int bullishFVGsCount = state.CountBullishFVGs();
if (hasBullishFVGs)
{
//
for (int i = 0; i < bullishFVGsCount; i++)
{
//
XCFVG *iFVG = state.bullishFVGs[i];
//
XCBullishFairValueGapObject *iFVGObj;
bool isCreated = mPOIDrawer
.CreateBullishFairValueGap(
iFVG,
iFVGObj //
);
if (isCreated)
{
//
iFVGObj.ZoneColor(clrLime);
//
Add(
(XCBaseObject *)iFVGObj,
drawnObjects //
);
}
}
}
//
// Bearish ...
bool hasBearishFVGs = state.HasBearishFVGs();
int bearishFVGsCount = state.CountBearishFVGs();
if (hasBearishFVGs)
{
//
for (int i = 0; i < bearishFVGsCount; i++)
{
//
XCFVG *iFVG = state.bearishFVGs[i];
//
XCBearishFairValueGapObject *iFVGObj;
bool isCreated = mPOIDrawer
.CreateBearishFairValueGap(
iFVG,
iFVGObj //
);
if (isCreated)
{
//
iFVGObj.ZoneColor(clrRed);
//
Add(
(XCBaseObject *)iFVGObj,
drawnObjects //
);
}
}
}
//
// Support Zones ...
bool hasSupportZones = state.HasSupportZones();
int supportZonesCount = state.CountSupportZones();
if (hasSupportZones)
{
//
for (int i = 0; i < supportZonesCount; i++)
{
//
XCSupportZoneObject *iObj;
bool isCreated = mPOIDrawer
.CreateSupportZone(
state.supportZones[i],
iObj //
);
//
if (isCreated)
{
//
iObj.ZoneColor(clrDarkSeaGreen);
//
Add(
(XCBaseObject *)iObj,
drawnObjects //
);
}
}
}
//
// Resistance Zones ...
bool hasResistanceZones = state.HasResistanceZones();
int resistanceZonesCount = state.CountResistanceZones();
if (hasResistanceZones)
{
//
for (int i = 0; i < resistanceZonesCount; i++)
{
//
XCResistanceZoneObject *iObj;
bool isCreated = mPOIDrawer
.CreateResistanceZone(
state.resistanceZones[i],
iObj //
);
//
if (isCreated)
{
//
iObj.ZoneColor(clrSaddleBrown);
//
Add(
(XCBaseObject *)iObj,
drawnObjects //
);
}
}
}
//
// Demand Zones ...
bool hasDemandZones = state.HasDemandZones();
int demandZonesCount = state.CountDemandZones();
if (hasDemandZones)
{
//
for (int i = 0; i < demandZonesCount; i++)
{
//
XCDemandZoneObject *iObj;
bool isCreated = mPOIDrawer
.CreateDemandZone(
state.demandZones[i],
iObj //
);
//
if (isCreated)
{
//
iObj.ZoneColor(clrDarkTurquoise);
//
Add(
(XCBaseObject *)iObj,
drawnObjects //
);
}
}
}
//
// Supply Zones ...
bool hasSupplyZones = state.HasSupplyZones();
int supplyZonesCount = state.CountSupplyZones();
if (hasSupplyZones)
{
//
for (int i = 0; i < supplyZonesCount; i++)
{
//
XCSupplyZoneObject *iObj;
bool isCreated = mPOIDrawer
.CreateSupplyZone(
state.supplyZones[i],
iObj //
);
//
if (isCreated)
{
//
iObj.ZoneColor(clrChocolate);
//
Add(
(XCBaseObject *)iObj,
drawnObjects //
);
}
}
}
//
result = ArraySize(drawnObjects);
//
return result;
}
//
// Virtuals ...