This commit is contained in:
2025-03-11 01:42:32 +03:30
parent d00dcf9ca0
commit f952cd1d93
6 changed files with 1311 additions and 124 deletions
@@ -54,6 +54,21 @@ string ToString(ENUM_X_CYCLES value)
return result;
}
bool IsValid(ENUM_X_CYCLES value)
{
//
bool result = false;
//
result =
value != X_CYCLE_NONE ||
value != X_CYCLE_TRIGGER ||
value != X_CYCLE_VERIFICATION;
//
return result;
}
enum ENUM_X_CYCLE_EVENTS
{
SAR_CHANGE_DETECTED,
@@ -584,6 +599,224 @@ class XC121SMCCycleHelper : public XCBase
return result;
}
//
int DetectRejections(
XBoxZone &rejections[],
int barIndex = 0,
bool forceBarType = true,
bool forceFiboPressure = true,
bool forceUnUsedRejections = true,
int maxAllowedLoopback = 587 //
)
{
//
int result = 0;
//
// Normalize Args ...
Clean(rejections);
//
if (barIndex < 0)
{
barIndex = 0;
}
//
int idx = -1;
bool has = false;
for (int i = barIndex + 1; i < barIndex + maxAllowedLoopback; i++)
{
//
// Init Indexed Bar ...
XOHCL iBar;
XOHCL iCBar;
XOHCL iPBar;
has = GetBar(iBar, i);
has =
has &&
iBar.GetPreviousBar(iCBar);
has =
has &&
iCBar.GetPreviousBar(iPBar);
if (!has)
{
//
iBar.Clean();
iCBar.Clean();
iPBar.Clean();
break;
}
//
// Check CBar Bullish Fibo Pressure ...
bool cBarHasBullishFiboPressure =
mBarAnalyser
.HasFiboPressure(
iCBar,
X_DIRECTION_BULLISH,
X_FIBO_LEVEL_382 //
);
//
// Check CBar Bearish Fibo Pressure ...
bool cBarHasBearishFiboPressure =
mBarAnalyser
.HasFiboPressure(
iCBar,
X_DIRECTION_BEARISH,
X_FIBO_LEVEL_382 //
);
//
// Check Bar is Bullish Rejection Swing ...
bool isBullishRejection =
//
iCBar.low < iBar.low &&
iCBar.low < iPBar.low &&
//
iCBar.low < iCBar.GetDown() &&
iCBar.GetLowShadow() > iCBar.GetBody() &&
iCBar.GetLowShadow() > iCBar.GetHighShadow()
//
;
//
// Check Bar is Bearish Rejection Swing ...
bool isBearishRejection =
//
iCBar.high > iBar.high &&
iCBar.high > iPBar.high &&
//
iCBar.high > iCBar.GetUp() &&
iCBar.GetHighShadow() > iCBar.GetBody() &&
iCBar.GetHighShadow() > iCBar.GetLowShadow()
//
;
//
// Apply Fibo Pressure ...
if (forceFiboPressure)
{
//
isBullishRejection =
isBullishRejection &&
cBarHasBullishFiboPressure;
//
isBearishRejection =
isBearishRejection &&
cBarHasBearishFiboPressure;
}
//
// Apply Force Bar Type ...
if (forceBarType)
{
//
isBullishRejection =
isBullishRejection &&
iCBar.IsBullish();
//
isBearishRejection =
isBearishRejection &&
iCBar.IsBearish();
}
//
// Summarize Result ...
has = isBullishRejection ||
isBearishRejection;
if (has)
{
//
XBoxZone iBox;
//
iBox.to = iBar.time;
iBox.from = iCBar.time;
iBox.period = iBar.period;
iBox.symbol = iBar.symbol;
//
iBox.dir =
isBullishRejection
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
iBox.upper =
isBullishRejection
? iCBar.GetDown()
: iCBar.high;
//
iBox.lower =
isBullishRejection
? iCBar.low
: iCBar.GetUp();
//
iBox.type =
isBullishRejection
? "XSwingLow"
: "XSwingHigh";
//
// Validate Box ...
has = iBox.IsValid();
if (has)
{
//
// Apply Force Unused Rejections ...
if (forceUnUsedRejections)
{
//
has = !IsBoxBreaked(
iBox,
iCBar.Index() + 1,
barIndex //
);
}
//
if (has)
{
//
idx = FindIndex(
iBox,
rejections //
);
has = !IsValidIndex(idx);
if (has)
{
//
AddRef(
iBox,
rejections //
);
}
}
}
//
iBox.Clean();
}
//
iBar.Clean();
iCBar.Clean();
iPBar.Clean();
}
//
result = ArraySize(rejections);
//
return result;
}
//
// Virtuals ...
@@ -638,7 +871,7 @@ class XC121SMCCycleHelper : public XCBase
bool mShowBidLine = true; // show bid line
bool mShowAskLine = true; // show ask line
bool mShowGrid = false; // show grids on chart
bool mShowVolumes = false; // show volumes
bool mShowVolumes = true; // show volumes
bool mShowTradeLevels = true; // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders)
bool mAutoScroll = true; // chart autoscroll
bool mQuickNavigation = true; // chart quick navigation state
@@ -2676,5 +2909,262 @@ struct X121SMCStrategyConditionParser
return result;
}
//
bool HasSenario2Conditions(
ENUM_X_CYCLES ttfCycle,
ENUM_X_DIRECTION trend,
XBoxZone &unavailableBoxes[],
XBoxZone &box,
ENUM_X_DIRECTION &dir,
X121SMCStrategySignalProviderData &provider,
int barIndex = 0 //
)
{
//
bool result = false;
//
// Validate Args ...
result =
IsValid(ttfCycle) &&
HasDirection(trend) &&
HasChild(unavailableBoxes);
if (!result)
{
return result;
}
//
bool hasBullishTrend = IsBullish(trend);
bool hasBearishTrend = IsBearish(trend);
//
// TTF Cycle Extract ...
XPOIState ttfState;
X121Conditions ttfXConditions;
XC121SMCCycleHelper *ttfHelper;
X121SMCCycleConditions ttfConditions;
result = provider.SelectCycle(
ttfCycle,
ttfState,
ttfXConditions,
ttfHelper,
ttfConditions //
);
if (!result)
{
//
ttfState.Clean();
ZeroMemory(ttfHelper);
ttfConditions.Clean();
ttfXConditions.Clean();
//
return result;
}
Parse(ttfXConditions);
//
// Normalize Args ...
//
box.Clean();
dir = X_DIRECTION_NONE;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
int idx = -1;
int count = 0;
bool has = false;
//
int zIDX = barIndex;
int cIDX = zIDX + 1;
int pIDX = cIDX + 1;
//
double ask = GetAsk(ttfState.symbol);
double bid = GetBid(ttfState.symbol);
//
bool isBullish = false;
bool isBearish = false;
//
XOHCL zBar;
XOHCL cBar;
XOHCL pBar;
//
// Initial Bars ...
result = zBar.Init(
ttfState.symbol,
ttfState.period,
barIndex //
);
result =
result &&
zBar.GetPreviousBar(cBar);
result =
result &&
cBar.GetPreviousBar(pBar);
if (!result)
{
//
zBar.Clean();
cBar.Clean();
pBar.Clean();
ttfState.Clean();
ZeroMemory(ttfHelper);
ttfConditions.Clean();
ttfXConditions.Clean();
//
return result;
}
//
// Conditions ...
//
// First we Have to Detect Inside Box ...
XBoxZone insideBox;
count = ArraySize(unavailableBoxes);
for (int i = 0; i < count; i++)
{
//
XBoxZone iBox = unavailableBoxes[i];
//
bool isInside =
IsInsideBox(
zBar,
iBox //
);
if (isInside)
{
//
// Since we have to Follow Trend based on Breaked Boxes ...
// we have to use:
// - Breaked Bullish Boxes on Bearish Trend ...
// - Breaked Bearish Boxes on Bullish Trend ...
isInside =
hasBullishTrend
? iBox.IsBearish()
: hasBearishTrend
? iBox.IsBullish()
: false;
//
if (isInside)
{
//
insideBox = iBox;
iBox.Clean();
//
break;
}
}
//
iBox.Clean();
}
//
result = insideBox.IsValid();
if (!result)
{
//
zBar.Clean();
cBar.Clean();
pBar.Clean();
ttfState.Clean();
insideBox.Clean();
ZeroMemory(ttfHelper);
ttfConditions.Clean();
ttfXConditions.Clean();
}
//
if (result)
{
//
insideBox.from = insideBox.to;
insideBox.to = zBar.time;
//
XCBoxObject *iObj;
has = ttfHelper.mPOIDrawer.DrawBox(
insideBox,
iObj //
);
if (has) {
//
iObj.Width(2);
iObj.BoxColor(clrGray);
}
//
Print("Has Inside Box ...");
}
//
// Bullish Conditions ...
isBullish = (
//
false
//
);
//
// Bearish Conditions ...
isBearish = (
//
false
//
);
//
// Filling Requirements ...
result =
isBullish ||
isBearish;
if (result)
{
}
//
// Check All Conditions ...
result =
box.IsValid() &&
HasDirection(dir) &&
(isBullish ||
isBearish //
);
//
// Cleanup Resource ...
//
zBar.Clean();
cBar.Clean();
pBar.Clean();
//
ttfState.Clean();
ZeroMemory(ttfHelper);
ttfConditions.Clean();
ttfXConditions.Clean();
//
return result;
}
//
};
@@ -35,6 +35,7 @@ class XCX121SMCXWZSignalDetector : public XCBase
//
// Props ...
bool useGuards;
double rfRewar;
bool useQuarterTargets;
X121SMCStrategyXWZWorkingZone workingZone;
X121SMCStrategyXWZSignalConditions mConditions;
@@ -213,6 +214,22 @@ class XCX121SMCXWZSignalDetector : public XCBase
hasWorkingZoneOveralDirection = workingZone
.DetectOveralDirection(wzOveralDir);
//
// Detectiong Signal Boxes ...
hasWaitingBoxes = workingZone
.DetectSignalBoxes(
X_CYCLE_ANALYSE,
provider,
zIndex //
);
if (hasWaitingBoxes)
{
//
workingZone
.ValidateWaitingBoxes(zIndex);
hasWaitingBoxes = workingZone.HasWaitingBoxes();
}
//
// Checking Working Zone Destory or not ...
bool isWorkingZoneDestroyed = workingZone.IsDestroyed(
@@ -517,20 +534,21 @@ class XCX121SMCXWZSignalDetector : public XCBase
}
//
double reward2 = 2 * risk;
double reward3 = 3 * risk;
double iTP2 = isBullish
? entry + reward2
: entry - reward2;
double iTP3 = isBullish
? entry + reward3
: entry - reward3;
// Reward to RF ...
if (rfRewar > 0)
{
//
double iRFReward = rfRewar * risk;
double iRFTP = isBullish
? entry + iRFReward
: entry - iRFReward;
//
Add(
iTP3,
targets //
);
//
Add(
iRFTP,
targets //
);
}
//
// Based On Priority ...
@@ -1667,8 +1685,9 @@ class XCX121SMCXWZSignalDetector : public XCBase
void Init()
{
//
useGuards = true;
useQuarterTargets = true;
rfRewar = 2;
useGuards = false;
useQuarterTargets = false;
}
/**
+181 -40
View File
@@ -722,6 +722,85 @@ struct X121SMCStrategyXWZWorkingZone
return result;
}
//
bool DetectSignalBoxes(
ENUM_X_CYCLES cycle,
X121SMCStrategySignalProviderData &provider,
int barIndex = 0 //
)
{
//
bool result = false;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
// Select Cycle ...
XPOIState cState;
X121Conditions cXConditions;
XC121SMCCycleHelper *cHelper;
X121SMCCycleConditions cConditions;
result = provider.SelectCycle(
cycle,
cState,
cXConditions,
cHelper,
cConditions //
);
if (!result)
{
//
cState.Clean();
ZeroMemory(cHelper);
cConditions.Clean();
cXConditions.Clean();
//
return result;
}
//
// Select Validate Rejection Boxes ...
XBoxZone rejections[];
int count = cHelper
.DetectRejections(
rejections,
barIndex //
);
//
result = IsValidSize(count);
if (result)
{
//
Copy(
rejections,
waitingBoxes,
false //
);
}
//
count = CountWaitingBoxes();
result = IsValidSize(count);
//
// Cleanup Resources ...
//
cState.Clean();
ZeroMemory(cHelper);
cConditions.Clean();
cXConditions.Clean();
//
return result;
}
//
int ValidateWaitingZones(
int barIndex = 0 //
@@ -821,8 +900,7 @@ struct X121SMCStrategyXWZWorkingZone
}
//
has = IsValid() &&
HasWaitingBoxes();
has = HasWaitingBoxes();
if (!has)
{
return result;
@@ -834,12 +912,24 @@ struct X121SMCStrategyXWZWorkingZone
for (int i = 0; i < result; i++)
{
//
has = IsValidBox(
waitingBoxes[i],
barIndex,
period //
);
if (!has)
XOHCL iBar;
XBoxZone iBox = waitingBoxes[i];
bool isInite = iBar
.Init(
iBox.symbol,
iBox.period,
iBox.from //
);
//
has = isInite &&
IsBoxBreaked(
iBox,
iBar.Index() - 1,
barIndex,
period //
);
if (has)
{
//
Add(
@@ -849,10 +939,14 @@ struct X121SMCStrategyXWZWorkingZone
//
AddRef(
waitingBoxes[i],
iBox,
unavailableBoxes //
);
}
//
iBox.Clean();
iBar.Clean();
}
//
@@ -903,7 +997,9 @@ struct X121SMCStrategyXWZWorkingZone
}
//
result = IsValid();
ENUM_X_DIRECTION trend;
result = IsValid() &&
DetectOveralDirection(trend);
if (!result)
{
return result;
@@ -928,8 +1024,10 @@ struct X121SMCStrategyXWZWorkingZone
//
// Senario 1:
// ----------
bool useSenario1 = true;
// ---------------------------------------------
// Detect Signal Box Based On Conditions ...
// ---------------------------------------------
bool useSenario1 = false;
bool isSenario1Happend = false;
bool isSenario1Bullish = false;
bool isSenario1Bearish = false;
@@ -965,13 +1063,50 @@ struct X121SMCStrategyXWZWorkingZone
//
// Senario 2:
// ----------
bool useSenario2 = false;
// ---------------------------------------------------
// Detect Signal Based On Breaked Rejection Boxes ...
// ---------------------------------------------------
bool useSenario2 = true;
bool isSenario2Happend = false;
bool isSenario2Bullish = false;
bool isSenario2Bearish = false;
if (useSenario2)
{
//
// Senario 2 Working Based on
// Breaked Boxes ...
// Since we Works only
// when Has UnAvailable Boxes ...
has = HasUnavailableBoxes();
if (has)
{
//
isSenario2Happend = cParser.HasSenario2Conditions(
X_CYCLE_DECISION,
trend,
unavailableBoxes,
box,
dir,
provider,
barIndex //
);
//
isSenario2Bullish =
isSenario2Happend &&
IsBullish(dir);
//
isSenario2Bearish =
isSenario2Happend &&
IsBearish(dir);
//
if (isSenario2Happend)
{
signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX;
}
}
}
//
@@ -985,6 +1120,17 @@ struct X121SMCStrategyXWZWorkingZone
{
}
//
// Senario 4:
// ----------
bool useSenario4 = false;
bool isSenario4Happend = false;
bool isSenario4Bullish = false;
bool isSenario4Bearish = false;
if (useSenario4)
{
}
//
// Summarize All Senario(s) Conditions ...
@@ -993,6 +1139,7 @@ struct X121SMCStrategyXWZWorkingZone
//
isSenario1Bullish ||
isSenario2Bullish ||
isSenario3Bullish ||
isSenario3Bullish
//
;
@@ -1002,6 +1149,7 @@ struct X121SMCStrategyXWZWorkingZone
//
isSenario1Bearish ||
isSenario2Bearish ||
isSenario3Bearish ||
isSenario3Bearish
//
;
@@ -1373,50 +1521,42 @@ struct X121SMCStrategyXWZWorkingZone
//
XOHCL supPriceOutBar;
XOHCL demPriceOutBar;
bool hasSupPriceOutBar = false;
result = DetectBoxNearestPriceOut(
supBox,
supPriceOutBar,
period //
supBox.period //
);
if (!result)
{
//
demBox.Clean();
supBox.Clean();
supPriceOutBar.Clean();
demPriceOutBar.Clean();
//
return result;
}
//
XOHCL demPriceOutBar;
bool hasDemPriceOutBar = false;
result = DetectBoxNearestPriceOut(
demBox,
demPriceOutBar,
period //
demBox.period //
);
if (!result)
{
//
demBox.Clean();
supBox.Clean();
supPriceOutBar.Clean();
demPriceOutBar.Clean();
//
return result;
}
//
hasSupPriceOutBar = supPriceOutBar.IsValid();
hasDemPriceOutBar = demPriceOutBar.IsValid();
//
// Specified Direction ...
dir =
(supPriceOutBar.IsValid() &&
demPriceOutBar.IsValid())
(hasSupPriceOutBar &&
hasDemPriceOutBar)
? supPriceOutBar.time > demPriceOutBar.time
? X_DIRECTION_BEARISH
: demPriceOutBar.time > supPriceOutBar.time
? X_DIRECTION_BULLISH
: X_DIRECTION_NONE
: (hasSupPriceOutBar &&
!hasDemPriceOutBar)
? X_DIRECTION_BEARISH
: (!hasSupPriceOutBar &&
hasDemPriceOutBar)
? X_DIRECTION_BULLISH
: X_DIRECTION_NONE;
//
@@ -1491,7 +1631,8 @@ struct X121SMCStrategyXWZWorkingZone
XCPOIDrawer *drawer,
bool drawSupplyZone = false,
bool drawDemandZone = false,
bool drawWaitingZones = false)
bool drawWaitingZones = false //
)
{
//
if (drawer == NULL)
@@ -704,7 +704,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
{
//
useXWZSignal = true;
useXWZSignalGuard = true;
useXWZSignalGuard = false;
//
string symbol = GetSymbol();
@@ -767,7 +767,8 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
//
x121Inputs.xatrInputs.atrMultiplier = 1.5;
x121Inputs.xatrInputs.atrSmoothingMode = X_MA_MODE_EMA;
x121Inputs.xatrInputs.atrSmoothingMode = X_MA_MODE_NONE;
x121Inputs.xpvInputs.goldenZoneLevel = X_FIBO_LEVEL_236;
//
x121Inputs.xvwapInputs.vwapFastLength = 20;
@@ -817,8 +818,8 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
//
// XATR ...
x121Inputs.xatrInputs.showATRUpper = showAll || false;
x121Inputs.xatrInputs.showATRLower = showAll || false;
x121Inputs.xatrInputs.showATRUpper = showAll || true;
x121Inputs.xatrInputs.showATRLower = showAll || true;
//
// XSTR ...