last works ...
This commit is contained in:
@@ -396,19 +396,29 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
//
|
||||
// Preparing Signal Targets ...
|
||||
XTarget iTarget;
|
||||
double spread = GetSpread(iZone.symbol);
|
||||
double entry = GetEntry(iZone.symbol, iZone.dir);
|
||||
double risk = MathAbs(entry - (isBullish ? iZone.lower : iZone.upper));
|
||||
double spread = GetSpread(symbol);
|
||||
double entry = GetEntry(symbol, iZone.dir);
|
||||
double risk = MathAbs(entry - slPrice);
|
||||
|
||||
//
|
||||
// Ignore Signal if Risk is too Much ...
|
||||
bool hasToomuchRisk = risk > (iZone.upper - iZone.lower) + slAddition + (100 * _point);
|
||||
if (hasToomuchRisk)
|
||||
{
|
||||
//
|
||||
iZone.Clean();
|
||||
Print("Too Much Risk ...");
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Partial Close Position if Reached TP 1.5 ...
|
||||
iTarget.Clean();
|
||||
iTarget.doRF = false;
|
||||
iTarget.actingDistance = 5;
|
||||
iTarget.doRFOnEntry = false;
|
||||
iTarget.volumeMultiplier = 0.5;
|
||||
iTarget.target = isBullish ? entry + (4 * risk) : entry - (4 * risk);
|
||||
AddRef(iTarget, iTargets);
|
||||
// iTarget.Clean();
|
||||
// iTarget.doRF = false;
|
||||
// iTarget.actingDistance = 5;
|
||||
// iTarget.doRFOnEntry = false;
|
||||
// iTarget.volumeMultiplier = 0.5;
|
||||
// iTarget.target = isBullish ? entry + (4 * risk) : entry - (4 * risk);
|
||||
// AddRef(iTarget, iTargets);
|
||||
|
||||
//
|
||||
// Handle Ignore Signal Targets if Forced ...
|
||||
@@ -429,14 +439,15 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
|
||||
//
|
||||
// Prepare Founded Signal ...
|
||||
has = PrepareSignal(
|
||||
iSignal,
|
||||
iDir,
|
||||
iTargets,
|
||||
0, // Use Default R2R ...
|
||||
slPrice, // Provided Price for SL ...
|
||||
0 // Specified Risk in Point ....
|
||||
);
|
||||
has = iZone.IsValid() &&
|
||||
PrepareSignal(
|
||||
iSignal,
|
||||
iDir,
|
||||
iTargets,
|
||||
0, // Use Default R2R ...
|
||||
slPrice, // Provided Price for SL ...
|
||||
0 // Specified Risk in Point ....
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
@@ -492,51 +503,57 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
|
||||
//
|
||||
// Force Hedging ...
|
||||
bool forceHedging = (positionsCount >= 2);
|
||||
if (forceHedging)
|
||||
{
|
||||
//
|
||||
// Minimum Required Reward ...
|
||||
double minRequiredReward = 1.5;
|
||||
// bool forceHedging = (positionsCount >= 2);
|
||||
// if (forceHedging)
|
||||
// {
|
||||
// //
|
||||
// // Minimum Required Reward ...
|
||||
// double minRequiredReward = 1.5;
|
||||
|
||||
//
|
||||
// Summarizing Risk and Reward of Collections ...
|
||||
double risk = 0;
|
||||
double reward = 0;
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
risk += positions[i].GetRisk() + positions[i].commission + (-1 * positions[i].swap);
|
||||
reward += positions[i].profit;
|
||||
}
|
||||
// //
|
||||
// // Summarizing Risk and Reward of Collections ...
|
||||
// // double risk = 0;
|
||||
// // double volume = 0;
|
||||
// // double reward = 0;
|
||||
// // for (int i = 0; i < positionsCount; i++)
|
||||
// // {
|
||||
// // //
|
||||
// // risk += positions[i].GetRisk() + positions[i].commission + (-1 * positions[i].swap);
|
||||
// // reward += positions[i].profit;
|
||||
// // volume += positions[i].volume;
|
||||
// // }
|
||||
|
||||
//
|
||||
// Calculating Can Hedge rops ...
|
||||
has = reward >= (risk * minRequiredReward);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
iGuard.Clean();
|
||||
iGuard.force = true;
|
||||
iGuard.symbol = symbol;
|
||||
iGuard.period = period;
|
||||
iGuard.provider = name;
|
||||
iGuard.time = TimeCurrent();
|
||||
iGuard.action = X_GUARD_ACTION_HEDGE;
|
||||
// // //
|
||||
// // risk *= volume;
|
||||
// // reward *= volume;
|
||||
|
||||
//
|
||||
// Validate Guard ...
|
||||
has = iGuard.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iGuard,
|
||||
guards //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
// // //
|
||||
// // // Calculating Can Hedge rops ...
|
||||
// // has = reward >= (risk * minRequiredReward);
|
||||
// // if (has)
|
||||
// // {
|
||||
// // //
|
||||
// // iGuard.Clean();
|
||||
// // iGuard.force = true;
|
||||
// // iGuard.symbol = symbol;
|
||||
// // iGuard.period = period;
|
||||
// // iGuard.provider = name;
|
||||
// // iGuard.time = TimeCurrent();
|
||||
// // iGuard.action = X_GUARD_ACTION_HEDGE;
|
||||
|
||||
// // //
|
||||
// // // Validate Guard ...
|
||||
// // has = iGuard.IsValid();
|
||||
// // if (has)
|
||||
// // {
|
||||
// // //
|
||||
// // AddRef(
|
||||
// // iGuard,
|
||||
// // guards //
|
||||
// // );
|
||||
// // }
|
||||
// // }
|
||||
// }
|
||||
|
||||
//
|
||||
result = ArraySize(guards);
|
||||
@@ -579,27 +596,58 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// result = Strategy2HasSignal(
|
||||
// bar,
|
||||
// zone,
|
||||
// targets,
|
||||
// dir //
|
||||
// );
|
||||
// Signaller Flags ...
|
||||
bool useSignaller1 = true;
|
||||
bool useSignaller2 = true;
|
||||
bool useSignaller3 = true;
|
||||
bool useSignaller4 = false;
|
||||
|
||||
//
|
||||
// if (!result)
|
||||
// {
|
||||
// //
|
||||
// result = Strategy3HasSignal(
|
||||
// bar,
|
||||
// zone,
|
||||
// targets,
|
||||
// dir //
|
||||
// );
|
||||
// }
|
||||
// Validator Flags ...
|
||||
bool validateByOrderFlow = true;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
// Signaller 1 ...
|
||||
if (!result && useSignaller1)
|
||||
{
|
||||
//
|
||||
result = Strategy1HasSignal(
|
||||
bar,
|
||||
zone,
|
||||
targets,
|
||||
dir //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Signaller 2 ...
|
||||
if (!result && useSignaller2)
|
||||
{
|
||||
//
|
||||
result = Strategy2HasSignal(
|
||||
bar,
|
||||
zone,
|
||||
targets,
|
||||
dir //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Signaller 3 ...
|
||||
if (!result && useSignaller3)
|
||||
{
|
||||
//
|
||||
result = Strategy3HasSignal(
|
||||
bar,
|
||||
zone,
|
||||
targets,
|
||||
dir //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Signaller 4 ...
|
||||
if (!result && useSignaller4)
|
||||
{
|
||||
//
|
||||
result = Strategy4HasSignal(
|
||||
@@ -610,6 +658,40 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Signals by Order Flow ...
|
||||
if (validateByOrderFlow)
|
||||
{
|
||||
//
|
||||
// Detecting OrderFlow ...
|
||||
XBoxZone orderFlow[];
|
||||
ENUM_X_DIRECTION orderFlowDir;
|
||||
bool hasOrderFlow = poiDetector.HasOrderFlow(
|
||||
bar,
|
||||
orderFlowDir,
|
||||
orderFlow,
|
||||
2,
|
||||
false, // Contains OB ...
|
||||
true, // Contains FVG ...
|
||||
false // Contains Support and Resistances ...
|
||||
);
|
||||
|
||||
//
|
||||
bool isBullish = hasOrderFlow &&
|
||||
IsXBullish(dir) &&
|
||||
IsXBullish(orderFlowDir);
|
||||
|
||||
//
|
||||
bool isBearish = hasOrderFlow &&
|
||||
IsXBearish(dir) &&
|
||||
IsXBearish(orderFlowDir);
|
||||
|
||||
//
|
||||
// Summarizing result ...
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
}
|
||||
|
||||
// //
|
||||
// if (result)
|
||||
// {
|
||||
@@ -630,7 +712,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Strategy2HasSignal(
|
||||
bool Strategy1HasSignal(
|
||||
XOHCL &bar,
|
||||
XBoxZone &zone,
|
||||
XTarget &targets[],
|
||||
@@ -922,7 +1004,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Strategy3HasSignal(
|
||||
bool Strategy2HasSignal(
|
||||
XOHCL &bar,
|
||||
XBoxZone &zone,
|
||||
XTarget &targets[],
|
||||
@@ -1238,7 +1320,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Strategy4HasSignal(
|
||||
bool Strategy3HasSignal(
|
||||
XOHCL &bar,
|
||||
XBoxZone &zone,
|
||||
XTarget &targets[],
|
||||
@@ -1310,57 +1392,102 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
|
||||
//
|
||||
// Validate based on Bars Patterns ...
|
||||
|
||||
//
|
||||
// Reading pBar Patterns ...
|
||||
XPatternAnalysis pBarAnalysis;
|
||||
poiDetector.AnalyseBarPatterns(
|
||||
pBar,
|
||||
pBarAnalysis,
|
||||
structureConfig.barsAnalysisConfig //
|
||||
);
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
bool isPBarHasBullishPatterns =
|
||||
(bar.close > pBar.low ||
|
||||
bar.open > pBar.low) &&
|
||||
(
|
||||
//
|
||||
pBarAnalysis.IsPinned(X_DIRECTION_BULLISH) ||
|
||||
pBarAnalysis.IsEngulfed(X_DIRECTION_BULLISH) ||
|
||||
pBarAnalysis.IsMomentum(X_DIRECTION_BULLISH) ||
|
||||
pBarAnalysis.IsPiercing(X_DIRECTION_BULLISH) ||
|
||||
pBarAnalysis.IsSignalKey(X_DIRECTION_BULLISH)
|
||||
//
|
||||
bool validateByBarPatterns = true;
|
||||
if (validateByBarPatterns)
|
||||
{
|
||||
//
|
||||
// Reading pBar Patterns ...
|
||||
XPatternAnalysis pBarAnalysis;
|
||||
poiDetector.AnalyseBarPatterns(
|
||||
pBar,
|
||||
pBarAnalysis,
|
||||
structureConfig.barsAnalysisConfig //
|
||||
);
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
bool isPBarHasBearishPatterns =
|
||||
(bar.close < pBar.high ||
|
||||
bar.open < pBar.high) &&
|
||||
(
|
||||
//
|
||||
pBarAnalysis.IsPinned(X_DIRECTION_BEARISH) ||
|
||||
pBarAnalysis.IsEngulfed(X_DIRECTION_BEARISH) ||
|
||||
pBarAnalysis.IsMomentum(X_DIRECTION_BEARISH) ||
|
||||
pBarAnalysis.IsPiercing(X_DIRECTION_BEARISH) ||
|
||||
pBarAnalysis.IsSignalKey(X_DIRECTION_BEARISH)
|
||||
//
|
||||
);
|
||||
//
|
||||
// Bullish ...
|
||||
bool isPBarHasBullishPatterns =
|
||||
(bar.close > pBar.low ||
|
||||
bar.open > pBar.low) &&
|
||||
(
|
||||
//
|
||||
pBarAnalysis.IsPinned(X_DIRECTION_BULLISH) ||
|
||||
pBarAnalysis.IsEngulfed(X_DIRECTION_BULLISH) ||
|
||||
pBarAnalysis.IsMomentum(X_DIRECTION_BULLISH) ||
|
||||
pBarAnalysis.IsPiercing(X_DIRECTION_BULLISH) ||
|
||||
pBarAnalysis.IsSignalKey(X_DIRECTION_BULLISH)
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
bool isPBarHasBearishPatterns =
|
||||
(bar.close < pBar.high ||
|
||||
bar.open < pBar.high) &&
|
||||
(
|
||||
//
|
||||
pBarAnalysis.IsPinned(X_DIRECTION_BEARISH) ||
|
||||
pBarAnalysis.IsEngulfed(X_DIRECTION_BEARISH) ||
|
||||
pBarAnalysis.IsMomentum(X_DIRECTION_BEARISH) ||
|
||||
pBarAnalysis.IsPiercing(X_DIRECTION_BEARISH) ||
|
||||
pBarAnalysis.IsSignalKey(X_DIRECTION_BEARISH)
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
isBullish =
|
||||
isBullish &&
|
||||
isPBarHasBullishPatterns &&
|
||||
!isPBarHasBearishPatterns;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
isBearish &&
|
||||
isPBarHasBearishPatterns &&
|
||||
!isPBarHasBullishPatterns;
|
||||
|
||||
//
|
||||
// Summarize Result ...
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
}
|
||||
|
||||
//
|
||||
isBullish =
|
||||
isBullish &&
|
||||
isPBarHasBullishPatterns &&
|
||||
!isPBarHasBearishPatterns;
|
||||
// Checking PullBack ...
|
||||
bool validateByPullback = false;
|
||||
if (validateByPullback)
|
||||
{
|
||||
//
|
||||
XBoxZone pullback;
|
||||
ENUM_X_DIRECTION pullbackDir;
|
||||
bool isPullBack = result &&
|
||||
poiDetector.IsPullbackPattern(
|
||||
pBar,
|
||||
pullback,
|
||||
pullbackDir,
|
||||
2,
|
||||
false // Force Break ...
|
||||
);
|
||||
bool isPullbackBullish = isPullBack &&
|
||||
IsXBullish(pullbackDir);
|
||||
bool isPullbackBearish = isPullBack &&
|
||||
IsXBearish(pullbackDir);
|
||||
|
||||
//
|
||||
isBearish =
|
||||
isBearish &&
|
||||
isPBarHasBearishPatterns &&
|
||||
!isPBarHasBullishPatterns;
|
||||
//
|
||||
isBullish =
|
||||
isBullish &&
|
||||
isPullbackBullish;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
isBearish &&
|
||||
isPullbackBearish;
|
||||
|
||||
//
|
||||
// Summarize Result ...
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
@@ -1424,6 +1551,173 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Bar Has Signal Based on Strategy 4 ...
|
||||
*
|
||||
* @param bar: XOHCL, reference to Bar ...
|
||||
* @param zone: XBoxZone, reference to holds affected zone ...
|
||||
* @param targets: XTarget, reference to detected Signal's Targets collections ...
|
||||
* @param dir: ENUM_X_DIRECTION, detected Signal's direction ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Strategy4HasSignal(
|
||||
XOHCL &bar,
|
||||
XBoxZone &zone,
|
||||
XTarget &targets[],
|
||||
ENUM_X_DIRECTION &dir //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
zone.Clean();
|
||||
XClean(targets);
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = bar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Requirements ...
|
||||
|
||||
//
|
||||
XOHCL pBar;
|
||||
XOHCL p2Bar;
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
// Read PBar ...
|
||||
result = bar.GetPreviousBar(pBar);
|
||||
result = result &&
|
||||
pBar.GetPreviousBar(p2Bar);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
pBar.Clean();
|
||||
p2Bar.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Do ...
|
||||
|
||||
//
|
||||
// Detecting OrderFlow ...
|
||||
XBoxZone orderFlow[];
|
||||
bool hasOrderFlow = poiDetector.HasOrderFlow(
|
||||
pBar,
|
||||
dir,
|
||||
orderFlow,
|
||||
2,
|
||||
false, // Contains OB ...
|
||||
true, // Contains FVG ...
|
||||
false // Contains Support and Resistances ...
|
||||
);
|
||||
|
||||
//
|
||||
isBullish = hasOrderFlow &&
|
||||
IsXBullish(dir);
|
||||
|
||||
//
|
||||
isBearish = hasOrderFlow &&
|
||||
IsXBearish(dir);
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
poiDrawer.DrawZones(orderFlow, structureDrawConfig.drawConfig);
|
||||
Print("OrderFlow Detected ...");
|
||||
}
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
result = HasDirection(dir);
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Zone ...
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
zone.Clean();
|
||||
result = ToBox(
|
||||
p2Bar,
|
||||
zone,
|
||||
dir,
|
||||
X_BAR_PATTERN_PINNED //
|
||||
);
|
||||
|
||||
//
|
||||
// Manage Stops ...
|
||||
if (result)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
result = zone.IsValid();
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Targets ...
|
||||
if (result)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zone.Clean();
|
||||
XClean(targets);
|
||||
dir = X_DIRECTION_NONE;
|
||||
}
|
||||
pBar.Clean();
|
||||
p2Bar.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user