This commit is contained in:
2025-04-04 13:10:31 +03:30
parent 72610213e7
commit 9e8d830707
5 changed files with 1535 additions and 527 deletions
File diff suppressed because it is too large Load Diff
+61 -6
View File
@@ -69,7 +69,7 @@ input double sarMax = 0.2; // Maximum
//
input group "Swing Detection";
input int swingLength = 5;
input int swingLength = 5; // Length
//
// Presentation ...
@@ -81,8 +81,8 @@ input int sarArrowCode = 159; // Parabolic Sar Arrow Code
input int peaksArrowCode = 159; // Peaks Arrow Code
input int valesArrowCode = 159; // Vales Arrow Code
input int trendArrowCode = 117; // Trend Arrow Code
input int swingLowsArrowCode = 159; // Swing Lows Arrow Code
input int swingHighsArrowCode = 159; // Swing Highs Arrow Code
input int swingLowsArrowCode = 225; // Swing Lows Arrow Code
input int swingHighsArrowCode = 226; // Swing Highs Arrow Code
input int supportsArrowCode = 159; // Supports Arrow Code
input int resistancesArrowCode = 159; // Resistances Arrow Code
@@ -351,6 +351,14 @@ ENUM_TIMEFRAMES mLCPeriod = NULL;
int mHCLength = 0;
ENUM_TIMEFRAMES mHCPeriod = NULL;
//
// Swings ...
double lSwingLow = emptyValue;
double lSwingHigh = emptyValue;
double lTrend = emptyValue;
double lTrendState = emptyValue;
double lTrendColor = hideColorIDX;
//
// Event Handlers ...
@@ -943,10 +951,17 @@ void CalculateBuffers(
tickVolume //
);
//
int swingBarIndex = bar_index;
if (bar_index < swingLength)
{
swingBarIndex = bar_index + swingLength;
}
//
// Calcultae Swing High and Low and Trends ...
CalculateSwingsAndTrend(
bar_index,
swingBarIndex,
prevCalculated,
ratesTotal,
open,
@@ -955,6 +970,21 @@ void CalculateBuffers(
low,
tickVolume //
);
//
if (bar_index < swingLength)
{
//
// for (int i = bar_index; i < bar_index + swingLength; i++)
// {
// //
// trendBuffer[i] = lTrend;
// swingLowsBuffer[i] = lSwingLow;
// swingHighsBuffer[i] = lSwingHigh;
// trendStateBuffer[i] = lTrendState;
// trendColorBuffer[i] = lTrendColor;
// }
}
}
else
{
@@ -1447,6 +1477,10 @@ void CalculateSwingsAndTrend(
? lastSwingLow
: iLow;
swingLowsBuffer[bar_index] = iSwingLow;
if (isSwingLow)
{
lSwingLow = iSwingLow;
}
//
// Swing High ...
@@ -1459,6 +1493,10 @@ void CalculateSwingsAndTrend(
? lastSwingHigh
: iHigh;
swingHighsBuffer[bar_index] = iSwingHigh;
if (isSwingHigh)
{
lSwingHigh = iSwingHigh;
}
//
// Calculate Trend ...
@@ -1476,6 +1514,14 @@ void CalculateSwingsAndTrend(
? iSwingHigh
: lastTrend;
trendBuffer[bar_index] = iTrend;
bool isBullTrnd =
isSwingLow &&
iSwingLow > lastSwingLow;
bool isBearTrnd =
isSwingHigh &&
iSwingHigh < lastSwingHigh;
bool isTrnd = isBullTrnd ||
isBearTrnd;
//
double lastTrendState = isFirstBar
@@ -1530,6 +1576,15 @@ void CalculateSwingsAndTrend(
? bearishColorIDX
: hideColorIDX;
trendColorBuffer[bar_index] = iTrendColor;
//
if (isTrnd)
{
//
lTrend = iTrend;
lTrendColor = iTrendColor;
lTrendState = iTrendState;
}
}
//
@@ -1547,7 +1602,7 @@ bool IsSwingLow(
bool result = false;
//
result = index - length > 0;
result = index - length >= 0;
if (!result)
{
return result;
@@ -1581,7 +1636,7 @@ bool IsSwingHigh(
bool result = false;
//
result = index - length > 0;
result = index - length >= 0;
if (!result)
{
return result;
+92 -6
View File
@@ -1340,12 +1340,12 @@ bool IsBoxValid(
}
//
int fromIndex = iBarShift(
int toIndex = iBarShift(
box.symbol,
forPeriod,
box.from //
box.to //
);
result = IsValidIndex(fromIndex);
result = IsValidIndex(toIndex);
if (!result)
{
return result;
@@ -1354,7 +1354,7 @@ bool IsBoxValid(
//
XOHCL iBar;
bool isBullish = box.IsBullish();
for (int i = barIndex; i < fromIndex; i++)
for (int i = barIndex; i < toIndex; i++)
{
//
result = iBar.Init(
@@ -1370,8 +1370,94 @@ bool IsBoxValid(
//
result =
isBullish
? iBar.GetDown() > box.lower
: iBar.GetUp() < box.upper;
? iBar.low > box.upper
: iBar.high < box.lower;
if (!result)
{
break;
}
//
iBar.Clean();
}
//
iBar.Clean();
//
return result;
}
/**
* Check Box Breaked ...
*
* @param box: XBoxZone instance ...
* @param barIndex: int, Current Bar Index ...
* @param forPeriod: Testing Period ...
*
* @return ( bool )
*/
bool IsBoxBreaked(
XBoxZone &box,
int barIndex = 0,
ENUM_TIMEFRAMES forPeriod = NULL //
)
{
//
bool result = false;
//
result = box.IsValid();
if (!result)
{
return result;
}
//
if (barIndex < 0)
{
barIndex = 0;
}
//
if (!IsValid(forPeriod))
{
forPeriod = box.period;
}
//
int toIndex = iBarShift(
box.symbol,
forPeriod,
box.to //
);
result = IsValidIndex(toIndex);
if (!result)
{
return result;
}
//
XOHCL iBar;
bool isBullish = box.IsBullish();
for (int i = barIndex; i < toIndex; i++)
{
//
result = iBar.Init(
box.symbol,
forPeriod,
i //
);
if (!result)
{
break;
}
//
result =
isBullish
? iBar.high < box.lower
: iBar.low > box.upper;
if (!result)
{
break;
+509 -21
View File
@@ -36,6 +36,10 @@ class XCX121SMCXINDSignalDetector : public XCBase
// Props ...
bool useGuards;
double rfRewar;
XBoxZone mWaitingBoxes[];
XBoxZone mInsideBoxes[];
XBoxZone mBreakedBoxes[];
XBoxZone mUnAvailableBoxes[];
X121SMCStrategyXINDSignalConditions mConditions;
X121SMCStrategyXINDSignalConditions mConditionsCollection[];
@@ -206,21 +210,39 @@ class XCX121SMCXINDSignalDetector : public XCBase
//
//
hasSignalBox = HasXPVConditions(
int waitingBoxesCount = UpdateWaitingBoxes(
X_CYCLE_DECISION,
signalBox,
signalBoxDir,
provider,
zIndex //
provider //
);
if (hasSignalBox)
bool hasWaitingBoxes = IsValidSize(waitingBoxesCount);
//
DrawBoxes(drawer);
//
if (hasWaitingBoxes)
{
signalProvider = X121SMC_XIND_PROVIDER_XSTR;
//
hasSignalBox = HasXPVConditions(
X_CYCLE_DECISION,
signalBox,
signalBoxDir,
provider,
zIndex //
);
if (hasSignalBox)
{
signalProvider = X121SMC_XIND_PROVIDER_XSTR;
}
}
//
// Update Models To Time ...
UpdateTo(cTime);
//
//
// //
// // Update Models To Time ...
// UpdateTo(cTime);
//
// Cleanup Signal if UnApproved ...
@@ -393,6 +415,7 @@ class XCX121SMCXINDSignalDetector : public XCBase
pBar.Clean();
pPBar.Clean();
signalBox.Clean();
ZeroMemory(drawer);
consolidationZBar.Clean();
//
@@ -1046,6 +1069,399 @@ class XCX121SMCXINDSignalDetector : public XCBase
return result;
}
//
// Waiting Boxes ...
int UpdateWaitingBoxes(
ENUM_X_CYCLES cycle,
X121SMCStrategySignalProviderData &provider //
)
{
//
int result = ArraySize(mWaitingBoxes) + ArraySize(mInsideBoxes);
//
int count = 0;
bool has = false;
//
// Fil Selected Data ...
XPOIState cState;
X121Conditions cXConditions;
XPOIStateEvents cStateEvents;
XC121SMCCycleHelper *cHelper;
X121SMCCycleConditions cConditions;
has = provider.SelectCycle(
cycle,
cState,
cStateEvents,
cXConditions,
cHelper,
cConditions //
);
if (!has)
{
//
cState.Clean();
ZeroMemory(cHelper);
cConditions.Clean();
cXConditions.Clean();
cStateEvents.Clean();
//
return result;
}
//
// Detecting New Boxes ...
//
// Checking Bullish Fair Value Gaps ...
has = cState.HasBullishFairValueGaps();
if (has)
{
//
XBoxZone tmpBoxes[];
ToBox(
cState.bullishFairValueGaps,
tmpBoxes //
);
//
count = ArraySize(tmpBoxes);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
//
XBoxZone iBox = tmpBoxes[i];
bool isValid = IsBoxValid(
iBox,
0,
iBox.period //
);
if (isValid)
{
//
has = IsBoxExists(iBox);
if (!has)
{
//
AddRef(
iBox,
mWaitingBoxes //
);
}
}
//
iBox.Clean();
}
}
//
Clean(tmpBoxes);
}
//
// Checking Bearish Fair Value Gaps ...
has = cState.HasBearishFairValueGaps();
if (has)
{
//
XBoxZone tmpBoxes[];
ToBox(
cState.bearishFairValueGaps,
tmpBoxes //
);
//
count = ArraySize(tmpBoxes);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
//
XBoxZone iBox = tmpBoxes[i];
bool isValid = IsBoxValid(
iBox,
0,
iBox.period //
);
if (isValid)
{
//
has = IsBoxExists(iBox);
if (!has)
{
//
AddRef(
iBox,
mWaitingBoxes //
);
}
}
//
iBox.Clean();
}
}
//
Clean(tmpBoxes);
}
//
// Update Times ...
//
count = ArraySize(mWaitingBoxes);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
mWaitingBoxes[i].to = TimeCurrent();
}
}
//
count = ArraySize(mInsideBoxes);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
mInsideBoxes[i].to = TimeCurrent();
}
}
//
// Validate Exists Boxes ...
//
// Waiting Boxes ...
// count = ArraySize(mWaitingBoxes);
// has = IsValidSize(count);
// if (has)
// {
// //
// int mustRemove[];
// for (int i = 0; i < count; i++)
// {
// //
// mWaitingBoxes[i].to = TimeCurrent();
// XBoxZone iBox = mWaitingBoxes[i];
// //
// bool isValid = IsBoxValid(
// iBox,
// 0,
// iBox.period //
// );
// bool isBreaked = IsBoxBreaked(
// iBox,
// 0,
// iBox.period //
// );
// //
// bool isInside = !isValid && !isBreaked;
// if (isInside)
// {
// //
// Add(
// i,
// mustRemove //
// );
// //
// AddRef(
// iBox,
// mInsideBoxes //
// );
// }
// //
// if (!isInside && isBreaked)
// {
// //
// Add(
// i,
// mustRemove //
// );
// //
// AddRef(
// iBox,
// mBreakedBoxes //
// );
// }
// }
// //
// CleanupArray(
// mustRemove,
// mWaitingBoxes //
// );
// }
//
// Inside Boxes ...
// count = ArraySize(mInsideBoxes);
// has = IsValidSize(count);
// if (has)
// {
// //
// int mustRemove[];
// for (int i = 0; i < count; i++)
// {
// //
// mInsideBoxes[i].to = TimeCurrent();
// XBoxZone iBox = mInsideBoxes[i];
// //
// bool isBreaked = IsBoxBreaked(
// iBox,
// 0,
// iBox.period //
// );
// if (isBreaked)
// {
// //
// Add(
// i,
// mustRemove //
// );
// //
// AddRef(
// iBox,
// mBreakedBoxes //
// );
// }
// }
// //
// CleanupArray(
// mustRemove,
// mInsideBoxes //
// );
// }
//
// Cleanup Resources ...
//
cState.Clean();
ZeroMemory(cHelper);
cConditions.Clean();
cXConditions.Clean();
cStateEvents.Clean();
//
result = ArraySize(mWaitingBoxes) + ArraySize(mInsideBoxes);
//
return result;
}
//
bool IsBoxExists(XBoxZone &box)
{
//
bool result = false;
//
int idx = -1;
int count = 0;
bool has = false;
//
// Witing Boxes ...
count = ArraySize(mWaitingBoxes);
has = IsValidSize(count);
if (has)
{
//
has = FindBoxIndex(
idx,
box,
mWaitingBoxes //
);
result = has;
if (result)
{
return result;
}
}
//
// Inside Boxes ...
count = ArraySize(mInsideBoxes);
has = IsValidSize(count);
if (has)
{
//
has = FindBoxIndex(
idx,
box,
mInsideBoxes //
);
result = has;
if (result)
{
return result;
}
}
//
// Breaked Boxes ...
count = ArraySize(mBreakedBoxes);
has = IsValidSize(count);
if (has)
{
//
has = FindBoxIndex(
idx,
box,
mBreakedBoxes //
);
result = has;
if (result)
{
return result;
}
}
//
// UnAvailable Boxes ...
count = ArraySize(mUnAvailableBoxes);
has = IsValidSize(count);
if (has)
{
//
has = FindBoxIndex(
idx,
box,
mUnAvailableBoxes //
);
result = has;
if (result)
{
return result;
}
}
//
return result;
}
//
// Add Conditions to Conditions Collection ...
int AddConditionsIfNotExists(
@@ -1188,6 +1604,78 @@ class XCX121SMCXINDSignalDetector : public XCBase
}
}
//
void DrawBoxes(
XCPOIDrawer *drawer,
bool forceClean = false //
)
{
//
if (forceClean)
{
mObjects.Clear();
}
//
int count = 0;
bool has = false;
//
// Waiting Boxes ...
count = ArraySize(mWaitingBoxes);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
//
XCBoxObject *iObj;
has = drawer.DrawBox(
mWaitingBoxes[i],
iObj //
);
if (has)
{
mObjects.Add(iObj);
}
}
}
//
// Inside Boxes ...
count = ArraySize(mInsideBoxes);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
//
XCBoxObject *iObj;
has = drawer.DrawBox(
mInsideBoxes[i],
iObj //
);
if (has)
{
//
if (mInsideBoxes[i].IsBullish())
{
iObj.BoxColor(clrYellow);
}
else
{
iObj.BoxColor(clrOrange);
}
//
mObjects.Add(iObj);
}
}
}
}
//
protected:
//
@@ -1225,18 +1713,18 @@ class XCX121SMCXINDSignalDetector : public XCBase
mBarObjects.Clear();
}
/**
* Update To Time of Exists Components ...
*
* @param value: updated time ...
*/
void UpdateTo(
datetime value = NULL //
)
{
//
value = NormalizeTime(value);
}
// /**
// * Update To Time of Exists Components ...
// *
// * @param value: updated time ...
// */
// void UpdateTo(
// datetime value = NULL //
// )
// {
// //
// value = NormalizeTime(value);
// }
//
};
@@ -448,10 +448,6 @@ bool HasXPVConditions(
//
//
//
// Check new Order Block ...
//
// Summarize Conditions ...
@@ -459,7 +455,7 @@ bool HasXPVConditions(
isBullish =
//
false
//
//
;
//