last ...
This commit is contained in:
@@ -142,7 +142,7 @@ void OnDeinit(const int reason)
|
|||||||
// REASON_CLOSE 9 Terminal closed
|
// REASON_CLOSE 9 Terminal closed
|
||||||
|
|
||||||
//
|
//
|
||||||
eaSignaller.DeInit();
|
// eaSignaller.DeInit();
|
||||||
|
|
||||||
//
|
//
|
||||||
ZeroMemory(eaAlert);
|
ZeroMemory(eaAlert);
|
||||||
@@ -235,6 +235,7 @@ void OnTick()
|
|||||||
.mConditionsCollection[i]);
|
.mConditionsCollection[i]);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
// If Triggered ...
|
||||||
if (has)
|
if (has)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -242,9 +243,19 @@ void OnTick()
|
|||||||
eaConditions = eaSignaller.mConditionsCollection[i];
|
eaConditions = eaSignaller.mConditionsCollection[i];
|
||||||
break;
|
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);
|
has = IsValidIndex(idx);
|
||||||
if (has)
|
if (has)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ struct XCAEAStrategyConditions
|
|||||||
double tp;
|
double tp;
|
||||||
double pivot;
|
double pivot;
|
||||||
double point;
|
double point;
|
||||||
|
double entry;
|
||||||
|
double reward;
|
||||||
string provider;
|
string provider;
|
||||||
double targets[];
|
double targets[];
|
||||||
|
|
||||||
@@ -103,6 +105,8 @@ struct XCAEAStrategyConditions
|
|||||||
tp = 0;
|
tp = 0;
|
||||||
pivot = 0;
|
pivot = 0;
|
||||||
point = 0;
|
point = 0;
|
||||||
|
entry = 0;
|
||||||
|
reward = 0;
|
||||||
|
|
||||||
//
|
//
|
||||||
symbol = NULL;
|
symbol = NULL;
|
||||||
@@ -1211,3 +1215,250 @@ bool TestDetectSignal(
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
@@ -122,8 +122,8 @@ class XCXCAEASignaller : XCBase
|
|||||||
|
|
||||||
//
|
//
|
||||||
inputs.x3maInputs.showFast = true;
|
inputs.x3maInputs.showFast = true;
|
||||||
inputs.x3maInputs.showSlow = false;
|
inputs.x3maInputs.showSlow = true;
|
||||||
inputs.x3maInputs.showMedium = false;
|
inputs.x3maInputs.showMedium = true;
|
||||||
|
|
||||||
//
|
//
|
||||||
inputs.caInputs.showMAH = true;
|
inputs.caInputs.showMAH = true;
|
||||||
@@ -141,8 +141,8 @@ class XCXCAEASignaller : XCBase
|
|||||||
//
|
//
|
||||||
inputs.caInputs.showKI = false;
|
inputs.caInputs.showKI = false;
|
||||||
inputs.caInputs.showTKI = false;
|
inputs.caInputs.showTKI = false;
|
||||||
inputs.caInputs.showVidya = false;
|
inputs.caInputs.showVidya = true;
|
||||||
inputs.caInputs.showTrend = false;
|
inputs.caInputs.showTrend = true;
|
||||||
inputs.caInputs.showPeakAndValeGolden = false;
|
inputs.caInputs.showPeakAndValeGolden = false;
|
||||||
inputs.caInputs.showSupportAndResistance = false;
|
inputs.caInputs.showSupportAndResistance = false;
|
||||||
|
|
||||||
@@ -520,6 +520,7 @@ class XCXCAEASignaller : XCBase
|
|||||||
// Prepare Conditions ...
|
// Prepare Conditions ...
|
||||||
mConditions.symbol = symbol;
|
mConditions.symbol = symbol;
|
||||||
mConditions.period = period;
|
mConditions.period = period;
|
||||||
|
mConditions.time = zBar.time;
|
||||||
|
|
||||||
//
|
//
|
||||||
double spread = GetSpread(symbol);
|
double spread = GetSpread(symbol);
|
||||||
@@ -568,6 +569,7 @@ class XCXCAEASignaller : XCBase
|
|||||||
// Filling ...
|
// Filling ...
|
||||||
mConditions.sl = sl;
|
mConditions.sl = sl;
|
||||||
mConditions.tp = tp;
|
mConditions.tp = tp;
|
||||||
|
mConditions.reward = tpReward;
|
||||||
mConditions.pivot =
|
mConditions.pivot =
|
||||||
isBullish
|
isBullish
|
||||||
? sl
|
? sl
|
||||||
@@ -659,12 +661,16 @@ class XCXCAEASignaller : XCBase
|
|||||||
*/
|
*/
|
||||||
bool DetectSignalTrigger(
|
bool DetectSignalTrigger(
|
||||||
XCAEAStrategyConditions &conditions,
|
XCAEAStrategyConditions &conditions,
|
||||||
int maxAllowedSetupAge = 60 //
|
int barIndex = 0,
|
||||||
|
int maxAllowedSetupAge = 200 //
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
barIndex = NormalizeInt(barIndex, 0);
|
||||||
|
|
||||||
//
|
//
|
||||||
result = conditions.IsSetuped();
|
result = conditions.IsSetuped();
|
||||||
if (!result)
|
if (!result)
|
||||||
@@ -709,51 +715,66 @@ class XCXCAEASignaller : XCBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Checking Breakeout or Rejection ...
|
// Checking Trigger Conditions ...
|
||||||
|
double sls[];
|
||||||
//
|
ENUM_X_DIRECTION triggerDir;
|
||||||
XOHCL cBar;
|
bool canTriggerCond1 = CanTriggerCond1(
|
||||||
result = cBar.Init(
|
helper,
|
||||||
conditions.symbol,
|
conditions.signalBox,
|
||||||
conditions.period,
|
triggerDir,
|
||||||
cIndex //
|
sls,
|
||||||
|
barIndex //
|
||||||
);
|
);
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
cBar.Clean();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Retrieving Conditions ...
|
// Update Signal Box To ...
|
||||||
XCAEAConditions helperConditions;
|
conditions.signalBox.to = cTime;
|
||||||
result = helper.GetConditions(
|
|
||||||
helperConditions,
|
//
|
||||||
cIndex,
|
isBullish = IsBullish(triggerDir);
|
||||||
5 //
|
isBearish = IsBearish(triggerDir);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Try To Draw Signal Box ...
|
||||||
|
XCBoxObject *iObj;
|
||||||
|
helper.poiDrawer.DrawBox(
|
||||||
|
conditions.signalBox,
|
||||||
|
iObj //
|
||||||
);
|
);
|
||||||
if (!result)
|
ZeroMemory(iObj);
|
||||||
{
|
|
||||||
//
|
|
||||||
cBar.Clean();
|
|
||||||
conditions.Clean();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Checking Breakeout or Rejection ...
|
|
||||||
// TODO: Handle this ...
|
|
||||||
bool isBreakeout = false;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
result = canTriggerCond1;
|
||||||
if (result)
|
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.triggerTime = cTime;
|
||||||
conditions.type = isBullish
|
conditions.type = isBullish
|
||||||
? X_POSITION_TYPE_LONG
|
? 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 ...
|
// Cleanup ...
|
||||||
|
|
||||||
//
|
//
|
||||||
cBar.Clean();
|
Clean(sls);
|
||||||
conditions.Clean();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user