last ...
This commit is contained in:
+184
-83
@@ -21,6 +21,8 @@
|
||||
//
|
||||
// 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-volume.class.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xcatb.helper.mq5"
|
||||
@@ -107,11 +109,11 @@ input string eaCloseAllOpenTradesAt = "";
|
||||
// Here we Provider All Requirements for
|
||||
// Configuring Alert Provider ...
|
||||
input group "Alert";
|
||||
input bool eaEnableAlerts = true; // Enable Alerts
|
||||
input bool eaLogAlerts = true; // Log Alerts
|
||||
input bool eaMailAlerts = false; // Mail Alerts
|
||||
input bool eaPushAlerts = true; // Push Alerts
|
||||
input bool eaTerminalAlerts = true; // Terminal Alerts
|
||||
input bool eaEnableAlerts = true; // Enable Alerts
|
||||
input bool eaLogAlerts = true; // Log Alerts
|
||||
input bool eaMailAlerts = false; // Mail Alerts
|
||||
input bool eaPushAlerts = true; // Push Alerts
|
||||
input bool eaTerminalAlerts = false; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Time Report ...
|
||||
@@ -132,23 +134,18 @@ input bool eaReportAfterTradesBalance = true; // Report Balance after a Trade Fi
|
||||
XCAlert *eaAlert;
|
||||
XCTrade *eaTrade;
|
||||
XSignal eaSignal;
|
||||
string eaTag = "";
|
||||
XCVolume *eaVolume;
|
||||
X121XCatbInputs eaInputs;
|
||||
XCX121XCatbHelper *eaHelper;
|
||||
CArrayObj *eaObjects;
|
||||
XCPOIDrawer *eaDrawer;
|
||||
XBarTracker eaBarTraker;
|
||||
X121XCatbInputs eaInputs;
|
||||
XTimeTracker eaTimeTracker;
|
||||
XCX121XCatbHelper *eaHelper;
|
||||
XCBarAnalyser *eaBarAnalyser;
|
||||
XCXCAEATradeManager *eaTradeManager;
|
||||
XCAEAStrategyConditions eaConditions;
|
||||
|
||||
//
|
||||
XTriggerBlock eaTB;
|
||||
|
||||
//
|
||||
CArrayObj *eaObjects;
|
||||
|
||||
//
|
||||
string eaTag = "";
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
@@ -210,10 +207,18 @@ void OnDeinit(const int reason)
|
||||
delete eaTrade;
|
||||
ZeroMemory(eaTrade);
|
||||
|
||||
//
|
||||
delete eaDrawer;
|
||||
ZeroMemory(eaDrawer);
|
||||
|
||||
//
|
||||
delete eaVolume;
|
||||
ZeroMemory(eaVolume);
|
||||
|
||||
//
|
||||
delete eaBarAnalyser;
|
||||
ZeroMemory(eaBarAnalyser);
|
||||
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaBarTraker.Clean();
|
||||
@@ -239,6 +244,11 @@ void OnTick()
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
|
||||
//
|
||||
bool has = false;
|
||||
int barIndex = 0;
|
||||
int cBarIndex = 0;
|
||||
|
||||
//
|
||||
// Check Bar Processing ...
|
||||
if (!eaBarTraker.CanProcessBar())
|
||||
@@ -247,16 +257,13 @@ void OnTick()
|
||||
}
|
||||
|
||||
//
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Retrieve Bars ...
|
||||
// Reading Required Bars ...
|
||||
XOHCL zBar;
|
||||
XOHCL cBar;
|
||||
has = zBar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
0 //
|
||||
barIndex //
|
||||
);
|
||||
has =
|
||||
has &&
|
||||
@@ -272,50 +279,131 @@ void OnTick()
|
||||
}
|
||||
|
||||
//
|
||||
double bid = GetBid(zBar.symbol);
|
||||
cBarIndex = barIndex + 1;
|
||||
|
||||
//
|
||||
// Update All Required Buffers ...
|
||||
eaHelper.Update(cBarIndex);
|
||||
|
||||
//
|
||||
// Check Trigger Block Detected or Not ...
|
||||
XTriggerBlock iTB;
|
||||
has = GetNewestX121TriggerBlock(
|
||||
has = DetectTriggerBlock(
|
||||
//
|
||||
_Symbol,
|
||||
_Period,
|
||||
iTB //
|
||||
//
|
||||
iTB,
|
||||
//
|
||||
eaBarAnalyser,
|
||||
//
|
||||
// Required Buffers ...
|
||||
eaHelper.atrBuffer,
|
||||
eaHelper.rsiBuffer,
|
||||
eaHelper.adxBuffer,
|
||||
eaHelper.adxpBuffer,
|
||||
eaHelper.adxnBuffer,
|
||||
eaHelper.peakBuffer,
|
||||
eaHelper.valeBuffer,
|
||||
eaHelper.deltaBuffer,
|
||||
eaHelper.sarBuffer,
|
||||
eaHelper.sarStateBuffer,
|
||||
eaHelper.trendBuffer,
|
||||
eaHelper.trendStateBuffer,
|
||||
eaHelper.atrUpperBuffer,
|
||||
eaHelper.atrLowerBuffer,
|
||||
eaHelper.sBarOpenBuffer,
|
||||
eaHelper.sBarCloseBuffer,
|
||||
eaHelper.hkSBarOpenBuffer,
|
||||
eaHelper.hkSBarCloseBuffer,
|
||||
eaHelper.peakGoldenBuffer,
|
||||
eaHelper.valeGoldenBuffer,
|
||||
eaHelper.deltaSignalBuffer,
|
||||
eaHelper.bullishVolumeSignalBuffer,
|
||||
eaHelper.bearishVolumeSignalBuffer,
|
||||
//
|
||||
cBarIndex,
|
||||
//
|
||||
// Signalling ...
|
||||
eaInputs.signalR2R,
|
||||
eaInputs.slAtrMultiplier,
|
||||
//
|
||||
// Configs ...
|
||||
eaInputs.rsiOBLevel,
|
||||
eaInputs.rsiOSLevel,
|
||||
eaInputs.adxThreshold,
|
||||
//
|
||||
// Validators ...
|
||||
eaInputs.forceObBarType,
|
||||
eaInputs.forceOBFVGBarType,
|
||||
eaInputs.forceHasSwing,
|
||||
eaInputs.forceHasFLiquidity,
|
||||
eaInputs.forceHasRLiquidity,
|
||||
eaInputs.validateGapSequence,
|
||||
eaInputs.validateBlockEdgeBreakout,
|
||||
//
|
||||
// Filters ...
|
||||
eaInputs.filterBasedOnPV,
|
||||
eaInputs.filterBasedOnSar,
|
||||
eaInputs.filterBasedOnRSI,
|
||||
eaInputs.filterBasedOnADX,
|
||||
eaInputs.filterBasedOnATR,
|
||||
eaInputs.filterBasedOnTrend,
|
||||
eaInputs.filterBasedOnDelta,
|
||||
eaInputs.filterBasedOnVolume,
|
||||
eaInputs.filterBasedOnSignalBar,
|
||||
eaInputs.filterBasedOnHKSignalBar //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Check Newest TB is Newer Than Exists TB ...
|
||||
bool canPass =
|
||||
!eaTB.IsValid()
|
||||
? true
|
||||
: iTB.ToIndex() < eaTB.ToIndex();
|
||||
if (canPass)
|
||||
{
|
||||
//
|
||||
eaTB = iTB;
|
||||
eaSignal = iTB.signal;
|
||||
eaBarTraker.Waits();
|
||||
|
||||
//
|
||||
// Prepare eaConditions if Reuqired ...
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
has = eaSignal.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Here we ensure which has a New Signal and must
|
||||
// prepare and Execute it ...
|
||||
Print("new Signal Detected ...");
|
||||
eaSignal = iTB.signal;
|
||||
|
||||
//
|
||||
// Here we Can Fill eaConditions ...
|
||||
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
//
|
||||
// Execute Signal ...
|
||||
has = eaTradeManager.Execute(
|
||||
eaSignal,
|
||||
eaConditions //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// eaTB.Clean();
|
||||
// Cleanup Resources ...
|
||||
|
||||
//
|
||||
iTB.Clean();
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -543,6 +631,13 @@ bool InitVolume()
|
||||
*/
|
||||
void InitRequirements()
|
||||
{
|
||||
//
|
||||
// Initial Bar Tracker ...
|
||||
eaBarTraker.Init(
|
||||
_Symbol,
|
||||
_Period //
|
||||
);
|
||||
|
||||
//
|
||||
// Preparing Tags ...
|
||||
eaTag =
|
||||
@@ -552,11 +647,13 @@ void InitRequirements()
|
||||
ShortName;
|
||||
|
||||
//
|
||||
// Initial Bar Tracker ...
|
||||
eaBarTraker.Init(
|
||||
_Symbol,
|
||||
_Period //
|
||||
);
|
||||
eaAlert = new XCAlert();
|
||||
eaAlert.SetPrefix(eaLogSuffix);
|
||||
eaAlert.SetLogAlerts(eaLogAlerts);
|
||||
eaAlert.SetMailAlerts(eaMailAlerts);
|
||||
eaAlert.SetPushAlerts(eaPushAlerts);
|
||||
eaAlert.SetEnableAlerts(eaEnableAlerts);
|
||||
eaAlert.SetTerminalAlerts(eaTerminalAlerts);
|
||||
|
||||
//
|
||||
// Objects ...
|
||||
@@ -573,6 +670,9 @@ void InitRequirements()
|
||||
//
|
||||
// we Can make Show all requirements here ...
|
||||
|
||||
//
|
||||
eaInputs.showATRBand = false;
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
eaInputs.signalR2R = eaSignalR2R;
|
||||
@@ -604,10 +704,10 @@ void InitRequirements()
|
||||
//
|
||||
// Alerts ...
|
||||
eaInputs.alertPrefix = eaTag;
|
||||
eaInputs.logAlerts = eaLogAlerts;
|
||||
eaInputs.pushAlerts = eaMailAlerts;
|
||||
eaInputs.mailAlerts = eaPushAlerts;
|
||||
eaInputs.terminalAlerts = eaTerminalAlerts;
|
||||
eaInputs.logAlerts = false; // eaLogAlerts;
|
||||
eaInputs.pushAlerts = false; // eaMailAlerts;
|
||||
eaInputs.mailAlerts = false; // eaPushAlerts;
|
||||
eaInputs.terminalAlerts = false; // eaTerminalAlerts;
|
||||
|
||||
//
|
||||
eaHelper = new XCX121XCatbHelper();
|
||||
@@ -618,15 +718,8 @@ void InitRequirements()
|
||||
);
|
||||
|
||||
//
|
||||
// EA Alert ...
|
||||
eaAlert = new XCAlert(
|
||||
eaTag,
|
||||
eaEnableAlerts,
|
||||
eaLogAlerts,
|
||||
eaTerminalAlerts,
|
||||
eaMailAlerts,
|
||||
eaPushAlerts //
|
||||
);
|
||||
eaDrawer = new XCPOIDrawer();
|
||||
eaBarAnalyser = new XCBarAnalyser();
|
||||
|
||||
//
|
||||
// EA Trade ...
|
||||
@@ -648,11 +741,11 @@ void InitRequirements()
|
||||
eaTrade //
|
||||
);
|
||||
eaTradeManager.SaveTrades(true);
|
||||
eaTradeManager.SetAlertEnableAlerts(eaEnableAlerts);
|
||||
eaTradeManager.SetAlertPrefix(eaTag);
|
||||
eaTradeManager.SetAlertLogAlerts(eaLogAlerts);
|
||||
eaTradeManager.SetAlertMailAlerts(eaMailAlerts);
|
||||
eaTradeManager.SetAlertPushAlerts(eaPushAlerts);
|
||||
eaTradeManager.SetAlertEnableAlerts(eaEnableAlerts);
|
||||
eaTradeManager.SetAlertTerminalAlerts(eaTerminalAlerts);
|
||||
|
||||
//
|
||||
@@ -690,6 +783,12 @@ void InitRequirements()
|
||||
*/
|
||||
void HandleTimeReport()
|
||||
{
|
||||
//
|
||||
if (eaAlert == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Monthly Report ....
|
||||
if (eaReportNewMonths &&
|
||||
@@ -699,7 +798,7 @@ void HandleTimeReport()
|
||||
string msg = "New Month ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -711,7 +810,7 @@ void HandleTimeReport()
|
||||
string msg = "New Week ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -723,7 +822,7 @@ void HandleTimeReport()
|
||||
string msg = "New Day ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -735,13 +834,14 @@ void HandleTimeReport()
|
||||
string msg = "New Hour ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Apply Signal Targets ...
|
||||
void ApplySignalTargets(XSignal &signal)
|
||||
/**
|
||||
* Update Signal Targets ...
|
||||
*/
|
||||
void UpdateSignalTargets(XSignal &signal)
|
||||
{
|
||||
//
|
||||
bool has = signal.IsValid();
|
||||
@@ -756,10 +856,9 @@ void ApplySignalTargets(XSignal &signal)
|
||||
|
||||
//
|
||||
// Calculate Requirements ...
|
||||
double r2r = 1;
|
||||
// maxAllowedR2R > 0
|
||||
// ? maxAllowedR2R
|
||||
// : 1;
|
||||
double r2r = eaSignalR2R > 0
|
||||
? eaSignalR2R
|
||||
: 1;
|
||||
double risk = signal.GetRisk();
|
||||
double reward = risk * r2r;
|
||||
|
||||
@@ -777,10 +876,10 @@ void ApplySignalTargets(XSignal &signal)
|
||||
// Try to Apply Money Management ...
|
||||
|
||||
//
|
||||
if (r2r <= 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// if (r2r <= 1)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
//
|
||||
// XTarget iTarget;
|
||||
@@ -834,3 +933,5 @@ void ApplySignalTargets(XSignal &signal)
|
||||
signal.targets //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user