This commit is contained in:
2025-05-07 18:22:47 +03:30
parent 8258c7a7ef
commit 32f895407f
3 changed files with 1273 additions and 340 deletions
+273
View File
@@ -0,0 +1,273 @@
//
// Detect SignalBox Trigger ...
// Cond1:
// - Close Under Min / Max ...
// - All Trendings in Direction ...
// - Consolidating Trendings ...
// - ...
bool CanTriggerCond1(
XCXCAEAHelper *helper,
XBoxZone &box,
ENUM_X_DIRECTION &dir,
double &sls[],
int barIndex = 0,
int loopback = 10 //
)
{
//
bool result = false;
//
// Normalize Args ...
Clean(sls);
dir = X_DIRECTION_NONE;
loopback = NormalizeInt(loopback, 5);
barIndex = NormalizeInt(barIndex, 0);
//
// Validate Decision Box ...
result = box.IsValid();
if (!result)
{
return result;
}
//
// Retrieve Market Conditions ...
XCAEAConditions conditions;
result = helper.GetConditions(
conditions,
barIndex,
loopback //
);
//
// Extract CBar ...
XOHCL cBar;
result = cBar.Init(
conditions.symbol,
conditions.period,
barIndex //
);
if (!result)
{
//
cBar.Clean();
conditions.Clean();
//
return result;
}
//
// Bar Conditions ...
//
ENUM_X_DIRECTION barDir;
//
// ENGULF ...
//
bool isCBarEngulfed = helper
.barAnalyser
.IsEngulfed(
cBar,
barDir //
);
//
bool isCBarBullishEngulfed =
isCBarEngulfed &&
IsBullish(barDir);
//
bool isCBarBearishEngulfed =
isCBarEngulfed &&
IsBearish(barDir);
//
bool isBullish = box.IsBullish();
bool isBearish = box.IsBearish();
//
int zIDX = 0;
int cIDX = zIDX + 1;
int pIDX = cIDX + 1;
int p2IDX = pIDX + 1;
int p3IDX = p2IDX + 1;
int p4IDX = p3IDX + 1;
//
// Reading Values ...
//
// SAR ...
double cSAR = conditions.sarBuffer[cIDX];
//
// SWH ...
double cSWH = conditions.swingHighBuffer[cIDX];
//
// SWL ...
double cSWL = conditions.swingLowBuffer[cIDX];
//
// PEAK ...
double cPeak = conditions.peakBuffer[cIDX];
//
// VALE ...
double cVale = conditions.valeBuffer[cIDX];
//
// MAH ...
double cMAH = conditions.mahBuffer[cIDX];
//
// MAC ...
double cMAC = conditions.macBuffer[cIDX];
//
// MAL ...
double cMAL = conditions.malBuffer[cIDX];
//
// KI ...
double cKI = conditions.kiBuffer[cIDX];
double cKIState = conditions.kiStateBuffer[cIDX];
//
// TKI ...
double cTKI = conditions.tkiBuffer[cIDX];
double cTKIState = conditions.tkiStateBuffer[cIDX];
//
// FAST ...
double cFast = conditions.fastBuffer[cIDX];
double cFastState = conditions.fastStateBuffer[cIDX];
//
// VIDYA ...
double cVidya = conditions.vidyaBuffer[cIDX];
double cVidyaState = conditions.vidyaStateBuffer[cIDX];
//
// TREND ...
double cTrend = conditions.trendBuffer[cIDX];
double cTrendState = conditions.trendStateBuffer[cIDX];
//
// Generating Conditions ...
//
bool isSWLOverBox = cSWL > box.lower;
bool isSWHUnderBox = cSWH < box.upper;
//
bool isValeOverBox = cVale > box.lower;
bool isPeakUnderBox = cPeak < box.upper;
//
bool hasBullishPress =
// isBullish &&
(isSWLOverBox ||
isValeOverBox);
//
bool hasBearishPress =
// isBearish &&
(isSWHUnderBox ||
isPeakUnderBox);
//
double trends[] = {
cMAH,
cMAC,
cMAL,
cKI,
cTKI,
cFast,
cVidya,
cTrend //
};
double trendMax = GetMax(trends);
double trendMin = GetMin(trends);
Copy(
trends,
sls //
);
//
bool isCloseOverMax = cBar.close > trendMax;
bool isCloseUnderMin = cBar.close < trendMin;
//
bool isStateBullish =
cKIState > 0 &&
cTKIState > 0 &&
cFastState > 0 &&
cTrendState > 0 &&
cVidyaState > 0;
//
bool isStateBearish =
cKIState < 0 &&
cTKIState < 0 &&
cFastState < 0 &&
cTrendState < 0 &&
cVidyaState < 0;
//
bool hasBullishTrend =
// isBullish &&
isStateBullish &&
isCloseOverMax;
//
bool hasBearishTrend =
// isBearish &&
isStateBearish &&
isCloseUnderMin;
//
// Summarizing ...
//
bool canTriggerLong =
// isBullish &&
hasBullishPress &&
hasBullishTrend;
//
bool canTriggerShort =
// isBearish &&
hasBearishPress &&
hasBearishTrend;
//
result = canTriggerLong ||
canTriggerShort;
if (result)
{
//
dir = canTriggerLong
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
Print("Triggered ...");
}
//
// Cleanup Resources ...
//
cBar.Clean();
Clean(trends);
conditions.Clean();
//
return result;
}
File diff suppressed because it is too large Load Diff
+98 -162
View File
@@ -454,18 +454,18 @@ class XCXCAEASignaller : XCBase
//
// Setup Conditions ...
XBoxZone signalBox;
bool hasSignalBox = false;
XBoxZone decisionZone;
bool hasDecisionZone = false;
XCAEAConditions conditions;
ENUM_X_DIRECTION signalBoxDir = X_DIRECTION_NONE;
ENUM_X_DIRECTION decisionZoneDir = X_DIRECTION_NONE;
//
// Checking Test Signal ...
hasSignalBox = TestDetectSignal(
// Checking Signal's Decision Zone ...
hasDecisionZone = DetectDecisionZone(
helper,
drawer,
signalBox,
signalBoxDir,
decisionZone,
decisionZoneDir,
conditions,
zIndex,
loopback //
@@ -473,22 +473,22 @@ class XCXCAEASignaller : XCBase
//
// Make Signal Box UnAvailable ...
if (hasSignalBox)
if (hasDecisionZone)
{
//
AddRef(
signalBox,
decisionZone,
unAvailableBoxes //
);
}
//
isBullish = hasSignalBox &&
IsBullish(signalBoxDir);
isBullish = hasDecisionZone &&
IsBullish(decisionZoneDir);
//
isBearish = hasSignalBox &&
IsBearish(signalBoxDir);
isBearish = hasDecisionZone &&
IsBearish(decisionZoneDir);
//
result = isBullish ||
@@ -499,139 +499,17 @@ class XCXCAEASignaller : XCBase
// Do What we Want ...
barTraker.Waits();
//
// Draw Signal Box ...
XCBoxObject *iObj;
bool isCreated = helper.poiDrawer.DrawBox(
signalBox,
iObj //
);
if (isCreated)
{
//
mObjects.Add(iObj);
ZeroMemory(iObj);
//
// Print("Signal Box ...");
}
//
// Prepare Conditions ...
mConditions.symbol = symbol;
mConditions.period = period;
mConditions.time = zBar.time;
//
double spread = GetSpread(symbol);
//
double entry =
isBullish
? signalBox.upper
: signalBox.lower;
//
double sl =
isBullish
? signalBox.lower
: signalBox.upper;
//
double risk =
isBullish
? entry - sl
: sl - entry;
risk += spread;
if (risk >= maxAllowedSLDistanceInPoint * points)
{
//
// Fix Risk in Big Distances ...
double hh5 = zBar.FindHighest(5, MODE_HIGH);
double ll5 = zBar.FindLowest(5, MODE_LOW);
//
double hhll5Delta = hh5 - ll5;
double riskDelta = hhll5Delta / 2;
risk = riskDelta;
}
//
double rewardTP = risk * tpReward;
//
double tp =
isBullish
? entry + rewardTP
: entry - rewardTP;
//
// Filling ...
mConditions.sl = sl;
mConditions.tp = tp;
mConditions.reward = tpReward;
mConditions.pivot =
isBullish
? sl
: entry;
mConditions.point =
isBullish
? entry
: sl;
mConditions.dir = signalBoxDir;
mConditions.provider = "XCAEA";
mConditions.signalBox = signalBox;
mConditions.setupTime = zBar.time;
mConditions.dir = decisionZoneDir;
mConditions.conditions = conditions;
//
// Targets Preparing ...
if (useTargets)
{
//
// Select RF Rewards ...
if (continuesRFTillTarget)
{
//
double rfReward = 1;
while (rfReward < tpReward)
{
//
double rewardRF = risk * rfReward;
double rfTP =
isBullish
? entry + rewardRF
: entry - rewardRF;
//
Add(
rfTP,
mConditions.targets //
);
//
rfReward++;
}
}
else
{
//
double rfReward = 2;
//
double rewardRF = risk * rfReward;
double rfTP =
isBullish
? entry + rewardRF
: entry - rewardRF;
//
Add(
rfTP,
mConditions.targets //
);
}
}
mConditions.decisionZone = decisionZone;
}
//
@@ -644,8 +522,8 @@ class XCXCAEASignaller : XCBase
pPBar.Clean();
//
signalBox.Clean();
conditions.Clean();
decisionZone.Clean();
//
return result;
@@ -682,6 +560,12 @@ class XCXCAEASignaller : XCBase
datetime setupTime = conditions.setupTime;
ENUM_X_DIRECTION setupDir = conditions.dir;
//
helper.GetConditions(
conditions.conditions,
barIndex //
);
//
bool isBullish = IsBullish(setupDir);
bool isBearish = IsBearish(setupDir);
@@ -716,35 +600,61 @@ class XCXCAEASignaller : XCBase
//
// Checking Trigger Conditions ...
double sls[];
double sl = 0;
double tp = 0;
ENUM_X_DIRECTION triggerDir;
//
// Checking Trigger Cond 1 ...
bool canTriggerCond1 = CanTriggerCond1(
helper,
conditions.signalBox,
conditions.decisionZone,
triggerDir,
sls,
sl,
tp,
barIndex //
);
//
// Checking Trigger Cond 2 ...
bool canTriggerCond2 = CanTriggerCond2(
helper,
conditions.decisionZone,
triggerDir,
sl,
tp,
barIndex //
);
//
// Update Signal Box To ...
conditions.signalBox.to = cTime;
conditions.decisionZone.to = cTime;
//
isBullish = IsBullish(triggerDir);
isBearish = IsBearish(triggerDir);
//
// Try To Draw Signal Box ...
XCBoxObject *iObj;
helper.poiDrawer.DrawBox(
conditions.signalBox,
bool has = helper.poiDrawer.DrawBox(
conditions.decisionZone,
iObj //
);
if (has)
{
mObjects.Add(iObj);
}
ZeroMemory(iObj);
//
result = canTriggerCond1;
// Summarizing Result ...
result =
canTriggerCond1 ||
canTriggerCond2;
//
isBullish = result &&
IsBullish(triggerDir);
isBearish = result &&
IsBearish(triggerDir);
//
if (result)
{
//
@@ -758,19 +668,35 @@ class XCXCAEASignaller : XCBase
conditions.entry = entry;
//
double slsMax = GetMax(sls);
double slsMin = GetMin(sls);
double sl = isBullish
? slsMin
: slsMax;
if (tp > 0.0)
{
//
Add(
tp,
conditions.targets //
);
}
//
double risk = MathAbs(entry - sl);
double tp =
double reward = (risk * conditions.reward);
tp =
isBullish
? entry + (risk * conditions.reward)
: entry - (risk * conditions.reward);
? entry + reward
: entry - reward;
//
// Handling RF ...
double rfReward = risk * 1.85;
double rfPrice =
isBullish
? entry + rfReward
: entry - rfReward;
Add(
rfPrice,
conditions.targets //
);
//
conditions.sl = sl;
conditions.tp = tp;
@@ -788,20 +714,30 @@ class XCXCAEASignaller : XCBase
if (!result)
{
//
// Check Box Age ...
int age = conditions.GetSetupAge();
bool has = age <= maxAllowedSetupAge;
if (!has)
{
conditions.Clean();
}
//
// Check Box Price ...
has = IsBoxBreaked(
helper,
conditions.decisionZone,
barIndex //
);
if (has)
{
conditions.Clean();
}
}
//
// Cleanup ...
//
Clean(sls);
//
return result;
}