This commit is contained in:
2025-02-04 03:33:59 +03:30
parent 6984b8365f
commit 7e32ebab82
20 changed files with 31271 additions and 12329 deletions
+303 -434
View File
@@ -26,6 +26,53 @@
#include "../Libraries/x-121.smc.guard.lib.mq5"
#include "../Libraries/x-121.smc.lib.mq5"
//
struct XOBTest
{
//
// Props ...
//
string symbol;
ENUM_TIMEFRAMES period;
//
XCOrderBlock *ob;
XCFVG *fvg;
//
datetime fvgActivatedAt;
datetime rewardedAt;
//
double reward;
//
// Constructor ...
XOBTest()
{
Clean();
}
//
// Tools ...
//
void Clean()
{
//
ob = NULL;
fvg = NULL;
symbol = NULL;
period = NULL;
rewardedAt = NULL;
fvgActivatedAt = NULL;
//
reward = 0;
}
};
//
// Definitions ...
struct X121SMCStrategyXOBSSignalConditions
@@ -56,18 +103,7 @@ struct X121SMCStrategyXOBSSignalConditions
//
// Extwnsion ...
//
datetime cOBAt;
XCOrderBlock *cOB;
bool isCOBActivated;
datetime cOBActivatedAt;
//
datetime aOBAt;
XCOrderBlock *aOB;
bool isAOBActivated;
datetime aOBActivatedAt;
XOBTest obTests[];
//
// Constructor ...
@@ -191,16 +227,7 @@ struct X121SMCStrategyXOBSSignalConditions
point = 0;
//
cOB = NULL;
cOBAt = NULL;
cOBActivatedAt = NULL;
isCOBActivated = false;
//
aOB = NULL;
aOBAt = NULL;
aOBActivatedAt = NULL;
isAOBActivated = false;
Clean(obTests);
}
//
@@ -434,84 +461,6 @@ bool DetectX121SMCXOBSSignalSetup(
//
// Setup Conditions ...
//
// Detect Trend ...
//
// Vision ...
ENUM_X_DIRECTION visionTrendDir;
bool hasVisionTrend =
visionCycleHelper
.DetectMarketStructure(
visionTrendDir //
);
bool hasVisionBullishTrend =
hasVisionTrend &&
IsBullish(visionTrendDir);
bool hasVisionBearishTrend =
hasVisionTrend &&
IsBearish(visionTrendDir);
//
// Consolidation ...
ENUM_X_DIRECTION consolidationTrendDir;
bool hasConsolidationTrend =
consolidationCycleHelper
.DetectMarketStructure(
consolidationTrendDir //
);
bool hasConsolidationBullishTrend =
hasConsolidationTrend &&
IsBullish(consolidationTrendDir);
bool hasConsolidationBearishTrend =
hasConsolidationTrend &&
IsBearish(consolidationTrendDir);
//
// Verification ...
ENUM_X_DIRECTION verificationTrendDir;
bool hasVerificationTrend =
verificationCycleHelper
.DetectMarketStructure(
verificationTrendDir //
);
bool hasVerificationBullishTrend =
hasVerificationTrend &&
IsBullish(verificationTrendDir);
bool hasVerificationBearishTrend =
hasVerificationTrend &&
IsBearish(verificationTrendDir);
//
// Analyse ...
ENUM_X_DIRECTION analyseTrendDir;
bool hasAnalyseTrend =
analyseCycleHelper
.DetectMarketStructure(
analyseTrendDir //
);
bool hasAnalyseBullishTrend =
hasAnalyseTrend &&
IsBullish(analyseTrendDir);
bool hasAnalyseBearishTrend =
hasAnalyseTrend &&
IsBearish(analyseTrendDir);
//
// Decision ...
ENUM_X_DIRECTION decisionTrendDir;
bool hasDecisionTrend =
decisionCycleHelper
.DetectMarketStructure(
decisionTrendDir //
);
bool hasDecisionBullishTrend =
hasDecisionTrend &&
IsBullish(decisionTrendDir);
bool hasDecisionBearishTrend =
hasDecisionTrend &&
IsBearish(decisionTrendDir);
//
// Detect Bar State ...
@@ -730,350 +679,36 @@ bool DetectX121SMCXOBSSignalSetup(
;
//
// Detect OrderBlocks ...
// Detect Order Flow ...
//
bool hasCOB =
conditions.cOB != NULL &&
conditions.cOB.IsValid() &&
IsValid(conditions.cOBAt);
//
if (!hasCOB)
// Test Market For Order Flow ...
int obTestsCount = ArraySize(conditions.obTests);
bool isOBTested = obTestsCount == 2;
if (!isOBTested)
{
//
int poiEvntsCount = ArraySize(consolidationPoiEvents);
bool hasEvent = IsValidSize(poiEvntsCount);
if (hasEvent)
XOBTest test;
bool hasTest = ReTestMarket(
test,
conditions.obTests,
consolidationState,
analyseState,
decisionState,
visionCycleHelper.mPOIDrawer //
);
if (hasTest)
{
//
bool hasNewBullOB = Contains(
X_BULLISH_ORDERBLOCK_DETECTED,
consolidationPoiEvents //
);
//
bool hasNewBearOB = Contains(
X_BEARISH_ORDERBLOCK_DETECTED,
consolidationPoiEvents //
);
//
bool hasNewOB =
hasNewBullOB ||
hasNewBearOB;
//
if (hasNewOB)
{
//
XCOrderBlock *ob = NULL;
if (hasNewBullOB)
{
//
int lastIDX = consolidationState.CountBullishOrderBlocks() - 1;
ob = consolidationState.bullishOrderBlocks[lastIDX];
//
// Validate OB ...
}
else if (hasNewBearOB)
{
//
int lastIDX = consolidationState.CountBearishOrderBlocks() - 1;
ob = consolidationState.bearishOrderBlocks[lastIDX];
//
// Validate OB ...
}
//
if (ob != NULL && ob.IsValid())
{
//
conditions.cOB = ob;
//
conditions.cOBAt = cTime;
//
hasCOB =
conditions.cOB != NULL &&
conditions.cOB.IsValid() &&
IsValid(conditions.cOBAt);
}
}
AddRef(
test,
conditions.obTests);
}
}
//
if (hasCOB)
{
conditions.cOB.To(cTime);
}
//
bool hasAOB =
conditions.aOB != NULL &&
conditions.aOB.IsValid() &&
IsValid(conditions.aOBAt);
//
if (hasCOB &&
!hasAOB)
{
//
int poiEvntsCount = ArraySize(analysePoiEvents);
bool hasEvent = IsValidSize(poiEvntsCount);
if (hasEvent)
{
//
bool hasNewBullOB = Contains(
X_BULLISH_ORDERBLOCK_DETECTED,
analysePoiEvents //
);
//
bool hasNewBearOB = Contains(
X_BEARISH_ORDERBLOCK_DETECTED,
analysePoiEvents //
);
//
bool hasNewOB =
hasNewBullOB ||
hasNewBearOB;
//
if (hasNewOB)
{
//
XCOrderBlock *ob = NULL;
if (hasNewBullOB)
{
//
int lastIDX = analyseState.CountBullishOrderBlocks() - 1;
ob = analyseState.bullishOrderBlocks[lastIDX];
//
// Validate OB ...
}
else if (hasNewBearOB)
{
//
int lastIDX = analyseState.CountBearishOrderBlocks() - 1;
ob = analyseState.bearishOrderBlocks[lastIDX];
//
// Validate OB ...
}
//
if (ob != NULL && ob.IsValid())
{
//
conditions.aOB = ob;
//
conditions.aOBAt = cTime;
//
hasAOB =
conditions.aOB != NULL &&
conditions.aOB.IsValid() &&
IsValid(conditions.aOBAt);
}
}
}
}
//
if (hasAOB)
{
conditions.aOB.To(cTime);
}
//
result = hasCOB &&
hasAOB;
if (!result)
{
return result;
}
//
// DRAW ...
//
//
// Draw Orer Block ...
bool isBullishCOB = conditions.cOB.IsBullish();
if (isBullishCOB)
{
//
XCBullishOrderBlockObject *iObj;
bool isCreated = consolidationCycleHelper
.mPOIDrawer
.CreateBullishOrderBlock(
conditions.cOB,
iObj //
);
}
else
{
//
XCBearishOrderBlockObject *iObj;
bool isCreated = consolidationCycleHelper
.mPOIDrawer
.CreateBearishOrderBlock(
conditions.cOB,
iObj //
);
}
bool isBullishAOB = conditions.aOB.IsBullish();
if (isBullishAOB)
{
//
XCBullishOrderBlockObject *iObj;
bool isCreated = analyseCycleHelper
.mPOIDrawer
.CreateBullishOrderBlock(
conditions.aOB,
iObj //
);
}
else
{
//
XCBearishOrderBlockObject *iObj;
bool isCreated = analyseCycleHelper
.mPOIDrawer
.CreateBearishOrderBlock(
conditions.aOB,
iObj //
);
}
//
// Draw From Bar ...
XOHCL cOBFromBar;
bool hasCOBFromBar = cOBFromBar.Init(
conditions.cOB.GetSymbol(),
conditions.cOB.GetPeriod(),
conditions.cOB.From() //
);
if (hasCOBFromBar)
{
//
XCOHCLObject *barObject;
bool iCreated = consolidationCycleHelper
.mPOIDrawer
.CreateBar(
cOBFromBar,
barObject //
);
}
//
// Draw From Bar ...
XOHCL aOBFromBar;
bool hasAOBFromBar = aOBFromBar.Init(
conditions.aOB.GetSymbol(),
conditions.aOB.GetPeriod(),
conditions.aOB.From() //
);
if (hasAOBFromBar)
{
//
XCOHCLObject *barObject;
bool iCreated = analyseCycleHelper
.mPOIDrawer
.CreateBar(
aOBFromBar,
barObject //
);
}
//
// END DRAW ...
//
//
// Check AOB Activation ...
if (!conditions.isAOBActivated)
{
//
int aPeakRepetition = analyseCycleHelper.CountPrevPeakRepetition();
int aValeRepetition = analyseCycleHelper.CountPrevValeRepetition();
//
bool isActivated =
//
bid >= conditions.aOB.Lower() &&
bid <= conditions.aOB.Upper() &&
//
cBar.low >= conditions.aOB.Lower() &&
cBar.high <= conditions.aOB.Upper() &&
//
(conditions.aOB.IsBullish()
? decisionXConditions.valesBuffer[1] >= conditions.aOB.Lower() &&
decisionXConditions.valesBuffer[1] <= conditions.aOB.Upper()
: decisionXConditions.peaksBuffer[1] >= conditions.aOB.Lower() &&
decisionXConditions.peaksBuffer[1] <= conditions.aOB.Upper())
//
;
//
if (isActivated)
{
//
conditions.aOBActivatedAt = cTime;
conditions.isAOBActivated = isActivated;
}
}
//
// Check COB Activation ...
if (!conditions.isCOBActivated)
{
//
int aPeakRepetition = analyseCycleHelper.CountPrevPeakRepetition();
int aValeRepetition = analyseCycleHelper.CountPrevValeRepetition();
//
bool isActivated =
//
bid >= conditions.cOB.Lower() &&
bid <= conditions.cOB.Upper() &&
//
cBar.low >= conditions.cOB.Lower() &&
cBar.high <= conditions.cOB.Upper() &&
//
(conditions.cOB.IsBullish()
? decisionXConditions.valesBuffer[1] >= conditions.cOB.Lower() &&
decisionXConditions.valesBuffer[1] <= conditions.cOB.Upper()
: decisionXConditions.peaksBuffer[1] >= conditions.cOB.Lower() &&
decisionXConditions.peaksBuffer[1] <= conditions.cOB.Upper())
//
;
//
if (isActivated)
{
//
conditions.cOBActivatedAt = cTime;
conditions.isCOBActivated = isActivated;
}
}
//
result = conditions.isAOBActivated ||
conditions.isCOBActivated;
if (!result)
{
return result;
}
// TODO:
return false;
//
double upper = 0;
@@ -1607,3 +1242,237 @@ int AddX121SMCXOBSConditionsIfNotExists(
}
//
//
//
/**
* Retest Market ...
*
* @param test: XOBTest instance Reference, Represet Result Test ...
* @param tests: XOBTest instance Reference Collection, Represet Founded Tests till now ...
* @param htfState: XPOIState instance Reference ...
* @param mtfState: XPOIState instance Reference ...
* @param ttfState: XPOIState instance Reference ...
*
* @return ( bool )
*/
bool ReTestMarket(
XOBTest &test,
XOBTest &tests[],
XPOIState &htfState,
XPOIState &mtfState,
XPOIState &ttfState, //
//
XCPOIDrawer *drawer
//
)
{
//
bool result = false;
//
test.Clean();
//
int testsCount = ArraySize(tests);
bool hasTests = IsValidSize(testsCount);
XOBTest lastTest;
if (hasTests)
{
lastTest = tests[testsCount - 1];
}
//
// Detect Order Blocks ...
// HTF ...
//
// Bullish OBs ...
XCOrderBlock *bullOBs[];
bool hasYoungestBullOB = false;
XCOrderBlock *youngestBullOB = NULL;
int bullOBsCount = ExtractUnActivatedOBs(
htfState.bullishOrderBlocks,
bullOBs //
);
//
bool isBullOBsPassed = bullOBsCount >= 1;
if (isBullOBsPassed)
{
//
XBoxZone boxes[];
int boxesCount = ToBox(
bullOBs,
boxes //
);
int youngestBoxIDX = GetYoungest(boxes);
hasYoungestBullOB = IsValidIndex(youngestBoxIDX);
if (hasYoungestBullOB)
{
youngestBullOB = bullOBs[youngestBoxIDX];
}
}
//
// Bearish OBs ...
XCOrderBlock *bearOBs[];
bool hasYoungestBearOB = false;
XCOrderBlock *youngestBearOB = NULL;
int bearOBsCount = ExtractUnActivatedOBs(
htfState.bearishOrderBlocks,
bearOBs //
);
//
bool isBearOBsPassed = bearOBsCount >= 1;
if (isBearOBsPassed)
{
//
XBoxZone boxes[];
int boxesCount = ToBox(
bearOBs,
boxes //
);
int youngestBoxIDX = GetYoungest(boxes);
hasYoungestBearOB = IsValidIndex(youngestBoxIDX);
if (hasYoungestBearOB)
{
youngestBearOB = bearOBs[youngestBoxIDX];
}
}
//
result = isBullOBsPassed ||
isBearOBsPassed;
if (!result)
{
return result;
}
//
// DRAW ...
//
//
XCBaseObject *drawnObjects[];
//
if (hasYoungestBullOB)
{
//
XCBullishOrderBlockObject *iObj;
bool isCreated = drawer
.CreateBullishOrderBlock(
youngestBullOB,
iObj //
);
//
if (isCreated)
{
//
Add(
(XCBaseObject *)iObj,
drawnObjects //
);
}
}
//
if (hasYoungestBearOB)
{
//
XCBearishOrderBlockObject *iObj;
bool isCreated = drawer
.CreateBearishOrderBlock(
youngestBearOB,
iObj //
);
//
if (isCreated)
{
//
Add(
(XCBaseObject *)iObj,
drawnObjects //
);
}
}
//
// END DRAW ...
//
//
Print("OBs Passed ...");
//
return result;
}
/**
* Extract UnActivated Order Blocks ...
*
* @return ( int )
*/
int ExtractUnActivatedOBs(
XCOrderBlock *&source[],
XCOrderBlock *&obs[] //
)
{
//
int result = 0;
//
Clean(obs);
//
int count = ArraySize(source);
bool hasOB = IsValidSize(count);
if (!hasOB)
{
return result;
}
//
for (int i = 0; i < count; i++)
{
//
bool isBullish = source[i].IsBullish();
ENUM_X_DIRECTION forDir =
isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
//
//
//
XOHCL activatedBar;
ENUM_X_DIRECTION activatedDir;
bool isActivated = source[i].IsActivated(
forDir,
activatedBar,
activatedDir //
);
if (!isActivated)
{
//
Add(
source[i],
obs //
);
}
}
//
result = ArraySize(obs);
//
return result;
}
//