Add Supports for Consolidation Range Founder ...

- [] required to Complete Supply and Demand Zone Retrieve in XConsolidation Zone Struct ...
This commit is contained in:
2024-12-11 02:14:37 +03:30
parent b5cec1f52a
commit a64430a28c
6 changed files with 1256 additions and 151 deletions
@@ -90,6 +90,33 @@ class XC121SMCCycleHelper : public XCBase
mMaxAllowedSavedChanges = value;
}
/**
* Get Consolidation Loopback Length ...
*
* @return ( int )
*/
int ConsolidationLoopback()
{
return mConsolidationLoopback;
}
/**
* Set Consolidation Loopback Length ...
*
* @param value: Integer ...
*/
void ConsolidationLoopback(int value)
{
//
if (value < 7)
{
value = 7;
}
//
mConsolidationLoopback = value;
}
//
// Actions ...
@@ -655,6 +682,231 @@ class XC121SMCCycleHelper : public XCBase
return result;
}
//
// Change Values Actions ...
/**
* Count Saved Parabolic Sar Changes ...
*
* @return ( int )
*/
int CountSarChanges()
{
return ArraySize(mSarChanges);
}
/**
* Fill Saved Sar Changes ...
*
* @param changes: XValueChange instance Array Reference ...
*
* @return ( int )
*/
int FillSarChanges(
XValueChange &changes[] //
)
{
//
Clean(changes);
//
Copy(
mSarChanges,
changes //
);
//
int result = ArraySize(changes);
//
return result;
}
/**
* Count Saved Peaks Changes ...
*
* @return ( int )
*/
int CountPeaksChanges()
{
return ArraySize(mPeaksChanges);
}
/**
* Fill Saved Peaks Changes ...
*
* @param changes: XValueChange instance Array Reference ...
*
* @return ( int )
*/
int FillPeaksChanges(
XValueChange &changes[] //
)
{
//
Clean(changes);
//
Copy(
mPeaksChanges,
changes //
);
//
int result = ArraySize(changes);
//
return result;
}
/**
* Count Saved Vales Changes ...
*
* @return ( int )
*/
int CountValesChanges()
{
return ArraySize(mValesChanges);
}
/**
* Fill Saved Vales Changes ...
*
* @param changes: XValueChange instance Array Reference ...
*
* @return ( int )
*/
int FillValesChanges(
XValueChange &changes[] //
)
{
//
Clean(changes);
//
Copy(
mValesChanges,
changes //
);
//
int result = ArraySize(changes);
//
return result;
}
/**
* Count Saved VWap Order Changes ...
*
* @return ( int )
*/
int CountVWapOrderChanges()
{
return ArraySize(mVWapOrderChanges);
}
/**
* Fill Saved VWap Order Changes ...
*
* @param changes: XValueChange instance Array Reference ...
*
* @return ( int )
*/
int FillVWapOrderChanges(
XValueChange &changes[] //
)
{
//
Clean(changes);
//
Copy(
mVWapOrderChanges,
changes //
);
//
int result = ArraySize(changes);
//
return result;
}
/**
* Count Saved VWap State Changes ...
*
* @return ( int )
*/
int CountVWapStateChanges()
{
return ArraySize(mVWapStateChanges);
}
/**
* Fill Saved VWap State Changes ...
*
* @param changes: XValueChange instance Array Reference ...
*
* @return ( int )
*/
int FillVWapStateChanges(
XValueChange &changes[] //
)
{
//
Clean(changes);
//
Copy(
mVWapStateChanges,
changes //
);
//
int result = ArraySize(changes);
//
return result;
}
/**
* Count Founded Consolidation Zones ...
*
* @return ( int )
*/
int CountConsolidationZones()
{
return ArraySize(mConsolidationZones);
}
/**
* Fill Broken Consolidations ...
*
* @param consolidations: XConsolidationZone instance Array Reference ...
*
* @return ( int )
*/
int FillConsolidations(
XConsolidationZone &consolidations[] //
)
{
//
Clean(consolidations);
//
Copy(
mConsolidationZones,
consolidations //
);
//
int result = ArraySize(consolidations);
//
return result;
}
//
// Virtuals ...
@@ -664,6 +916,7 @@ class XC121SMCCycleHelper : public XCBase
virtual void Default()
{
//
ConsolidationLoopback(15);
MaxAllowedSavedChanges(50);
}
@@ -709,48 +962,358 @@ class XC121SMCCycleHelper : public XCBase
isSarSwitchedToBearish;
//
if (period == PERIOD_M1)
if (isSarChanged)
{
//
if (isSarChanged)
XValueChange sarChanged;
//
datetime time = changeBar.time;
double after = conditions.x121Conditions.sarBuffer[1];
double before = conditions.x121Conditions.sarBuffer[2];
ENUM_X_DIRECTION dir =
isSarSwitchedToBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
// Initialize Model ...
isInited = sarChanged.Init(
before,
after,
dir,
time //
);
if (isInited)
{
//
XValueChange sarChanged;
//
datetime time = changeBar.time;
double after = conditions.x121Conditions.sarBuffer[1];
double before = conditions.x121Conditions.sarBuffer[2];
ENUM_X_DIRECTION dir =
isSarSwitchedToBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
// Initialize Model ...
isInited = sarChanged.Init(
before,
after,
dir,
time //
);
if (isInited)
{
//
isInited = AddSarChange(sarChanged);
if (isInited)
{
Print("Sar Switched ...");
}
}
isInited = AddSarChange(sarChanged);
}
}
//
// Detect Peak Changes ...
// Detect Peaks Changes ...
//
// Detect Vale Changes ...
bool isNewPeak = conditions.x121Conditions.isNewPeak;
bool isNewPeakOverLast = conditions.x121Conditions.isNewPeakOverLast;
bool isNewPeakUnderLast = conditions.x121Conditions.isNewPeakUnderLast;
//
if (isNewPeak)
{
//
XValueChange peaksChanged;
//
datetime time = changeBar.time;
double after = conditions.x121Conditions.peaksBuffer[1];
double before = conditions.x121Conditions.peaksBuffer[2];
ENUM_X_DIRECTION dir =
isNewPeakOverLast
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
// Initialize Model ...
isInited = peaksChanged.Init(
before,
after,
dir,
time //
);
if (isInited)
{
isInited = AddPeaksChange(peaksChanged);
}
}
//
// Detect Vales Changes ...
//
bool isNewVale = conditions.x121Conditions.isNewVale;
bool isNewValeOverLast = conditions.x121Conditions.isNewValeOverLast;
bool isNewValeUnderLast = conditions.x121Conditions.isNewValeUnderLast;
//
if (isNewVale)
{
//
XValueChange valesChanged;
//
datetime time = changeBar.time;
double after = conditions.x121Conditions.valesBuffer[1];
double before = conditions.x121Conditions.valesBuffer[2];
ENUM_X_DIRECTION dir =
isNewValeUnderLast
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
// Initialize Model ...
isInited = valesChanged.Init(
before,
after,
dir,
time //
);
if (isInited)
{
isInited = AddValesChange(valesChanged);
}
}
//
// VWap Direction Change ...
//
// Ordered Change ...
bool isVWapSwitchedToBullishOrdered =
conditions.x121Conditions.isVWapSwitchedToBullishOrdered;
bool isVWapSwitchedToBearishOrdered =
conditions.x121Conditions.isVWapSwitchedToBearishOrdered;
bool isVWAPOrderedChanged = isVWapSwitchedToBullishOrdered ||
isVWapSwitchedToBearishOrdered;
//
if (isVWAPOrderedChanged)
{
//
XValueChange vwapOrderChanged;
//
datetime time = changeBar.time;
ENUM_X_DIRECTION dir =
isVWapSwitchedToBullishOrdered
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
double after = 0;
double before = 0;
if (isVWapSwitchedToBullishOrdered)
{
//
// After Max ...
after = MathMax(
conditions.x121Conditions.vwapFastBuffer[1],
conditions.x121Conditions.vwapMidBuffer[1] //
);
after = MathMax(
after,
conditions.x121Conditions.vwapSlowBuffer[1] //
);
//
// Before Min ...
before = MathMin(
conditions.x121Conditions.vwapFastBuffer[1],
conditions.x121Conditions.vwapMidBuffer[1] //
);
before = MathMin(
before,
conditions.x121Conditions.vwapSlowBuffer[1] //
);
}
else
{
//
// After Min ...
after = MathMin(
conditions.x121Conditions.vwapFastBuffer[1],
conditions.x121Conditions.vwapMidBuffer[1] //
);
after = MathMin(
after,
conditions.x121Conditions.vwapSlowBuffer[1] //
);
//
// Before Max ...
before = MathMax(
conditions.x121Conditions.vwapFastBuffer[1],
conditions.x121Conditions.vwapMidBuffer[1] //
);
before = MathMax(
before,
conditions.x121Conditions.vwapSlowBuffer[1] //
);
}
//
// Initialize Model ...
isInited = vwapOrderChanged.Init(
before,
after,
dir,
time //
);
if (isInited)
{
isInited = AddVWapOrderChange(vwapOrderChanged);
}
}
//
// States Changed ...
bool isVWapSwitchedToBullishState =
conditions.x121Conditions.isVWapSwitchedToBullishState;
bool isVWapSwitchedToBearishState =
conditions.x121Conditions.isVWapSwitchedToBearishState;
bool isVWapStatesChanged = isVWapSwitchedToBullishState ||
isVWapSwitchedToBearishState;
//
if (isVWapStatesChanged)
{
//
XValueChange vwapStateChanged;
//
datetime time = changeBar.time;
ENUM_X_DIRECTION dir =
isVWapSwitchedToBullishState
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
double after = 0;
double before = 0;
if (isVWapSwitchedToBullishState)
{
//
// After Max ...
after = MathMax(
conditions.x121Conditions.vwapFastBuffer[1],
conditions.x121Conditions.vwapMidBuffer[1] //
);
after = MathMax(
after,
conditions.x121Conditions.vwapSlowBuffer[1] //
);
//
// Before Min ...
before = MathMin(
conditions.x121Conditions.vwapFastBuffer[1],
conditions.x121Conditions.vwapMidBuffer[1] //
);
before = MathMin(
before,
conditions.x121Conditions.vwapSlowBuffer[1] //
);
}
else
{
//
// After Min ...
after = MathMin(
conditions.x121Conditions.vwapFastBuffer[1],
conditions.x121Conditions.vwapMidBuffer[1] //
);
after = MathMin(
after,
conditions.x121Conditions.vwapSlowBuffer[1] //
);
//
// Before Max ...
before = MathMax(
conditions.x121Conditions.vwapFastBuffer[1],
conditions.x121Conditions.vwapMidBuffer[1] //
);
before = MathMax(
before,
conditions.x121Conditions.vwapSlowBuffer[1] //
);
}
//
// Initialize Model ...
isInited = vwapStateChanged.Init(
before,
after,
dir,
time //
);
if (isInited)
{
isInited = AddVWapStateChange(vwapStateChanged);
}
}
//
// Detect Consolidations ...
//
int consolidationLoopback = ConsolidationLoopback();
if (IsValidSize(consolidationLoopback))
{
//
double upper = 0;
double lower = 0;
bool hasConsolidation =
mBarAnalyser.IsConsolidate(
changeBar,
upper,
lower,
consolidationLoopback //
);
//
if (hasConsolidation &&
!mActioveConsolidationZone.IsValid())
{
//
// Initialize Consolidation Zone ...
bool isInited = mActioveConsolidationZone.Init(
changeBar.symbol,
changeBar.period,
upper,
lower,
consolidationLoopback //
);
}
//
if (!hasConsolidation &&
mActioveConsolidationZone.IsValid())
{
//
// Check Consolidation Breaks ...
// Update Zone ...
// Add it ...
bool isBOSTop = changeBar.high > mActioveConsolidationZone.upper;
bool isBOSBottom = changeBar.low < mActioveConsolidationZone.lower;
//
// Calculate Break Direction ...
ENUM_X_DIRECTION bosDir = isBOSTop
? X_DIRECTION_BULLISH
: isBOSBottom
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
//
// Update Actiove Zone ...
mActioveConsolidationZone.breakerBar = changeBar;
mActioveConsolidationZone.breakDirection = bosDir;
//
// Add Active to List ...
AddRef(
mActioveConsolidationZone,
mConsolidationZones //
);
//
// Clean Active Zone ...
mActioveConsolidationZone.Clean();
//
Print("Breake ...");
}
}
}
//
@@ -761,8 +1324,17 @@ class XC121SMCCycleHelper : public XCBase
//
// Change Holders ...
int mMaxAllowedSavedChanges; // Max llowed Changes to Save ...
XValueChange mSarChanges[]; // Holds Parabolic Sar Direction Changes ...
int mMaxAllowedSavedChanges; // Max llowed Changes to Save ...
XValueChange mSarChanges[]; // Holds Parabolic Sar Direction Changes ...
XValueChange mPeaksChanges[]; // Holds Peaks Changes ...
XValueChange mValesChanges[]; // Holds Vales Changes ...
XValueChange mVWapOrderChanges[]; // Holds Vales Changes ...
XValueChange mVWapStateChanges[]; // Holds Vales Changes ...
//
int mConsolidationLoopback; // Consolidation Loopback Length ...
XConsolidationZone mConsolidationZones[]; // Holds Consolidation Zones ...
XConsolidationZone mActioveConsolidationZone; // Holds Actiove Consolidation Zone ...
//
// Actions ...
@@ -870,16 +1442,6 @@ class XC121SMCCycleHelper : public XCBase
//
// Change Values Actions ...
/**
* Count Saved Parabolic Sar Changes ...
*
* @return ( int )
*/
int CountSarChanges()
{
return ArraySize(mSarChanges);
}
/**
* Add Specified Parabolic Sar Changed Item ...
*
@@ -928,5 +1490,197 @@ class XC121SMCCycleHelper : public XCBase
return result;
}
/**
* Add Specified Peaks Changed Item ...
*
* @param value: XValueChange instance Reference ...
*
* @return ( bool )
*/
bool AddPeaksChange(XValueChange &value)
{
//
bool result = false;
//
result = value.IsValid();
if (!result)
{
return result;
}
//
int beforeCount = CountSarChanges();
//
AddIfNotExists(
value,
mPeaksChanges //
);
//
int afterCount = CountSarChanges();
//
result = afterCount == beforeCount + 1;
if (result)
{
//
// Cleaning Up Unused Items ...
int maxAllowed = MaxAllowedSavedChanges();
CleanupArray(
mPeaksChanges,
maxAllowed //
);
}
//
return result;
}
/**
* Add Specified Vales Changed Item ...
*
* @param value: XValueChange instance Reference ...
*
* @return ( bool )
*/
bool AddValesChange(XValueChange &value)
{
//
bool result = false;
//
result = value.IsValid();
if (!result)
{
return result;
}
//
int beforeCount = CountSarChanges();
//
AddIfNotExists(
value,
mValesChanges //
);
//
int afterCount = CountSarChanges();
//
result = afterCount == beforeCount + 1;
if (result)
{
//
// Cleaning Up Unused Items ...
int maxAllowed = MaxAllowedSavedChanges();
CleanupArray(
mValesChanges,
maxAllowed //
);
}
//
return result;
}
/**
* Add Specified VWap Order Changed Item ...
*
* @param value: XValueChange instance Reference ...
*
* @return ( bool )
*/
bool AddVWapOrderChange(XValueChange &value)
{
//
bool result = false;
//
result = value.IsValid();
if (!result)
{
return result;
}
//
int beforeCount = CountSarChanges();
//
AddIfNotExists(
value,
mVWapOrderChanges //
);
//
int afterCount = CountSarChanges();
//
result = afterCount == beforeCount + 1;
if (result)
{
//
// Cleaning Up Unused Items ...
int maxAllowed = MaxAllowedSavedChanges();
CleanupArray(
mVWapOrderChanges,
maxAllowed //
);
}
//
return result;
}
/**
* Add Specified VWap State Changed Item ...
*
* @param value: XValueChange instance Reference ...
*
* @return ( bool )
*/
bool AddVWapStateChange(XValueChange &value)
{
//
bool result = false;
//
result = value.IsValid();
if (!result)
{
return result;
}
//
int beforeCount = CountSarChanges();
//
AddIfNotExists(
value,
mVWapStateChanges //
);
//
int afterCount = CountSarChanges();
//
result = afterCount == beforeCount + 1;
if (result)
{
//
// Cleaning Up Unused Items ...
int maxAllowed = MaxAllowedSavedChanges();
CleanupArray(
mVWapStateChanges,
maxAllowed //
);
}
//
return result;
}
//
};
+3
View File
@@ -637,6 +637,9 @@ struct X121SMCStrategyConditions
string provider;
ENUM_X_DIRECTION marketStructureDir;
//
//
void X121SMCStrategyConditions()
{
@@ -115,10 +115,12 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy
// Start Calculations ...
//
// Retrieve Common Data ...
string symbol = GetSymbol();
ENUM_TIMEFRAMES period = GetPeriod();
//
// Required Value For SL/TP Calculations ...
double points = GetPoints(symbol);
double pip = GetPipPrice(symbol);
double pip2 = 2 * pip;
@@ -466,54 +468,6 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy
double bid = GetBid(symbol);
datetime cTime = TimeCurrent();
// //
// // Detect Valid Supply and Demand Zones ...
// XCSupplyZone *supplyZone;
// XCDemandZone *demandZone;
// result = mTriggerCycleHelper
// .DetectValisSupplyZone(
// cBar,
// supplyZone,
// demandZone //
// );
// if (!result)
// {
// //
// conditions.Clean();
// return result;
// }
// //
// supplyZone.To(cTime);
// XCSupplyZoneObject *iSupplyZoneObj;
// result = mPOIDrawer.CreateSupplyZone(
// supplyZone,
// iSupplyZoneObj //
// );
// if (!result)
// {
// //
// conditions.Clean();
// return result;
// }
// //
// demandZone.To(cTime);
// XCDemandZoneObject *iDemandZoneObj;
// result = mPOIDrawer.CreateDemandZone(
// demandZone,
// iDemandZoneObj //
// );
// if (!result)
// {
// //
// conditions.Clean();
// return result;
// }
// //
// Print("Supply and Demand Zone Created ...");
//
if (!result)
{