prepare X5121 EA for Works ...
This commit is contained in:
@@ -2934,14 +2934,7 @@ public:
|
|||||||
//
|
//
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
mWaitsUntilNewBar = true;
|
mWaitsUntilNewBar = true;
|
||||||
|
|
||||||
//
|
|
||||||
string providerTypeStr = GetSymbol() + ", " + provider + "(" + (hasLong ? "Long" : "Short") + ")";
|
|
||||||
string mConditionsStr = mConditions.GenerateSummary(providerTypeStr, true);
|
|
||||||
mConditionsCollector.Add(mConditionsStr);
|
|
||||||
Print(mConditionsStr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+264
-29
@@ -23,6 +23,8 @@
|
|||||||
#define ShortName "X5121EA"
|
#define ShortName "X5121EA"
|
||||||
|
|
||||||
//
|
//
|
||||||
|
#include "../Classes/x-saherelm.xalert.class.mq5"
|
||||||
|
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
||||||
#include "../Classes/x-saherelm.x5.provider.class.mq5"
|
#include "../Classes/x-saherelm.x5.provider.class.mq5"
|
||||||
#include "../Classes/x-saherelm.x121.provider.class.mq5"
|
#include "../Classes/x-saherelm.x121.provider.class.mq5"
|
||||||
|
|
||||||
@@ -302,28 +304,39 @@ struct X5121ProviderDescriptor
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Inputs ...
|
// Inputs ...
|
||||||
long x5EAMagicNumber = 78692110; // Magic Number
|
long x5121EAMagicNumber = 78692110; // Magic Number
|
||||||
int x5EASlippage = 10; // Slippgae
|
int x5121EASlippage = 10; // Slippgae
|
||||||
string x5EASymbols = "EURUSDb"; // Symbols
|
string x5121EASymbols = "EURUSDb"; // Symbols
|
||||||
//
|
//
|
||||||
bool x5EAAllowLong = true; // Allow Long Trades
|
bool x5121EAAllowLong = true; // Allow Long Trades
|
||||||
bool x5EAAllowShort = true; // Allow Short Trades
|
bool x5121EAAllowShort = true; // Allow Short Trades
|
||||||
int x5EAManageInterval = 5; // Manager Check Intervals Seconds
|
int x5121EAManageInterval = 5; // Manager Check Intervals Seconds
|
||||||
int x5EAMaxAllowedPositions = 15; // Max Allowed Positions
|
int x5121EAMaxAllowedPositions = 15; // Max Allowed Positions
|
||||||
double x5EAMaxAllowedSpread = 0; // Max Allowed Spred for Opening Trades
|
double x5121EAMaxAllowedSpread = 0; // Max Allowed Spred for Opening Trades
|
||||||
double x5EAMinProfitPerTrade = 0; // Min Profit Per Trade based On Volume Factor (Hedge)
|
double x5121EAMinProfitPerTrade = 0; // Min Profit Per Trade based On Volume Factor (Hedge)
|
||||||
double x5EAMinProfitPerVolumeFactor = 0; // Min Volume Factor for Calculating Profit (Hedge)
|
double x5121EAMinProfitPerVolumeFactor = 0; // Min Volume Factor for Calculating Profit (Hedge)
|
||||||
double x5EAMaxAllowedDrawdownFactor = 0; // Max Allowed Drawdown Factor
|
double x5121EAMaxAllowedDrawdownFactor = 0; // Max Allowed Drawdown Factor
|
||||||
//
|
//
|
||||||
double x5EAVolume = 0.01;
|
double x5121EAVolume = 0.01;
|
||||||
|
//
|
||||||
|
bool x5121EAEnableAlerts = true; // Enable Alerts
|
||||||
|
bool x5121EALogAlerts = true; // Log Alerts
|
||||||
|
bool x5121EATerminalAlerts = false; // Terminal Alerts
|
||||||
|
bool x5121EAMailAlerts = false; // Mail Alerts
|
||||||
|
bool x5121EAPushAlerts = false; // Push Alerts
|
||||||
|
|
||||||
//
|
//
|
||||||
// Vars ...
|
// Vars ...
|
||||||
string x5EASymbol;
|
string x5121EASymbol;
|
||||||
ENUM_TIMEFRAMES x5EAPeriod;
|
ENUM_TIMEFRAMES x5121EAPeriod;
|
||||||
|
|
||||||
//
|
//
|
||||||
MqlTick x5EATick;
|
MqlTick x5121EATick;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Trade Class Instance ...
|
||||||
|
XSCTrade *x5121EATrader;
|
||||||
|
XSCAlert *x5121EAAlert;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Providers ...
|
// Providers ...
|
||||||
@@ -337,15 +350,15 @@ X5121ProviderDescriptor x5121EAProviders[];
|
|||||||
int OnInit()
|
int OnInit()
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
if (x5EASymbol == NULL || StringLen(x5EASymbol) <= 0)
|
if (x5121EASymbol == NULL || StringLen(x5121EASymbol) <= 0)
|
||||||
{
|
{
|
||||||
x5EASymbol = _Symbol;
|
x5121EASymbol = _Symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
if (x5EAPeriod == NULL)
|
if (x5121EAPeriod == NULL)
|
||||||
{
|
{
|
||||||
x5EAPeriod = _Period;
|
x5121EAPeriod = _Period;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -396,13 +409,54 @@ void OnTick()
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Reading Tick ...
|
// Reading Tick ...
|
||||||
if (!SymbolInfoTick(x5EASymbol, x5EATick))
|
if (!SymbolInfoTick(x5121EASymbol, x5121EATick))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// mX5121EA.OnTick();
|
// Draw ...
|
||||||
|
HandleOnDraw();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Trade Events ...
|
||||||
|
XOnTradeHandlerState tState;
|
||||||
|
x5121EATrader.HandleOnTradeEvent(tState);
|
||||||
|
|
||||||
|
//
|
||||||
|
// First Check For Any Guard Actions ...
|
||||||
|
// then Handle Guards if Provided ...
|
||||||
|
XGuard guards[];
|
||||||
|
bool hasGuard = CheckForGuard(guards);
|
||||||
|
if (hasGuard)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// TODO: Complete this ...
|
||||||
|
// DoGuards(guards);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Second Check for Position Management or Equity Management
|
||||||
|
// Actions like Supports or etc ...
|
||||||
|
bool isIgnored = HandleStateManagement();
|
||||||
|
if (isIgnored)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Second Check For Signals ...
|
||||||
|
// then Execute Signals if Provided ...
|
||||||
|
XSignal signals[];
|
||||||
|
int signalsCount = RequestForSignal(signals);
|
||||||
|
if (signalsCount <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Execute Signals ...
|
||||||
|
HandleSignalsExecution(signals);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -418,8 +472,8 @@ bool X5121EAValidateInputs()
|
|||||||
//
|
//
|
||||||
result =
|
result =
|
||||||
//
|
//
|
||||||
x5EASlippage > 0 &&
|
x5121EASlippage > 0 &&
|
||||||
x5EAMagicNumber > 0
|
x5121EAMagicNumber > 0
|
||||||
//
|
//
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -442,7 +496,7 @@ bool InitialEA()
|
|||||||
// - XAUUSD/M5;
|
// - XAUUSD/M5;
|
||||||
|
|
||||||
//
|
//
|
||||||
result = IsValid(x5EASymbols);
|
result = IsValid(x5121EASymbols);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
@@ -452,13 +506,37 @@ bool InitialEA()
|
|||||||
string symbols[];
|
string symbols[];
|
||||||
int symbolsCount = SplitContent(
|
int symbolsCount = SplitContent(
|
||||||
symbols,
|
symbols,
|
||||||
x5EASymbols);
|
x5121EASymbols);
|
||||||
result = symbolsCount > 0;
|
result = symbolsCount > 0;
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Instance XSCTrade Class ...
|
||||||
|
x5121EATrader = new XSCTrade(
|
||||||
|
x5121EASlippage,
|
||||||
|
x5121EAMagicNumber,
|
||||||
|
x5121EAManageInterval,
|
||||||
|
x5121EAMaxAllowedSpread,
|
||||||
|
x5121EAMaxAllowedPositions,
|
||||||
|
x5121EAMaxAllowedDrawdownFactor
|
||||||
|
//
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Instantiate Alert Class ...
|
||||||
|
x5121EAAlert = new XSCAlert(
|
||||||
|
"X5121EA",
|
||||||
|
x5121EAEnableAlerts,
|
||||||
|
x5121EALogAlerts,
|
||||||
|
x5121EATerminalAlerts,
|
||||||
|
x5121EAMailAlerts,
|
||||||
|
x5121EAPushAlerts
|
||||||
|
//
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Define Signallers ...
|
// Define Signallers ...
|
||||||
ENUM_X5_SIGNAL_PROVIDERS signallers[];
|
ENUM_X5_SIGNAL_PROVIDERS signallers[];
|
||||||
@@ -478,8 +556,8 @@ bool InitialEA()
|
|||||||
//
|
//
|
||||||
iDescriptor.symbol = symbols[i];
|
iDescriptor.symbol = symbols[i];
|
||||||
iDescriptor.period = PERIOD_M5;
|
iDescriptor.period = PERIOD_M5;
|
||||||
iDescriptor.allowLong = x5EAAllowLong;
|
iDescriptor.allowLong = x5121EAAllowLong;
|
||||||
iDescriptor.allowShort = x5EAAllowShort;
|
iDescriptor.allowShort = x5121EAAllowShort;
|
||||||
Copy(
|
Copy(
|
||||||
signallers,
|
signallers,
|
||||||
iDescriptor.signallers);
|
iDescriptor.signallers);
|
||||||
@@ -675,7 +753,15 @@ bool InitialEA()
|
|||||||
bool isX5InputsValid = iDescriptor.x5Inputs.IsValid();
|
bool isX5InputsValid = iDescriptor.x5Inputs.IsValid();
|
||||||
if (!isX5InputsValid)
|
if (!isX5InputsValid)
|
||||||
{
|
{
|
||||||
continue;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Init X121 Inputs ...
|
||||||
|
bool isX121InputsInit = iDescriptor.x121Inputs.Init();
|
||||||
|
if (!isX121InputsInit)
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -685,7 +771,7 @@ bool InitialEA()
|
|||||||
bool isDescriptorInitialized = iDescriptor.Init();
|
bool isDescriptorInitialized = iDescriptor.Init();
|
||||||
if (!isDescriptorInitialized)
|
if (!isDescriptorInitialized)
|
||||||
{
|
{
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -704,4 +790,153 @@ bool InitialEA()
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void HandleOnDraw() {}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool HandleStateManagement()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool CheckForGuard(XGuard &guards[])
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int RequestForSignal(
|
||||||
|
XSignal &signals[] // Holds Signals ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
Clean(signals);
|
||||||
|
|
||||||
|
//
|
||||||
|
int descriptorsCount = ArraySize(x5121EAProviders);
|
||||||
|
if (descriptorsCount <= 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < descriptorsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
X5121ProviderDescriptor iDescriptor = x5121EAProviders[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool iHasSignal = iDescriptor.HasSignal(0);
|
||||||
|
if (iHasSignal)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
AddRef(
|
||||||
|
iDescriptor.signal,
|
||||||
|
signals //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = ArraySize(signals);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void HandleSignalsExecution(XSignal &signals[])
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int signalsCount = ArraySize(signals);
|
||||||
|
if (signalsCount <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Filter Signals Based on their Types ...
|
||||||
|
XSignal filteredSignals[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Try to Filter Signals ...
|
||||||
|
for (int i = 0; i < signalsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XSignal iSignal = signals[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isLong = IsLong(iSignal.type);
|
||||||
|
|
||||||
|
//
|
||||||
|
if ((isLong && !x5121EAAllowLong) || (!isLong && !x5121EAAllowShort))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
AddRef(
|
||||||
|
iSignal,
|
||||||
|
filteredSignals //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int filteredSignalsCount = ArraySize(filteredSignals);
|
||||||
|
if (filteredSignalsCount <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Try to Execute Signals ...
|
||||||
|
ENUM_X_SIGNAL_EXECUTION_RESULT reasons[];
|
||||||
|
int executedSignalsCount = x5121EATrader.ExecuteSignals(
|
||||||
|
filteredSignals,
|
||||||
|
reasons
|
||||||
|
//
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
string message = NULL;
|
||||||
|
if (executedSignalsCount == 0)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
message = "(" + ToString(filteredSignalsCount) + ") Signals Execution Failed ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int j = 0; j < ArraySize(reasons); j++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string iReason = ToString(reasons[j]);
|
||||||
|
|
||||||
|
//
|
||||||
|
// ToString(GetSpread(filteredSignals[j].symbol)) + ","
|
||||||
|
message += "\n" + ToString(j) + ": " + iReason;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (executedSignalsCount < filteredSignalsCount)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int diff = filteredSignalsCount - executedSignalsCount;
|
||||||
|
|
||||||
|
//
|
||||||
|
message = "Failed to Execute (" + ToString(diff) + ") Signals ...";
|
||||||
|
}
|
||||||
|
else if (executedSignalsCount == filteredSignalsCount)
|
||||||
|
{
|
||||||
|
message = "(" + ToString(executedSignalsCount) + ") Signals Executed Successfully ...";
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (IsValid(message))
|
||||||
|
{
|
||||||
|
x5121EAAlert.Alert(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
Reference in New Issue
Block a user