complete XCATBEA and all of it's requirements, such as:
- Expert Class; - Class Based EA; - Signaller(s); - Multi Symbol; - Multi Session; - ...
This commit is contained in:
+152
-234
@@ -20,15 +20,10 @@
|
||||
|
||||
//
|
||||
// Include Common Library ...
|
||||
#include "../Classes/x-saherelm.x-alert.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-bar.analyser.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-poi.drawer.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-trade.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-guard.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-volume.class.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xcatb.helper.mq5"
|
||||
#include "../XCATBEA/Classes/xcatbea.signaller.class.mq5"
|
||||
#include "../XCATBEA/Classes/xcatbea.x-trade.manager.class.mq5"
|
||||
#include "../XCATBEA/Libraries/xcatbea.signaller.lib.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "XCATBEA"
|
||||
@@ -66,6 +61,7 @@ input bool eaValidateBlockEdgeBreakout = false; // Validate Order Block Edge Bre
|
||||
//
|
||||
// Filtering ...
|
||||
input group "Filters";
|
||||
input bool eaFilterBasedOnKI = false; // Filter Based On KI Flats
|
||||
input bool eaFilterBasedOnPV = false; // Filter Based On PV
|
||||
input int eaBosLoopback = 0; // PV Based Filtering BOS Lookup
|
||||
input bool eaFilterBasedOnSar = false; // Filter Based On SAR
|
||||
@@ -94,13 +90,14 @@ input bool eaForceHasTrendDirOnBothSide = false; // TREND Must Has Following Dir
|
||||
input bool eaFilterBasedOnDelta = false; // Filter Based On Delta
|
||||
input bool eaFilterBasedOnVolume = false; // Filter Based On Volume
|
||||
input bool eaFilterBasedOnSignalBar = false; // Filter Based on Signal Bar
|
||||
input bool eaFilterBasedOnRoundPrice = false; // Filter Based On Round Prices
|
||||
input bool eaFilterBasedOnHKSignalBar = false; // Filter Based On HK Signal Bar
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
input group "Signal";
|
||||
input int eaSignalR2R = 2; // Risk Reward Ratio
|
||||
input double eaSLAtrMultiplier = 0; // ATR Multiplier for SL
|
||||
input double eaSLATRMultiplier = 0; // ATR Multiplier for SL
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
@@ -117,6 +114,7 @@ input double eaConstantBalance = 0.0; // Constant Ba
|
||||
// Management ...
|
||||
// eaSessions => (SYDNEY_02:00_14:00),(NY_19:00_23:00)
|
||||
input group "Management";
|
||||
input bool eaAllowGuards = false; // Allow Guards
|
||||
input bool eaAllowTrade = true; // Allow Trade on Signals
|
||||
input bool eaAllowLongs = true; // Allow Long Trades
|
||||
input bool eaAllowShorts = true; // Allow Short Trades
|
||||
@@ -165,13 +163,14 @@ input bool eaSaveLosts = false; // Save Lost Conditions
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
XCAlert *eaAlert;
|
||||
XCTrade *eaTrade;
|
||||
string eaTag = "";
|
||||
XCVolume *eaVolume;
|
||||
XTimeTracker eaTimeTracker;
|
||||
XCXCATBEASignaller *eaSignallers[];
|
||||
XCXCATBEATradeManager *eaTradeManager;
|
||||
XCAlert *eaAlert; // EA Scope Alert Handler ...
|
||||
XCTrade *eaTrade; // EA Scope Trade Handler ...
|
||||
XCGuard *eaGuard; // EA Scope Guard Handler ...
|
||||
string eaTag = ""; // Specified Alert Tag for EA ...
|
||||
XCVolume *eaVolume; // EA Scope Voluem Handler ...
|
||||
XTimeTracker eaTimeTracker; // EA Scope Time Tracker ...
|
||||
XCXCATBEASignaller *eaSignallers[]; // EA Signallers Collection ...
|
||||
XCXCATBEATradeManager *eaTradeManager; // EA Scope Trade Manager ...
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
@@ -227,6 +226,10 @@ void OnDeinit(const int reason)
|
||||
delete eaTrade;
|
||||
ZeroMemory(eaTrade);
|
||||
|
||||
//
|
||||
delete eaGuard;
|
||||
ZeroMemory(eaGuard);
|
||||
|
||||
//
|
||||
delete eaVolume;
|
||||
ZeroMemory(eaVolume);
|
||||
@@ -234,6 +237,13 @@ void OnDeinit(const int reason)
|
||||
//
|
||||
eaTimeTracker.Clean();
|
||||
|
||||
//
|
||||
Clean(eaSignallers);
|
||||
|
||||
//
|
||||
delete eaTradeManager;
|
||||
ZeroMemory(eaTradeManager);
|
||||
|
||||
//
|
||||
DestroyTimer();
|
||||
}
|
||||
@@ -345,6 +355,7 @@ void OnTick()
|
||||
{
|
||||
//
|
||||
// Handle Guards Firing ...
|
||||
eaGuard.DoGuards(guards);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -354,6 +365,7 @@ void OnTick()
|
||||
{
|
||||
//
|
||||
// Handle Conditions Triggering ...
|
||||
TriggerConditions(conditions);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -362,226 +374,6 @@ void OnTick()
|
||||
//
|
||||
Clean(guards);
|
||||
Clean(conditions);
|
||||
|
||||
// //
|
||||
// eaTB.Clean();
|
||||
// eaSignal.Clean();
|
||||
// eaConditions.Clean();
|
||||
// eaCatbConditions.Clean();
|
||||
|
||||
// //
|
||||
// bool has = false;
|
||||
// int barIndex = 0;
|
||||
// int cBarIndex = 0;
|
||||
|
||||
// //
|
||||
// // Check Bar Processing ...
|
||||
// if (!eaBarTraker.CanProcessBar())
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// eaHelper.Check(barIndex);
|
||||
|
||||
// //
|
||||
// // Reading Required Bars ...
|
||||
// XOHCL zBar;
|
||||
// XOHCL cBar;
|
||||
// has = zBar.Init(
|
||||
// _Symbol,
|
||||
// _Period,
|
||||
// barIndex //
|
||||
// );
|
||||
// has =
|
||||
// has &&
|
||||
// zBar.GetPreviousBar(cBar);
|
||||
// if (!has)
|
||||
// {
|
||||
// //
|
||||
// zBar.Clean();
|
||||
// cBar.Clean();
|
||||
|
||||
// //
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// cBarIndex = barIndex + 1;
|
||||
|
||||
// //
|
||||
// // Update All Required Buffers ...
|
||||
// eaHelper.Update(cBarIndex);
|
||||
|
||||
// //
|
||||
// // Check Trigger Block Detected or Not ...
|
||||
// if (tradeUsingTriggerBlock)
|
||||
// {
|
||||
// //
|
||||
// // Trigger Block Detection ...
|
||||
// has = DetectTriggerBlock1(
|
||||
// eaHelper,
|
||||
// eaBarAnalyser,
|
||||
// eaTB,
|
||||
// eaCatbConditions,
|
||||
// eaValidations,
|
||||
// eaFilters,
|
||||
// barIndex,
|
||||
// 10 // Loopback ...
|
||||
// );
|
||||
|
||||
// //
|
||||
// if (has)
|
||||
// {
|
||||
// //
|
||||
// // Wait for Next Bar for anything ...
|
||||
// eaBarTraker.Waits();
|
||||
|
||||
// //
|
||||
// // Prepare Target ...
|
||||
// double targets[];
|
||||
// for (int i = 1; i <= eaSignalR2R; i++)
|
||||
// {
|
||||
// //
|
||||
// Add(
|
||||
// (double)i,
|
||||
// targets //
|
||||
// );
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Calculate SL Additions ...
|
||||
// double iATR = 0;
|
||||
// if (barIndex > 0 &&
|
||||
// barIndex < ArraySize(eaHelper.atrBuffer))
|
||||
// {
|
||||
// iATR = eaHelper.atrBuffer[barIndex];
|
||||
// }
|
||||
// double slAdditional = eaSLAtrMultiplier * iATR;
|
||||
|
||||
// //
|
||||
// // Preparing Signal ...
|
||||
// has = ToSignal(
|
||||
// eaTB.trigger,
|
||||
// eaTB.signal,
|
||||
// targets,
|
||||
// slAdditional //
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Draw Trigger Block ...
|
||||
// DrawTriggerBlock(
|
||||
// eaTB,
|
||||
// eaDrawer,
|
||||
// eaObjects,
|
||||
// NULL //
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Attach Signal ...
|
||||
// eaSignal = eaTB.signal;
|
||||
|
||||
// //
|
||||
// // Check Signal Type ...
|
||||
// bool isLong = IsLong(eaSignal.type);
|
||||
|
||||
// //
|
||||
// // Update Entry ...
|
||||
// eaSignal.entry = GetEntry(
|
||||
// eaSignal.symbol,
|
||||
// eaSignal.type //
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Update Signal Targets ...
|
||||
// UpdateSignalTargets(eaSignal);
|
||||
|
||||
// //
|
||||
// // Handle Volume Management ...
|
||||
// double iVolume = eaVolume.CalculateVolume(eaSignal);
|
||||
// if (iVolume > X_MIN_VOLUME &&
|
||||
// iVolume != eaSignal.volume)
|
||||
// {
|
||||
// eaSignal.volume = iVolume;
|
||||
// }
|
||||
|
||||
// //
|
||||
// eaConditions.sl = eaSignal.sl;
|
||||
// eaConditions.tp = eaSignal.tp;
|
||||
// eaConditions.pivot = eaSignal.sl;
|
||||
// eaConditions.time = eaSignal.time;
|
||||
// eaConditions.reward = eaSignalR2R;
|
||||
// eaConditions.point = eaSignal.entry;
|
||||
// eaConditions.entry = eaSignal.entry;
|
||||
// eaConditions.symbol = eaSignal.symbol;
|
||||
// eaConditions.period = eaSignal.period;
|
||||
// eaConditions.setupTime = eaSignal.time;
|
||||
// eaConditions.triggerTime = eaSignal.time;
|
||||
// eaConditions.decisionZone = eaTB.trigger;
|
||||
// eaConditions.provider = eaSignal.provider;
|
||||
// eaConditions.conditions = eaCatbConditions;
|
||||
// eaConditions.type = ToPositionType(eaSignal.type);
|
||||
// eaConditions.dir =
|
||||
// isLong
|
||||
// ? X_DIRECTION_BULLISH
|
||||
// : X_DIRECTION_BEARISH;
|
||||
// Copy(
|
||||
// eaSignal.targets,
|
||||
// eaConditions.targets //
|
||||
// );
|
||||
// eaSignal.conditions =
|
||||
// eaCatbConditions
|
||||
// .GenerateSummary(
|
||||
// false, // Commons ...
|
||||
// true, // Conditions ...
|
||||
// true, // Scores ...
|
||||
// false // Ignore Falses ...
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Execute Signal ...
|
||||
// has = eaTradeManager.Execute(
|
||||
// eaSignal,
|
||||
// eaConditions //
|
||||
// );
|
||||
// }
|
||||
|
||||
// //
|
||||
// eaTB.Clean();
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Trade Using Market Conditions ...
|
||||
// if (tradeUsingMarketConditions1)
|
||||
// {
|
||||
// //
|
||||
// XBoxZone signalZone;
|
||||
// X121XCatbConditions conditions;
|
||||
// has = DetectSignalZone(
|
||||
// eaDrawer,
|
||||
// eaHelper,
|
||||
// eaBarAnalyser,
|
||||
// signalZone,
|
||||
// conditions,
|
||||
// barIndex //
|
||||
// );
|
||||
// if (has)
|
||||
// {
|
||||
// //
|
||||
// // Convert Box to Signal ...
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Cleanup Resources ...
|
||||
|
||||
// //
|
||||
// zBar.Clean();
|
||||
// cBar.Clean();
|
||||
// eaTB.Clean();
|
||||
// eaSignal.Clean();
|
||||
// eaConditions.Clean();
|
||||
// eaCatbConditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -835,6 +627,8 @@ void InitRequirements()
|
||||
eaMaxAllowedPositions,
|
||||
eaMaxAllowedDrawdownFactor //
|
||||
);
|
||||
|
||||
//
|
||||
eaTrade.AddOnStopLossEventHandler(OnStopLossTriggered);
|
||||
eaTrade.AddOnTakeProfitEventHandler(OnTakeProfitTriggered);
|
||||
eaTrade.AddOnForceClosePositionEventHandler(OnPositionForceClosed);
|
||||
@@ -845,6 +639,7 @@ void InitRequirements()
|
||||
eaTradeManager = new XCXCATBEATradeManager(
|
||||
eaTrade //
|
||||
);
|
||||
|
||||
//
|
||||
eaTradeManager.SetAlertPrefix(eaTag);
|
||||
eaTradeManager.SetAlertLogAlerts(eaLogAlerts);
|
||||
@@ -852,6 +647,7 @@ void InitRequirements()
|
||||
eaTradeManager.SetAlertPushAlerts(eaPushAlerts);
|
||||
eaTradeManager.SetAlertEnableAlerts(eaEnableAlerts);
|
||||
eaTradeManager.SetAlertTerminalAlerts(eaTerminalAlerts);
|
||||
|
||||
//
|
||||
eaTradeManager.SaveWins(eaSaveWins);
|
||||
eaTradeManager.SaveLosts(eaSaveLosts);
|
||||
@@ -887,6 +683,20 @@ void InitRequirements()
|
||||
eaMaxAllowedTrades //
|
||||
);
|
||||
|
||||
//
|
||||
// EA Guard Initialization ...
|
||||
eaGuard = new XCGuard(
|
||||
eaTrade //
|
||||
);
|
||||
|
||||
//
|
||||
eaGuard.SetAlertPrefix(eaTag);
|
||||
eaGuard.SetAlertLogAlerts(eaLogAlerts);
|
||||
eaGuard.SetAlertMailAlerts(eaMailAlerts);
|
||||
eaGuard.SetAlertPushAlerts(eaPushAlerts);
|
||||
eaGuard.SetAlertEnableAlerts(eaEnableAlerts);
|
||||
eaGuard.SetAlertTerminalAlerts(eaTerminalAlerts);
|
||||
|
||||
//
|
||||
// Initializing Sessions ...
|
||||
string sessions[];
|
||||
@@ -974,12 +784,23 @@ void InitRequirements()
|
||||
// Provider Name ...
|
||||
iSignallerInputs.period = _Period;
|
||||
iSignallerInputs.provider = "XTRGB";
|
||||
iSignallerInputs.allowGuards = eaAllowGuards;
|
||||
iSignallerInputs.riskToRewardRatio = eaSignalR2R;
|
||||
iSignallerInputs.allowDraws = IsRunningOnTestMode();
|
||||
iSignallerInputs.slATRMultiplier = eaSLATRMultiplier;
|
||||
|
||||
//
|
||||
// CATB Indicator ...
|
||||
iSignallerInputs.catbInputs.Default();
|
||||
iSignallerInputs.catbInputs.Hide();
|
||||
|
||||
//
|
||||
// Make Available all Requirement Buffers of XCATB indicator ...
|
||||
iSignallerInputs.catbInputs.showPV = true;
|
||||
iSignallerInputs.catbInputs.showKI = true;
|
||||
iSignallerInputs.catbInputs.showATRBand = true;
|
||||
iSignallerInputs.catbInputs.showPVGolden = true;
|
||||
|
||||
//
|
||||
// Trigger Block Validations ...
|
||||
iSignallerInputs.validations.forceHasSwing = eaForceHasSwing;
|
||||
@@ -1036,11 +857,15 @@ void InitRequirements()
|
||||
iSignallerInputs.filters.forceHasTrendDirOnBothSide = eaForceHasTrendDirOnBothSide;
|
||||
|
||||
//
|
||||
iSignallerInputs.filters.filterBasedOnKI = eaFilterBasedOnKI;
|
||||
iSignallerInputs.filters.filterBasedOnDelta = eaFilterBasedOnDelta;
|
||||
iSignallerInputs.filters.filterBasedOnVolume = eaFilterBasedOnVolume;
|
||||
iSignallerInputs.filters.filterBasedOnSignalBar = eaFilterBasedOnSignalBar;
|
||||
iSignallerInputs.filters.filterBasedOnRoundPrice = eaFilterBasedOnRoundPrice;
|
||||
iSignallerInputs.filters.filterBasedOnHKSignalBar = eaFilterBasedOnHKSignalBar;
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
// Loop Through Symbols for Signalling Initializing ...
|
||||
int symbolsCount = ArraySize(symbols);
|
||||
@@ -1233,4 +1058,97 @@ void UpdateSignalTargets(XSignal &signal)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a Triggered Conditions to Signal and
|
||||
* Execute it ...
|
||||
*/
|
||||
void TriggerConditions(XCATBEAStrategyConditions &conditions[])
|
||||
{
|
||||
//
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
has = HasChild(conditions);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
count = ArraySize(conditions);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
// Retrieve Indexed Conditions ...
|
||||
XCATBEAStrategyConditions iConditions = conditions[i];
|
||||
|
||||
//
|
||||
// Prepare Signal Based on Conditions ...
|
||||
XSignal iSignal;
|
||||
|
||||
//
|
||||
// Check if a Trigger Block Attached and Has Signal ...
|
||||
// use it ...
|
||||
has =
|
||||
iConditions.IsValid() &&
|
||||
iConditions.IsSetuped() &&
|
||||
iConditions.CanTrigger() &&
|
||||
iConditions.triggerBlock.IsValid() &&
|
||||
iConditions.triggerBlock.signal.IsValid();
|
||||
if (has)
|
||||
{
|
||||
iSignal = iConditions.triggerBlock.signal;
|
||||
}
|
||||
|
||||
//
|
||||
// if we Have any other Signalling senarios we can Handle them here ...
|
||||
|
||||
//
|
||||
// Validate Signal ...
|
||||
has = iSignal.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Retrieve Signal Type ...
|
||||
bool isLong = IsLong(iSignal.type);
|
||||
|
||||
//
|
||||
// Update Signal Entry ...
|
||||
iSignal.entry = GetEntry(
|
||||
iSignal.symbol,
|
||||
iSignal.type //
|
||||
);
|
||||
|
||||
//
|
||||
// Update Signal Targets ...
|
||||
UpdateSignalTargets(iSignal);
|
||||
|
||||
//
|
||||
// Handle Volume Management ...
|
||||
double iVolume = eaVolume.CalculateVolume(iSignal);
|
||||
has = iVolume > X_MIN_VOLUME &&
|
||||
iVolume != iSignal.volume;
|
||||
if (has)
|
||||
{
|
||||
iSignal.volume = iVolume;
|
||||
}
|
||||
|
||||
//
|
||||
// Execute Signal ...
|
||||
has = eaTradeManager.Execute(
|
||||
iSignal,
|
||||
iConditions //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
|
||||
//
|
||||
iSignal.Clean();
|
||||
iConditions.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user