last ...
This commit is contained in:
@@ -166,7 +166,6 @@ class XCX121SMCXWZSignalDetector : public XCBase
|
||||
XBoxZone signalBox;
|
||||
bool hasPriority = false;
|
||||
int activatedFVGIDX = -1;
|
||||
int activatedBoxIDX = -1;
|
||||
int activatedZoneIDX = -1;
|
||||
double amountPercent = -1;
|
||||
bool hasSignalBox = false;
|
||||
@@ -283,113 +282,66 @@ class XCX121SMCXWZSignalDetector : public XCBase
|
||||
// Detect Signal Box ...
|
||||
|
||||
//
|
||||
bool isZoneActivated =
|
||||
hasWorkingZone &&
|
||||
hasWaitingZones &&
|
||||
workingZone.IsZoneActivated(
|
||||
activatedZoneIDX,
|
||||
activatedFVGIDX,
|
||||
provider,
|
||||
zIndex //
|
||||
);
|
||||
|
||||
//
|
||||
bool isBoxActivated =
|
||||
hasWorkingZone &&
|
||||
hasWaitingBoxes &&
|
||||
workingZone.IsBoxActivated(
|
||||
activatedBoxIDX,
|
||||
provider,
|
||||
zIndex //
|
||||
);
|
||||
// TODO: Check This ...
|
||||
// bool isZoneActivated =
|
||||
// hasWorkingZone &&
|
||||
// hasWaitingZones &&
|
||||
// workingZone.IsZoneActivated(
|
||||
// activatedZoneIDX,
|
||||
// activatedFVGIDX,
|
||||
// provider,
|
||||
// zIndex //
|
||||
// );
|
||||
|
||||
//
|
||||
hasSignalBox =
|
||||
isBoxActivated ||
|
||||
isZoneActivated;
|
||||
hasWorkingZone &&
|
||||
hasWaitingBoxes &&
|
||||
workingZone.IsBoxActivated(
|
||||
signalBox,
|
||||
signalBoxDir,
|
||||
signalProvider,
|
||||
provider,
|
||||
zIndex //
|
||||
);
|
||||
|
||||
//
|
||||
if (hasSignalBox)
|
||||
{
|
||||
//
|
||||
signalBox.Clean();
|
||||
|
||||
//
|
||||
if (isZoneActivated)
|
||||
if (hasWaitingBoxes)
|
||||
{
|
||||
//
|
||||
XOBFVG iOBFVG = workingZone.waitingZones[activatedZoneIDX];
|
||||
XCFVG *activatedFVG = iOBFVG.fvgs[activatedFVGIDX];
|
||||
hasSignalBox = ToBox(
|
||||
int idx = FindIndex(
|
||||
signalBox,
|
||||
activatedFVG //
|
||||
workingZone.waitingBoxes //
|
||||
);
|
||||
|
||||
//
|
||||
signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE;
|
||||
|
||||
//
|
||||
ArrayRemove(
|
||||
workingZone.waitingZones[activatedZoneIDX].fvgs,
|
||||
activatedFVGIDX,
|
||||
1 //
|
||||
);
|
||||
bool isValid = workingZone.waitingZones[activatedZoneIDX].IsValid();
|
||||
if (!isValid)
|
||||
bool has = IsValidIndex(idx);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
workingZone.waitingZones[activatedZoneIDX],
|
||||
workingZone.unavailableZones //
|
||||
);
|
||||
|
||||
//
|
||||
ArrayRemove(
|
||||
workingZone.waitingZones,
|
||||
activatedZoneIDX,
|
||||
workingZone.waitingBoxes,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
iOBFVG.Clean();
|
||||
ZeroMemory(activatedFVG);
|
||||
}
|
||||
|
||||
//
|
||||
if (isBoxActivated)
|
||||
{
|
||||
//
|
||||
signalBox = workingZone.waitingBoxes[activatedBoxIDX];
|
||||
|
||||
//
|
||||
signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX;
|
||||
|
||||
//
|
||||
AddRef(
|
||||
signalBox,
|
||||
workingZone.unavailableBoxes //
|
||||
);
|
||||
|
||||
//
|
||||
ArrayRemove(
|
||||
workingZone.waitingBoxes,
|
||||
activatedBoxIDX,
|
||||
1 //
|
||||
);
|
||||
}
|
||||
AddRef(
|
||||
signalBox,
|
||||
workingZone.unavailableBoxes //
|
||||
);
|
||||
|
||||
//
|
||||
if (hasSignalBox)
|
||||
{
|
||||
//
|
||||
signalBox.to = cTime;
|
||||
signalBoxDir = signalBox.dir;
|
||||
}
|
||||
signalBox.to = cTime;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Remove Invalidate Zones ...
|
||||
if (hasWaitingZones)
|
||||
@@ -499,25 +451,48 @@ class XCX121SMCXWZSignalDetector : public XCBase
|
||||
// iSL = signalBox.lower + (signalBox.upper - signalBox.lower) / 2;
|
||||
// }
|
||||
|
||||
// //
|
||||
// if (provider == X121SMC_XWZ_PROVIDER_PV_ZONE)
|
||||
// {
|
||||
// }
|
||||
//
|
||||
if (signalProvider == X121SMC_XWZ_PROVIDER_ACTIVATED_MA)
|
||||
{
|
||||
//
|
||||
// Default SL ...
|
||||
iSL = pivot;
|
||||
|
||||
//
|
||||
Add(
|
||||
iSL,
|
||||
sls //
|
||||
);
|
||||
}
|
||||
else if (signalProvider == X121SMC_XWZ_PROVIDER_ACTIVATED_BOX)
|
||||
{
|
||||
//
|
||||
// Default SL ...
|
||||
iSL = pivot;
|
||||
|
||||
//
|
||||
Add(
|
||||
iSL,
|
||||
sls //
|
||||
);
|
||||
}
|
||||
else if (signalProvider == X121SMC_XWZ_PROVIDER_ACTIVATED_AREA)
|
||||
{
|
||||
//
|
||||
// Default SL ...
|
||||
iSL = pivot;
|
||||
|
||||
//
|
||||
Add(
|
||||
iSL,
|
||||
sls //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double iAtr = provider.decisionXConditions.atrBuffer[1];
|
||||
iAtr *= 1.5;
|
||||
|
||||
//
|
||||
// Default SL ...
|
||||
iSL = pivot;
|
||||
|
||||
//
|
||||
Add(
|
||||
iSL,
|
||||
sls //
|
||||
);
|
||||
|
||||
//
|
||||
// Select Condition SL ...
|
||||
|
||||
@@ -538,16 +513,30 @@ class XCX121SMCXWZSignalDetector : public XCBase
|
||||
// Targets ...
|
||||
|
||||
//
|
||||
// Force Add TP 2 as Target ...
|
||||
double risk = MathAbs(entry - sl);
|
||||
|
||||
//
|
||||
// Checking risk ...
|
||||
if (risk >= maxAllowedSLDistanceInPoint)
|
||||
{
|
||||
// Print("Max Aloowed Risk Point Reached ...");
|
||||
}
|
||||
|
||||
//
|
||||
double reward2 = 2 * risk;
|
||||
// double iTP2 = isBullish
|
||||
// ? entry + reward2
|
||||
// : entry - reward2;
|
||||
// Add(
|
||||
// iTP2,
|
||||
// targets //
|
||||
// );
|
||||
double reward3 = 3 * risk;
|
||||
double iTP2 = isBullish
|
||||
? entry + reward2
|
||||
: entry - reward2;
|
||||
double iTP3 = isBullish
|
||||
? entry + reward3
|
||||
: entry - reward3;
|
||||
|
||||
//
|
||||
Add(
|
||||
iTP2,
|
||||
targets //
|
||||
);
|
||||
|
||||
//
|
||||
// Based On Priority ...
|
||||
@@ -984,18 +973,10 @@ class XCX121SMCXWZSignalDetector : public XCBase
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
return false;
|
||||
|
||||
//
|
||||
Clean(guards);
|
||||
|
||||
//
|
||||
bool isCycleHelpersValid =
|
||||
//
|
||||
provider.IsValid()
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Set Provider for Common Guards ...
|
||||
string signalProvider = ToString(X_121_SMC_PROVIDER_XWZ);
|
||||
@@ -1006,6 +987,9 @@ class XCX121SMCXWZSignalDetector : public XCBase
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
|
||||
//
|
||||
int loopback = 10;
|
||||
|
||||
@@ -1016,14 +1000,18 @@ class XCX121SMCXWZSignalDetector : public XCBase
|
||||
double points = GetPoints(symbol);
|
||||
|
||||
//
|
||||
// Check Cycle Helpers Validation ...
|
||||
result = isCycleHelpersValid &&
|
||||
provider.Prepare(
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
// Cycles Conditions ...
|
||||
result = provider.IsValid();
|
||||
result =
|
||||
result &&
|
||||
provider.Prepare(
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
provider.Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1117,18 +1105,18 @@ class XCX121SMCXWZSignalDetector : public XCBase
|
||||
// Get Global and Common Guards ...
|
||||
|
||||
//
|
||||
ENUM_X_121_SMC_GUARD_ACTIONS ignoreGuards[1] = {
|
||||
X_121_SMC_GUARD_ACTION_TRAIL_STOP //
|
||||
};
|
||||
result = DetectX121SMCGuards(
|
||||
signalProvider,
|
||||
guards,
|
||||
positions,
|
||||
provider,
|
||||
//
|
||||
ignoreGuards
|
||||
//
|
||||
);
|
||||
// ENUM_X_121_SMC_GUARD_ACTIONS ignoreGuards[1] = {
|
||||
// X_121_SMC_GUARD_ACTION_TRAIL_STOP //
|
||||
// };
|
||||
// result = DetectX121SMCGuards(
|
||||
// signalProvider,
|
||||
// guards,
|
||||
// positions,
|
||||
// provider,
|
||||
// //
|
||||
// ignoreGuards
|
||||
// //
|
||||
// );
|
||||
|
||||
//
|
||||
//
|
||||
@@ -1178,6 +1166,70 @@ class XCX121SMCXWZSignalDetector : public XCBase
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
XBoxZone bullishBox;
|
||||
bool hasBullishBox = false;
|
||||
bool isBullishBoxBreaked = false;
|
||||
if (!hasBullishBox)
|
||||
{
|
||||
//
|
||||
XCOrderBlock *ob = NULL;
|
||||
idx = GetYoungest(provider.analyseState.bullishOrderBlocks);
|
||||
has = IsValidIndex(idx);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
ob = provider.analyseState.bullishOrderBlocks[idx];
|
||||
|
||||
//
|
||||
hasBullishBox = ToBox(
|
||||
bullishBox,
|
||||
ob //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
if (!hasBullishBox)
|
||||
{
|
||||
bullishBox.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
ZeroMemory(ob);
|
||||
}
|
||||
|
||||
//
|
||||
XBoxZone bearishBox;
|
||||
bool hasBearishBox = false;
|
||||
bool isBearishBoxBreaked = false;
|
||||
if (!hasBearishBox)
|
||||
{
|
||||
//
|
||||
XCOrderBlock *ob = NULL;
|
||||
idx = GetYoungest(provider.analyseState.bearishOrderBlocks);
|
||||
has = IsValidIndex(idx);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
ob = provider.analyseState.bearishOrderBlocks[idx];
|
||||
|
||||
//
|
||||
hasBearishBox = ToBox(
|
||||
bearishBox,
|
||||
ob //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
if (!hasBearishBox)
|
||||
{
|
||||
bearishBox.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
ZeroMemory(ob);
|
||||
}
|
||||
|
||||
//
|
||||
// Here We Have all Requirements for Guarding Positions ...
|
||||
|
||||
@@ -1216,12 +1268,32 @@ class XCX121SMCXWZSignalDetector : public XCBase
|
||||
//
|
||||
// X_121_SMC_GUARD_ACTION_TRAIL_STOP:
|
||||
// Trail Stop Specified Position on Specified Conditions ...
|
||||
bool handleStoptrailingBasedOnBoxes = true;
|
||||
bool handleStoptrailingBasedOnConsolidationZones = true;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = ownPositions[i];
|
||||
|
||||
//
|
||||
bool isInited = cBar.Init(
|
||||
iPosition.symbol,
|
||||
iPosition.period,
|
||||
cIndex //
|
||||
);
|
||||
|
||||
//
|
||||
isBullishBoxBreaked =
|
||||
isInited &&
|
||||
hasBullishBox &&
|
||||
cBar.high < bullishBox.lower;
|
||||
|
||||
//
|
||||
isBearishBoxBreaked =
|
||||
isInited &&
|
||||
hasBearishBox &&
|
||||
cBar.low > bearishBox.upper;
|
||||
|
||||
//
|
||||
bool isLong = IsLong(iPosition.type);
|
||||
bool isInProfit = iPosition.profit > 0;
|
||||
@@ -1272,6 +1344,90 @@ class XCX121SMCXWZSignalDetector : public XCBase
|
||||
canTraiLonglUsingCZone ||
|
||||
canTraiShortlUsingCZone;
|
||||
|
||||
//
|
||||
// Trail Stop Using Boxes ...
|
||||
|
||||
//
|
||||
bool canTraiLonglUsingBox =
|
||||
//
|
||||
handleStoptrailingBasedOnBoxes &&
|
||||
//
|
||||
(isLong &&
|
||||
isInProfit &&
|
||||
hasBullishBox &&
|
||||
bullishBox.lower > iPosition.sl &&
|
||||
bullishBox.lower > iPosition.entry)
|
||||
//
|
||||
;
|
||||
if (canTraiLonglUsingBox)
|
||||
{
|
||||
sl = bullishBox.lower;
|
||||
}
|
||||
|
||||
//
|
||||
bool canTraiShortlUsingBox =
|
||||
//
|
||||
handleStoptrailingBasedOnBoxes &&
|
||||
//
|
||||
(!isLong &&
|
||||
isInProfit &&
|
||||
hasBearishBox &&
|
||||
bearishBox.upper < iPosition.sl &&
|
||||
bearishBox.upper < iPosition.entry)
|
||||
//
|
||||
;
|
||||
if (canTraiShortlUsingBox)
|
||||
{
|
||||
sl = bearishBox.upper;
|
||||
}
|
||||
|
||||
//
|
||||
bool canTrailUsingBox =
|
||||
canTraiLonglUsingBox ||
|
||||
canTraiShortlUsingBox;
|
||||
|
||||
//
|
||||
bool canTraiLonglUsingBreakedBox =
|
||||
//
|
||||
handleStoptrailingBasedOnBoxes &&
|
||||
//
|
||||
(isLong &&
|
||||
isInProfit &&
|
||||
isBearishBoxBreaked &&
|
||||
bearishBox.upper > iPosition.sl &&
|
||||
bearishBox.upper > iPosition.entry)
|
||||
//
|
||||
;
|
||||
if (canTraiLonglUsingBreakedBox)
|
||||
{
|
||||
sl = bearishBox.upper;
|
||||
}
|
||||
|
||||
//
|
||||
bool canTraiShortlUsingBreakedBox =
|
||||
//
|
||||
handleStoptrailingBasedOnBoxes &&
|
||||
//
|
||||
(!isLong &&
|
||||
isInProfit &&
|
||||
isBullishBoxBreaked &&
|
||||
bullishBox.lower < iPosition.sl &&
|
||||
bullishBox.lower < iPosition.entry)
|
||||
//
|
||||
;
|
||||
if (canTraiShortlUsingBreakedBox)
|
||||
{
|
||||
sl = bullishBox.lower;
|
||||
}
|
||||
|
||||
//
|
||||
bool canTrailUsingBreakedBox =
|
||||
canTraiLonglUsingBreakedBox ||
|
||||
canTraiShortlUsingBreakedBox;
|
||||
|
||||
//
|
||||
// Summarize SL ...
|
||||
|
||||
//
|
||||
bool isSLPassed =
|
||||
sl > 0 &&
|
||||
@@ -1282,7 +1438,9 @@ class XCX121SMCXWZSignalDetector : public XCBase
|
||||
//
|
||||
bool canTrail =
|
||||
isSLPassed &&
|
||||
canTrailUsingCZone;
|
||||
(canTrailUsingBox ||
|
||||
canTrailUsingCZone ||
|
||||
canTrailUsingBreakedBox);
|
||||
if (canTrail)
|
||||
{
|
||||
//
|
||||
@@ -1319,9 +1477,20 @@ class XCX121SMCXWZSignalDetector : public XCBase
|
||||
//
|
||||
// Cleanup Collections ...
|
||||
|
||||
//
|
||||
cBar.Clean();
|
||||
|
||||
//
|
||||
provider.Clean();
|
||||
|
||||
//
|
||||
bullishBox.Clean();
|
||||
bearishBox.Clean();
|
||||
|
||||
//
|
||||
bullishConsolidationZone.Clean();
|
||||
bearishConsolidationZone.Clean();
|
||||
|
||||
//
|
||||
count = ArraySize(guards);
|
||||
result = IsValidSize(count);
|
||||
|
||||
Reference in New Issue
Block a user