last works on XFIMA ...

This commit is contained in:
2025-10-23 21:09:12 +03:30
parent 97bb7b4509
commit d63c5596fc
3 changed files with 278 additions and 211 deletions
+5 -1
View File
@@ -57,7 +57,9 @@ class XCBaseSignaller : public XCBase
ENUM_TIMEFRAMES period; // Period ... ENUM_TIMEFRAMES period; // Period ...
// //
double slAdditionDistance; // SL Addition Distance ... bool ignoreTargets; // Ignore Signal Targets ...
double slAdditionDistance; // SL Addition Distance ...
double maxAllowedRiskDistance; // Max Allowed Risk In Points ...
// //
// Restrictions ... // Restrictions ...
@@ -92,7 +94,9 @@ class XCBaseSignaller : public XCBase
period = _period; period = _period;
// //
ignoreTargets = false;
slAdditionDistance = 0; slAdditionDistance = 0;
maxAllowedRiskDistance = 0;
// //
processAllTicks = _processAllTicks; processAllTicks = _processAllTicks;
+16 -24
View File
@@ -131,17 +131,17 @@ input ENUM_BASE_CORNER barTimeCorner = CORNER_RIGHT_LOWER; // Text Position
// //
// Presentation ... // Presentation ...
input group "Presentation"; input group "Presentation";
input bool showPV = true; // Show PV input bool showPV = false; // Show PV
input bool showHK = true; // Show HK input bool showHK = false; // Show HK
input bool showSAR = true; // Show Sar input bool showSAR = false; // Show Sar
input bool showBars = true; // Show Bars input bool showBars = true; // Show Bars
input bool showMAFast = true; // Show MA Fast input bool showMAFast = false; // Show MA Fast
input bool showMASlow = true; // Show MA Slow input bool showMASlow = false; // Show MA Slow
input bool showMABond = true; // Show MA Bond input bool showMABond = false; // Show MA Bond
input bool showHKBond = true; // Show HK Bond input bool showHKBond = false; // Show HK Bond
input bool showBarTime = true; // Show Bar Time input bool showBarTime = true; // Show Bar Time
input bool showZigZag = true; // Show ZigZag input bool showZigZag = false; // Show ZigZag
input bool showFiboZone = true; // Show Fibo Zone input bool showFiboZone = false; // Show Fibo Zone
// //
input int startCalculationForLastBars = 1500; // Calculate Last n Bars input int startCalculationForLastBars = 1500; // Calculate Last n Bars
@@ -163,16 +163,6 @@ XCBackTesterEA *eaExpert; // EA Expert ...
// Registered Signallers ... // Registered Signallers ...
XCXFIMAStrategy1Signaller *fima1Signaller; // XFIMA1 Signaller ... XCXFIMAStrategy1Signaller *fima1Signaller; // XFIMA1 Signaller ...
//
// XFIMAMarketStructure marketStructure; // POI Analysis Result ...
// XFIMAPatternDetectorConfig detectorConfig; // POI Detector Config ...
// XFIMAMarketStructureDrawerConfig marketStructureDrawerConfig; // POI Drawer Config ...
//
// Drawer and eaDraws ...
CArrayObj eaDraws; // Drawn Objects ...
CArrayObj *marketStructureObjects; // Market Structure Objects ...
// //
XBarTracker eaBarTracker; // EA Bar Traker ... XBarTracker eaBarTracker; // EA Bar Traker ...
@@ -195,9 +185,6 @@ color eaBarBearishColor = clrRed;
color eaBarBullishColor = clrLime; color eaBarBullishColor = clrLime;
color eaBarVolumesColor = clrGreen; color eaBarVolumesColor = clrGreen;
//
// Define Indicators Here ...
// //
// Event Handlers ... // Event Handlers ...
@@ -362,7 +349,12 @@ int OnInit()
eaSignallerRiskInPoint, // Default Risk In Points ... eaSignallerRiskInPoint, // Default Risk In Points ...
eaSignallerVolume // Defaul Volume ... eaSignallerVolume // Defaul Volume ...
); );
//
// Configure Signaller ...
fima1Signaller.ignoreTargets = false;
fima1Signaller.slAdditionDistance = 30; fima1Signaller.slAdditionDistance = 30;
fima1Signaller.maxAllowedRiskDistance = 200;
fima1Signaller.AddOnSignalEventHandler(OnSignalTriggered); fima1Signaller.AddOnSignalEventHandler(OnSignalTriggered);
// //
@@ -41,7 +41,6 @@ class XCXFIMABaseSignaller : public XCBaseSignaller
// Props ... // Props ...
// //
bool ignoreTargets; // Ignore Signal Targets ...
CArrayObj drawnObjects; // Drawing Objects Holder ... CArrayObj drawnObjects; // Drawing Objects Holder ...
XFIMAInputs fimaInputs; // XFIMA Inputs ... XFIMAInputs fimaInputs; // XFIMA Inputs ...
XCXFIMAHelper *fimaHelper; // XFIMA Indicator Helper ... XCXFIMAHelper *fimaHelper; // XFIMA Indicator Helper ...
@@ -256,8 +255,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
public: public:
// //
// Props ... // Props ...
XFIMAConditions conditions; // XFIMA Conditions ...
XFIMAMarketStructure structure; // XFIMA Market Structure ...
// //
// Constructor ... // Constructor ...
@@ -283,13 +280,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// Configure ... // Configure ...
structureConfig.Default(); structureConfig.Default();
structureDrawConfig.Default(); structureDrawConfig.Default();
//
structure.Clean();
//
// Ignore Signal Targets ...
ignoreTargets = false;
} }
// //
@@ -298,9 +288,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
{ {
// //
Destroy(); Destroy();
//
structure.Clean();
} }
// //
@@ -328,12 +315,10 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// //
XOHCL iBar; XOHCL iBar;
int count = 0;
XBoxZone iZone; XBoxZone iZone;
XSignal iSignal; XSignal iSignal;
bool has = false; bool has = false;
XTarget iTargets[]; XTarget iTargets[];
string iName = NULL;
bool isBullish = false; bool isBullish = false;
bool isBearish = false; bool isBearish = false;
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
@@ -354,7 +339,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// //
// Strategy X ... // Strategy X ...
has = StrategyXHasSignal( has = HasSignal(
iBar, iBar,
iZone, iZone,
iTargets, iTargets,
@@ -365,13 +350,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// Handle Resting Signals ... // Handle Resting Signals ...
has = HasDirection(iDir) && has = HasDirection(iDir) &&
iZone.IsValid(); iZone.IsValid();
if (has)
{
//
// has = false;
// iZone.Clean();
// iDir = X_DIRECTION_NONE;
}
// //
// Prepare Signal ... // Prepare Signal ...
@@ -383,81 +361,41 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// //
// Provided SL ... // Provided SL ...
double _point = GetPoints(iBar.symbol); double points = GetPoints(symbol);
double spread = GetSpread(symbol);
double entry = GetEntry(symbol, iDir);
//
// Calculate SL Addition ...
double slAddition = double slAddition =
slAdditionDistance <= 0 slAdditionDistance <= 0
? 0 ? 0
: slAdditionDistance * _point; : slAdditionDistance * points;
double slPrice =
//
// Calculate SL Price ...
double sl =
isBullish isBullish
? iZone.lower - slAddition ? iZone.lower - slAddition
: iZone.upper + slAddition; : iZone.upper + slAddition;
// //
// Preparing Signal Targets ... // Prepare Signal ...
XTarget iTarget; has = PrepareSignal(
double spread = GetSpread(symbol); iSignal,
double entry = GetEntry(symbol, iZone.dir); iDir,
double risk = MathAbs(entry - slPrice); iTargets,
0, // Use Default R2R ...
sl, // Provided Price for SL ...
0 // Specified Risk in Point ....
);
}
// //
// Ignore Signal if Risk is too Much ... // Notify On Signal Event ...
bool hasToomuchRisk = risk > (iZone.upper - iZone.lower) + slAddition + (100 * _point); if (has)
if (hasToomuchRisk) {
{ NotifySignalEventListeners(iSignal);
//
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);
//
// Handle Ignore Signal Targets if Forced ...
if (ignoreTargets)
{
XClean(iTargets);
}
//
// Handle Restrictions Based Signal Targets ...
if (risk > 0 && HasRestrictions())
{
//
// Here we Can Do Target Preparing if Signaller Restricted and
// then ignore restrictions if required ...
ResetRestrictions();
}
//
// Prepare Founded Signal ...
has = iZone.IsValid() &&
PrepareSignal(
iSignal,
iDir,
iTargets,
0, // Use Default R2R ...
slPrice, // Provided Price for SL ...
0 // Specified Risk in Point ....
);
if (has)
{
//
// Notify On Signal Event ...
NotifySignalEventListeners(iSignal);
}
//
// Cleanup ...
iTarget.Clean();
} }
// //
@@ -465,7 +403,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
iBar.Clean(); iBar.Clean();
iZone.Clean(); iZone.Clean();
iSignal.Clean(); iSignal.Clean();
SpecifiedClean(iTargets); XClean(iTargets);
} }
/** /**
@@ -487,7 +425,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
int result = 0; int result = 0;
// //
SpecifiedClean(guards); XClean(guards);
// //
int positionsCount = ArraySize(positions); int positionsCount = ArraySize(positions);
@@ -585,7 +523,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
* *
* @return ( bool ) * @return ( bool )
*/ */
bool StrategyXHasSignal( bool HasSignal(
XOHCL &bar, XOHCL &bar,
XBoxZone &zone, XBoxZone &zone,
XTarget &targets[], XTarget &targets[],
@@ -595,6 +533,9 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// //
bool result = false; bool result = false;
//
// Configuration Flags ...
// //
// Signaller Flags ... // Signaller Flags ...
bool useSignaller1 = true; bool useSignaller1 = true;
@@ -604,7 +545,36 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// //
// Validator Flags ... // Validator Flags ...
bool validateByOrderFlow = true; string provider = NULL;
bool validateByOrderFlow = false;
//
// Target Flags ...
bool hasPartialCloseOnTp1 = true;
//
// Draw Flags ...
bool draw = true;
bool drawZone = true;
bool drawOrderFlow = true;
XPOIDrawConfig iDrawConfig;
//
// Signal Checking ...
//
// 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 ...
);
// //
// Signaller 1 ... // Signaller 1 ...
@@ -617,6 +587,12 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
targets, targets,
dir // dir //
); );
//
if (result)
{
provider = "1";
}
} }
// //
@@ -630,6 +606,12 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
targets, targets,
dir // dir //
); );
//
if (result)
{
provider = "2";
}
} }
// //
@@ -643,6 +625,12 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
targets, targets,
dir // dir //
); );
//
if (result)
{
provider = "3";
}
} }
// //
@@ -656,26 +644,21 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
targets, targets,
dir // dir //
); );
//
if (result)
{
provider = "4";
}
} }
// //
// Validate Signals by Order Flow ... // Signal Validating ...
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 ...
);
//
// Validate Signals by Order Flow ...
if (result && validateByOrderFlow)
{
// //
bool isBullish = hasOrderFlow && bool isBullish = hasOrderFlow &&
IsXBullish(dir) && IsXBullish(dir) &&
@@ -692,11 +675,171 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
isBearish; isBearish;
} }
// // //
// if (result) // Targets, Restrictions and Risk Management ...
// { if (result)
// Print("Salam"); {
// } //
// Requirements ...
XTarget iTarget;
//
// Checking Direction of Signal ...
bool isBullish = IsXBullish(dir);
bool isBearish = IsXBearish(dir);
//
// Provided SL ...
double points = GetPoints(symbol);
double spread = GetSpread(symbol);
double entry = GetEntry(symbol, dir);
//
// Calculate SL Addition ...
double slAddition =
slAdditionDistance <= 0
? 0
: slAdditionDistance * points;
//
// Calculate SL Price ...
double sl =
isBullish
? zone.lower - slAddition
: zone.upper + slAddition;
//
// Calculate Risk ...
double risk = MathAbs(entry - sl);
//
// Calculate Reward ...
double reward = defaultSignalR2R * risk;
//
// Calculate TP1 ...
double tp1 = isBullish
? entry + risk
: entry - risk;
double tp2 = isBullish
? entry + (2 * risk)
: entry - (2 * risk);
//
// Calculate TP ...
double tp = isBullish
? entry + reward
: entry - reward;
//
// Check Max Allowed Risk ...
bool hasTooMuchRisk = maxAllowedRiskDistance <= 0
? false
: risk >= (maxAllowedRiskDistance * points);
if (hasTooMuchRisk)
{
//
// Clean Signal if Too much Risk ...
zone.Clean();
dir = X_DIRECTION_NONE;
}
//
// Common Targets ...
//
// Partial Close on TP 1 ...
if (hasPartialCloseOnTp1 && tp > tp1)
{
//
iTarget.Clean();
iTarget.target = tp1;
iTarget.doRFOnEntry = true;
iTarget.actingDistance = 5;
iTarget.volumeMultiplier = 0.8;
//
AddRef(iTarget, targets);
}
//
// Custom Signaller Targets ...
//
// Restrictions Handling ...
if (risk > 0 && HasRestrictions())
{
//
// Reset Restricitons if necessary ...
ResetRestrictions();
//
// Handle Custom Restrictions Senario ...
}
//
// Ignore Targets ...
if (ignoreTargets)
{
XClean(targets);
}
//
// Summarize Result ...
result = zone.IsValid() &&
HasDirection(dir);
//
// Cleanup ...
iTarget.Clean();
}
//
// Draws ...
if (result && draw)
{
//
// Prepare Draw Config ...
iDrawConfig = structureDrawConfig.drawConfig;
iDrawConfig.zonesWidth = 3;
iDrawConfig.zonesStyle = STYLE_DASH;
iDrawConfig.bullishColor = clrYellow;
iDrawConfig.bearishColor = clrDarkOrange;
//
// Draw Zone ...
if (drawZone)
{
poiDrawer.DrawZone(zone, iDrawConfig);
}
//
// Draw Order Flow ...
if (drawOrderFlow && HasChild(orderFlow))
{
poiDrawer.DrawZones(orderFlow, iDrawConfig);
}
//
// Other Drawing Materials ...
}
//
// Cleanup ...
if (!result)
{
//
zone.Clean();
XClean(targets);
dir = X_DIRECTION_NONE;
}
//
// Debug Breake ...
if (result)
{
DebugBreak();
}
// //
return result; return result;
@@ -1231,36 +1374,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// Breaked Zones ... // Breaked Zones ...
ExtractBreakeds(bar, breakedZones, affectedZones); ExtractBreakeds(bar, breakedZones, affectedZones);
//
// Draw Affected Zones ...
if (HasChild(affectedZones))
{
//
UpdateToTime(affectedZones, bar.time);
poiDrawer.DrawZones(affectedZones, structureDrawConfig.drawConfig);
}
//
// Draw Acted Zones ...
// if (HasChild(actedZones))
// {
// poiDrawer.DrawZones(actedZones, structureDrawConfig.drawConfig);
// }
//
// Draw Inside Zones ...
// if (HasChild(insideZones))
// {
// poiDrawer.DrawZones(insideZones, structureDrawConfig.drawConfig);
// }
// //
// // Draw Breaked Zones ...
// if (HasChild(breakedZones))
// {
// poiDrawer.DrawZones(breakedZones, structureDrawConfig.drawConfig);
// }
// //
// Cleanup ... // Cleanup ...
XClean(tmps); XClean(tmps);
@@ -1271,19 +1384,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
XClean(affectedZones); XClean(affectedZones);
} }
//
if (result)
{
//
zone.to = bar.time;
//
poiDrawer.DrawZone(
zone,
structureDrawConfig.drawConfig //
);
}
// //
result = zone.IsValid(); result = zone.IsValid();
} }
@@ -1493,40 +1593,11 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// Validate ... // Validate ...
result = isBullish || result = isBullish ||
isBearish; isBearish;
if (result)
{
//
dir = zone.dir;
zone.to = bar.time;
XPOIDrawConfig iConfig = structureDrawConfig.drawConfig;
iConfig.zonesWidth = 3;
iConfig.bullishColor = clrYellow;
iConfig.bearishColor = clrDarkOrange;
poiDrawer.DrawZone(zone, iConfig);
Print("Consolidation");
}
// //
// Prepare Zone ... // Prepare Zone ...
if (result) if (result)
{ {
//
// zone.Clean();
// result = ToBox(
// p2Bar,
// zone,
// dir,
// X_BAR_PATTERN_PINNED //
// );
//
// Manage Stops ...
if (result)
{
}
//
result = zone.IsValid();
} }
// //