This commit is contained in:
2025-05-06 21:22:41 +03:30
parent 50a6c60b9f
commit 8258c7a7ef
3 changed files with 339 additions and 44 deletions
+12 -1
View File
@@ -142,7 +142,7 @@ void OnDeinit(const int reason)
// REASON_CLOSE 9 Terminal closed
//
eaSignaller.DeInit();
// eaSignaller.DeInit();
//
ZeroMemory(eaAlert);
@@ -235,6 +235,7 @@ void OnTick()
.mConditionsCollection[i]);
//
// If Triggered ...
if (has)
{
//
@@ -242,9 +243,19 @@ void OnTick()
eaConditions = eaSignaller.mConditionsCollection[i];
break;
}
//
// Check Condition Validation ...
has = eaSignaller.mConditionsCollection[i].IsValid() &&
eaSignaller.mConditionsCollection[i].IsSetuped();
if (!has)
{
idx = i;
}
}
//
// Remove Setuped Condition if provided IDX ...
has = IsValidIndex(idx);
if (has)
{
+251
View File
@@ -69,6 +69,8 @@ struct XCAEAStrategyConditions
double tp;
double pivot;
double point;
double entry;
double reward;
string provider;
double targets[];
@@ -103,6 +105,8 @@ struct XCAEAStrategyConditions
tp = 0;
pivot = 0;
point = 0;
entry = 0;
reward = 0;
//
symbol = NULL;
@@ -1210,4 +1214,251 @@ bool TestDetectSignal(
return result;
}
//
// 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;
}
//
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;
}
//
+76 -43
View File
@@ -122,8 +122,8 @@ class XCXCAEASignaller : XCBase
//
inputs.x3maInputs.showFast = true;
inputs.x3maInputs.showSlow = false;
inputs.x3maInputs.showMedium = false;
inputs.x3maInputs.showSlow = true;
inputs.x3maInputs.showMedium = true;
//
inputs.caInputs.showMAH = true;
@@ -141,8 +141,8 @@ class XCXCAEASignaller : XCBase
//
inputs.caInputs.showKI = false;
inputs.caInputs.showTKI = false;
inputs.caInputs.showVidya = false;
inputs.caInputs.showTrend = false;
inputs.caInputs.showVidya = true;
inputs.caInputs.showTrend = true;
inputs.caInputs.showPeakAndValeGolden = false;
inputs.caInputs.showSupportAndResistance = false;
@@ -520,6 +520,7 @@ class XCXCAEASignaller : XCBase
// Prepare Conditions ...
mConditions.symbol = symbol;
mConditions.period = period;
mConditions.time = zBar.time;
//
double spread = GetSpread(symbol);
@@ -568,6 +569,7 @@ class XCXCAEASignaller : XCBase
// Filling ...
mConditions.sl = sl;
mConditions.tp = tp;
mConditions.reward = tpReward;
mConditions.pivot =
isBullish
? sl
@@ -659,12 +661,16 @@ class XCXCAEASignaller : XCBase
*/
bool DetectSignalTrigger(
XCAEAStrategyConditions &conditions,
int maxAllowedSetupAge = 60 //
int barIndex = 0,
int maxAllowedSetupAge = 200 //
)
{
//
bool result = false;
//
barIndex = NormalizeInt(barIndex, 0);
//
result = conditions.IsSetuped();
if (!result)
@@ -709,51 +715,66 @@ class XCXCAEASignaller : XCBase
}
//
// Checking Breakeout or Rejection ...
//
XOHCL cBar;
result = cBar.Init(
conditions.symbol,
conditions.period,
cIndex //
// Checking Trigger Conditions ...
double sls[];
ENUM_X_DIRECTION triggerDir;
bool canTriggerCond1 = CanTriggerCond1(
helper,
conditions.signalBox,
triggerDir,
sls,
barIndex //
);
if (!result)
{
//
cBar.Clean();
//
return result;
}
//
// Retrieving Conditions ...
XCAEAConditions helperConditions;
result = helper.GetConditions(
helperConditions,
cIndex,
5 //
// Update Signal Box To ...
conditions.signalBox.to = cTime;
//
isBullish = IsBullish(triggerDir);
isBearish = IsBearish(triggerDir);
//
// Try To Draw Signal Box ...
XCBoxObject *iObj;
helper.poiDrawer.DrawBox(
conditions.signalBox,
iObj //
);
if (!result)
{
//
cBar.Clean();
conditions.Clean();
//
return result;
}
//
// Checking Breakeout or Rejection ...
// TODO: Handle this ...
bool isBreakeout = false;
ZeroMemory(iObj);
//
result = canTriggerCond1;
if (result)
{
//
// Reconfigure Position TP/SL Entry and etc ...
//
double entry = GetEntry(
conditions.symbol,
triggerDir //
);
conditions.entry = entry;
//
double slsMax = GetMax(sls);
double slsMin = GetMin(sls);
double sl = isBullish
? slsMin
: slsMax;
//
double risk = MathAbs(entry - sl);
double tp =
isBullish
? entry + (risk * conditions.reward)
: entry - (risk * conditions.reward);
//
conditions.sl = sl;
conditions.tp = tp;
conditions.dir = triggerDir;
conditions.triggerTime = cTime;
conditions.type = isBullish
? X_POSITION_TYPE_LONG
@@ -762,12 +783,24 @@ class XCXCAEASignaller : XCBase
//
}
//
// Validating Conditions if not Triggered ...
if (!result)
{
//
int age = conditions.GetSetupAge();
bool has = age <= maxAllowedSetupAge;
if (!has)
{
conditions.Clean();
}
}
//
// Cleanup ...
//
cBar.Clean();
conditions.Clean();
Clean(sls);
//
return result;