Complete Strategy 4 Signals ...

This commit is contained in:
2025-10-26 19:13:04 +03:30
parent de338d8916
commit 8f317a3b1d
4 changed files with 3071 additions and 63 deletions
@@ -907,7 +907,10 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
//
// Target Flags ...
bool hasPartialCloseOnTp1 = true;
bool hasPartialCloseOnTp1 = false;
//
bool doRFOnEntryOnTP1 = false;
//
// Draw Flags ...
@@ -918,6 +921,10 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
bool drawMarketStructureOrderFlow = true;
XPOIDrawConfig iDrawConfig;
//
drawLeg = false;
drawOrderFlow = false;
//
// Signal Checking ...
@@ -927,15 +934,16 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
//
// Check Market ...
result = HasLeg() &&
HasOrderFlow() &&
orderFlowDir == leg.dir;
if (result)
{
//
result = false;
DebugBreak();
}
// result = HasLeg() &&
// HasOrderFlow() &&
// orderFlowDir == leg.dir;
// result = HasBearishOrderFlow();
// if (result)
// {
// //
// result = false;
// DebugBreak();
// }
//
// Signaller 1 ...
@@ -1125,9 +1133,9 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
//
iTarget.Clean();
iTarget.target = tp1;
iTarget.doRFOnEntry = true;
iTarget.actingDistance = 5;
iTarget.volumeMultiplier = 0.8;
iTarget.doRFOnEntry = doRFOnEntryOnTP1;
//
AddRef(iTarget, targets);
@@ -2025,6 +2033,23 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
/**
* Check Bar Has Signal Based on Strategy 4 ...
*
* Strategy 4:
* ===========
* - Works Based on Order Flow ...
* - Looking for new and Fresh Order Flow ...
* - Validate Bar is Inside Order Flow ...
* - Validate Bar has Proper Pattern ...
* - Validate Bar Based on ATR Band in two Step:
* - Step 1: Bars is Inside ATR Band (Middle) ...
* - Step 2: Trigger Bars Close Price based on ATR Band ...
* - Validate Order Flow based on Market Structure Zone ...
* - Validate Trigger Bar based on InDirectional Market Structure Zones ...
*
* Manipulations:
* ================
* there are Some Flags properties to Change Validations in Strategy ...
* we can use them for Testing Purposes ...
*
* @param bar: XOHCL, reference to Bar ...
* @param zone: XBoxZone, reference to holds affected zone ...
* @param targets: XTarget, reference to detected Signal's Targets collections ...
@@ -2062,6 +2087,9 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
bool validateByBarPatterns = true;
bool validateByBarInsideATRBand = true;
bool validateByBarBasedOnATRBand = true;
bool validateMarketStructureHasDirectionalZone = true;
bool validateMarketStructureDirectionalZoneInsideOrderFlow = true;
bool validateMarketStructureHasNotInDirectionalZoneOrUnReachedTP = true;
//
// Define Requirements ...
@@ -2098,9 +2126,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// Retrieve pBar Patterns ...
XPatternAnalysis pBarPatterns;
XPatternAnalysisConfig patternConfig = structureConfig.barsAnalysisConfig;
// patternConfig.Default();
// patternConfig.supportAndResistanceLoopbackLength = 21;
// patternConfig.supportAndResistanceValidationLength = 7;
//
poiDetector.AnalyseBarPatterns(
@@ -2111,7 +2136,19 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
//
// Detecting OrderFlow ...
bool hasOrderFlow = HasOrderFlow();
XBoxZone oFlow[];
bool hasOrderFlow = poiDetector.HasOrderFlow(
p3Bar,
dir,
oFlow,
structureConfig.orderFlowValidation,
structureConfig.orderFlowUseOB,
structureConfig.orderFlowUseFVG,
structureConfig.orderFlowUseSupportAndResistance,
patternConfig.supportAndResistanceLoopbackLength,
patternConfig.supportAndResistanceValidationLength,
structureConfig.loopback //
);
//
double atrBandUpper = EMPTY_VALUE;
@@ -2139,15 +2176,16 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
double orderFlowLower = 0;
//
int idx = GetHighest(orderFlow);
int idx = -1;
idx = GetHighest(oFlow);
if (IsValidIndex(idx))
{
orderFlowUpper = orderFlow[idx].upper;
orderFlowUpper = oFlow[idx].upper;
}
idx = GetLowest(orderFlow);
idx = GetLowest(oFlow);
if (IsValidIndex(idx))
{
orderFlowLower = orderFlow[idx].lower;
orderFlowLower = oFlow[idx].lower;
}
//
@@ -2179,6 +2217,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
//
// Bullish ...
bool isPBarHasBullishPatterns =
result &&
// (bar.close > pBar.low ||
// bar.open > pBar.low) &&
(
@@ -2194,6 +2233,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
//
// Bearish ...
bool isPBarHasBearishPatterns =
result &&
// (bar.close < pBar.high ||
// bar.open < pBar.high) &&
(
@@ -2296,46 +2336,171 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
}
//
result = false;
isBullish = false;
isBearish = false;
if (result)
// for Bullish has Support ...
// for Bearish has Resistance ...
if (result && validateMarketStructureHasDirectionalZone)
{
// //
// UpdateToTime(orderFlow, bar.time);
// poiDrawer.DrawZones(orderFlow, structureDrawConfig.drawConfig);
// poiDrawer.DrawPatternAnalysis(pBarPatterns, structureDrawConfig.barAnalysisDrawConfig);
//
XOHCL tmpBar;
XPivot tmpPivot;
XBoxZone support;
XBoxZone resistance;
// //
// // Draw ATR Band Middle ...
// if (NotEmptyZero(atrBandMiddle))
// {
// //
// XPOIDrawConfig iConfig = structureDrawConfig.drawConfig;
// iConfig.trendRayLeft = false;
// iConfig.trendRayRight = false;
//
// Check Market Strucutre Has Support / Resistance ...
bool hasSupport = pBarPatterns.IsSupport();
bool hasResistance = pBarPatterns.IsResistance();
// //
// datetime to = bar.time;
// datetime from = p2Bar.BeforeOn();
// string trendName = "ATRBandMiddle_" + ToXString(TimeToSeconds(p2Bar.time));
// poiDrawer.DrawTrendLine(
// trendName,
// atrBandMiddle,
// from,
// atrBandMiddle,
// to,
// iConfig,
// clrYellow //
// );
//
// Retrieve Support / Resistance Zone ...
if (hasSupport)
{
pBarPatterns.GetSupport(tmpBar, tmpPivot, support);
}
if (hasResistance)
{
pBarPatterns.GetResistance(tmpBar, tmpPivot, resistance);
}
// //
// iConfig.Clean();
// }
//
// Validate Support and Resistance by Order Flow ...
// //
// Print("OrderFlow ...");
// DebugBreak();
//
// Converts Order Flow to Zone ...
XBoxZone ofZone;
bool hasOFBox = ToBox(ofZone, oFlow);
//
// Check Market Strucutre Support and Resistance Validation ...
if (validateMarketStructureDirectionalZoneInsideOrderFlow)
{
//
hasSupport =
hasOFBox &&
hasSupport &&
ofZone.lower < support.lower &&
ofZone.upper > support.upper;
//
hasResistance =
hasOFBox &&
hasResistance &&
ofZone.lower < resistance.lower &&
ofZone.upper > resistance.upper;
}
//
// Validate Directional Support or Resistance Exists ...
//
isBullish =
isBullish &&
hasSupport;
//
isBearish =
isBearish &&
hasResistance;
//
// Cleanup ...
ofZone.Clean();
tmpBar.Clean();
support.Clean();
tmpPivot.Clean();
resistance.Clean();
//
// Summarize Result ...
result = isBullish || isBearish;
}
//
// Validate Makret Structure Has Not Indirectional Zone ...
if (result && validateMarketStructureHasNotInDirectionalZoneOrUnReachedTP)
{
//
XOHCL tmpBar;
XPivot tmpPivot;
XBoxZone support;
XBoxZone resistance;
//
// Check Market Strucutre Has Support / Resistance ...
bool hasSupport = pBarPatterns.IsSupport();
bool hasResistance = pBarPatterns.IsResistance();
//
// Retrieve Support / Resistance Zone ...
if (hasSupport)
{
pBarPatterns.GetSupport(tmpBar, tmpPivot, support);
}
if (hasResistance)
{
pBarPatterns.GetResistance(tmpBar, tmpPivot, resistance);
}
//
// Converts Order Flow to Zone ...
XBoxZone ofZone;
bool hasOFBox = ToBox(ofZone, oFlow);
//
bool hasIndirectionalZone =
(isBullish && hasResistance) ||
(isBearish && hasSupport);
if (hasIndirectionalZone)
{
//
// Here we Have to Validate Zone Place ...
//
double point = GetPoints(bar.symbol);
double entry = GetEntry(bar.symbol, dir);
double slAddition = slAdditionDistance > 0 ? slAdditionDistance : 0;
double risk = MathAbs(entry - (isBullish ? oFlow[0].lower : oFlow[0].upper)) + (slAddition * point);
double reward = (defaultSignalR2R * risk);
double tp = isBullish
? entry + reward
: entry - reward;
//
// Bullish ...
if (isBullish && hasResistance)
{
hasResistance = resistance.lower <= tp;
}
//
// Bearish ...
if (isBearish && hasSupport)
{
hasSupport = support.upper >= tp;
}
}
//
isBullish =
isBullish &&
!hasResistance;
//
isBearish =
isBearish &&
!hasSupport;
//
// Cleanup ...
ofZone.Clean();
tmpBar.Clean();
support.Clean();
tmpPivot.Clean();
resistance.Clean();
//
// Summarize Result ...
result = isBullish || isBearish;
}
//
@@ -2377,6 +2542,16 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// Manage Stops ...
if (result)
{
//
// Since Stop Management Changes Zones Edge(s) ...
// we do it here for Refining Zone ...
//
poiDrawer.DrawZone(zone, structureDrawConfig.drawConfig);
poiDrawer.DrawPatternAnalysis(pBarPatterns, structureDrawConfig.barAnalysisDrawConfig);
//
DebugBreak();
}
//
@@ -2387,6 +2562,38 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// Prepare Targets ...
if (result)
{
//
XTarget iTarget;
//
// Calculate Requirements ...
double point = GetPoints(bar.symbol);
double entry = GetEntry(bar.symbol, dir);
double slAddition = slAdditionDistance > 0 ? slAdditionDistance : 0;
double risk = MathAbs(entry - (isBullish ? zone.lower : zone.upper)) + (slAddition * point);
double reward = (defaultSignalR2R * risk);
double tp = isBullish
? entry + reward
: entry - reward;
//
// High Risk Target is Used to Protect In Profit Positiions
// from Reversal Patterns ...
double highRiskR2r = (defaultSignalR2R / 5) * 4;
double highRiskReward = highRiskR2r * risk;
double highRiskTP = isBullish
? entry + highRiskReward
: entry - highRiskReward;
iTarget.Clean();
iTarget.actingDistance = 5;
iTarget.doRFOnEntry = true;
iTarget.target = highRiskTP;
iTarget.volumeMultiplier = 0.8;
AddRef(iTarget, targets);
//
// Cleanup ...
iTarget.Clean();
}
//