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
+4
View File
@@ -57,7 +57,9 @@ class XCBaseSignaller : public XCBase
ENUM_TIMEFRAMES period; // Period ...
//
bool ignoreTargets; // Ignore Signal Targets ...
double slAdditionDistance; // SL Addition Distance ...
double maxAllowedRiskDistance; // Max Allowed Risk In Points ...
//
// Restrictions ...
@@ -92,7 +94,9 @@ class XCBaseSignaller : public XCBase
period = _period;
//
ignoreTargets = false;
slAdditionDistance = 0;
maxAllowedRiskDistance = 0;
//
processAllTicks = _processAllTicks;
+14 -22
View File
@@ -131,17 +131,17 @@ input ENUM_BASE_CORNER barTimeCorner = CORNER_RIGHT_LOWER; // Text Position
//
// Presentation ...
input group "Presentation";
input bool showPV = true; // Show PV
input bool showHK = true; // Show HK
input bool showSAR = true; // Show Sar
input bool showPV = false; // Show PV
input bool showHK = false; // Show HK
input bool showSAR = false; // Show Sar
input bool showBars = true; // Show Bars
input bool showMAFast = true; // Show MA Fast
input bool showMASlow = true; // Show MA Slow
input bool showMABond = true; // Show MA Bond
input bool showHKBond = true; // Show HK Bond
input bool showMAFast = false; // Show MA Fast
input bool showMASlow = false; // Show MA Slow
input bool showMABond = false; // Show MA Bond
input bool showHKBond = false; // Show HK Bond
input bool showBarTime = true; // Show Bar Time
input bool showZigZag = true; // Show ZigZag
input bool showFiboZone = true; // Show Fibo Zone
input bool showZigZag = false; // Show ZigZag
input bool showFiboZone = false; // Show Fibo Zone
//
input int startCalculationForLastBars = 1500; // Calculate Last n Bars
@@ -163,16 +163,6 @@ XCBackTesterEA *eaExpert; // EA Expert ...
// Registered Signallers ...
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 ...
@@ -195,9 +185,6 @@ color eaBarBearishColor = clrRed;
color eaBarBullishColor = clrLime;
color eaBarVolumesColor = clrGreen;
//
// Define Indicators Here ...
//
// Event Handlers ...
@@ -362,7 +349,12 @@ int OnInit()
eaSignallerRiskInPoint, // Default Risk In Points ...
eaSignallerVolume // Defaul Volume ...
);
//
// Configure Signaller ...
fima1Signaller.ignoreTargets = false;
fima1Signaller.slAdditionDistance = 30;
fima1Signaller.maxAllowedRiskDistance = 200;
fima1Signaller.AddOnSignalEventHandler(OnSignalTriggered);
//
@@ -41,7 +41,6 @@ class XCXFIMABaseSignaller : public XCBaseSignaller
// Props ...
//
bool ignoreTargets; // Ignore Signal Targets ...
CArrayObj drawnObjects; // Drawing Objects Holder ...
XFIMAInputs fimaInputs; // XFIMA Inputs ...
XCXFIMAHelper *fimaHelper; // XFIMA Indicator Helper ...
@@ -256,8 +255,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
public:
//
// Props ...
XFIMAConditions conditions; // XFIMA Conditions ...
XFIMAMarketStructure structure; // XFIMA Market Structure ...
//
// Constructor ...
@@ -283,13 +280,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// Configure ...
structureConfig.Default();
structureDrawConfig.Default();
//
structure.Clean();
//
// Ignore Signal Targets ...
ignoreTargets = false;
}
//
@@ -298,9 +288,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
{
//
Destroy();
//
structure.Clean();
}
//
@@ -328,12 +315,10 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
//
XOHCL iBar;
int count = 0;
XBoxZone iZone;
XSignal iSignal;
bool has = false;
XTarget iTargets[];
string iName = NULL;
bool isBullish = false;
bool isBearish = false;
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
@@ -354,7 +339,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
//
// Strategy X ...
has = StrategyXHasSignal(
has = HasSignal(
iBar,
iZone,
iTargets,
@@ -365,13 +350,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// Handle Resting Signals ...
has = HasDirection(iDir) &&
iZone.IsValid();
if (has)
{
//
// has = false;
// iZone.Clean();
// iDir = X_DIRECTION_NONE;
}
//
// Prepare Signal ...
@@ -383,81 +361,41 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
//
// 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 =
slAdditionDistance <= 0
? 0
: slAdditionDistance * _point;
double slPrice =
: slAdditionDistance * points;
//
// Calculate SL Price ...
double sl =
isBullish
? iZone.lower - slAddition
: iZone.upper + slAddition;
//
// Preparing Signal Targets ...
XTarget iTarget;
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);
//
// 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(
// Prepare Signal ...
has = PrepareSignal(
iSignal,
iDir,
iTargets,
0, // Use Default R2R ...
slPrice, // Provided Price for SL ...
sl, // Provided Price for SL ...
0 // Specified Risk in Point ....
);
if (has)
{
//
// Notify On Signal Event ...
NotifySignalEventListeners(iSignal);
}
//
// Cleanup ...
iTarget.Clean();
// Notify On Signal Event ...
if (has)
{
NotifySignalEventListeners(iSignal);
}
//
@@ -465,7 +403,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
iBar.Clean();
iZone.Clean();
iSignal.Clean();
SpecifiedClean(iTargets);
XClean(iTargets);
}
/**
@@ -487,7 +425,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
int result = 0;
//
SpecifiedClean(guards);
XClean(guards);
//
int positionsCount = ArraySize(positions);
@@ -585,7 +523,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
*
* @return ( bool )
*/
bool StrategyXHasSignal(
bool HasSignal(
XOHCL &bar,
XBoxZone &zone,
XTarget &targets[],
@@ -595,6 +533,9 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
//
bool result = false;
//
// Configuration Flags ...
//
// Signaller Flags ...
bool useSignaller1 = true;
@@ -604,64 +545,23 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
//
// Validator Flags ...
bool validateByOrderFlow = true;
string provider = NULL;
bool validateByOrderFlow = false;
//
// Signaller 1 ...
if (!result && useSignaller1)
{
//
result = Strategy1HasSignal(
bar,
zone,
targets,
dir //
);
}
// Target Flags ...
bool hasPartialCloseOnTp1 = true;
//
// Signaller 2 ...
if (!result && useSignaller2)
{
//
result = Strategy2HasSignal(
bar,
zone,
targets,
dir //
);
}
// Draw Flags ...
bool draw = true;
bool drawZone = true;
bool drawOrderFlow = true;
XPOIDrawConfig iDrawConfig;
//
// Signaller 3 ...
if (!result && useSignaller3)
{
//
result = Strategy3HasSignal(
bar,
zone,
targets,
dir //
);
}
// Signal Checking ...
//
// Signaller 4 ...
if (!result && useSignaller4)
{
//
result = Strategy4HasSignal(
bar,
zone,
targets,
dir //
);
}
//
// Validate Signals by Order Flow ...
if (validateByOrderFlow)
{
//
// Detecting OrderFlow ...
XBoxZone orderFlow[];
@@ -676,6 +576,89 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
false // Contains Support and Resistances ...
);
//
// Signaller 1 ...
if (!result && useSignaller1)
{
//
result = Strategy1HasSignal(
bar,
zone,
targets,
dir //
);
//
if (result)
{
provider = "1";
}
}
//
// Signaller 2 ...
if (!result && useSignaller2)
{
//
result = Strategy2HasSignal(
bar,
zone,
targets,
dir //
);
//
if (result)
{
provider = "2";
}
}
//
// Signaller 3 ...
if (!result && useSignaller3)
{
//
result = Strategy3HasSignal(
bar,
zone,
targets,
dir //
);
//
if (result)
{
provider = "3";
}
}
//
// Signaller 4 ...
if (!result && useSignaller4)
{
//
result = Strategy4HasSignal(
bar,
zone,
targets,
dir //
);
//
if (result)
{
provider = "4";
}
}
//
// Signal Validating ...
//
// Validate Signals by Order Flow ...
if (result && validateByOrderFlow)
{
//
bool isBullish = hasOrderFlow &&
IsXBullish(dir) &&
@@ -692,11 +675,171 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
isBearish;
}
// //
// if (result)
// {
// Print("Salam");
// }
//
// Targets, Restrictions and Risk Management ...
if (result)
{
//
// 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;
@@ -1231,36 +1374,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// Breaked Zones ...
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 ...
XClean(tmps);
@@ -1271,19 +1384,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
XClean(affectedZones);
}
//
if (result)
{
//
zone.to = bar.time;
//
poiDrawer.DrawZone(
zone,
structureDrawConfig.drawConfig //
);
}
//
result = zone.IsValid();
}
@@ -1493,40 +1593,11 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// Validate ...
result = isBullish ||
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 ...
if (result)
{
//
// zone.Clean();
// result = ToBox(
// p2Bar,
// zone,
// dir,
// X_BAR_PATTERN_PINNED //
// );
//
// Manage Stops ...
if (result)
{
}
//
result = zone.IsValid();
}
//