prepare x5121 ...
This commit is contained in:
+485
-29
@@ -23,16 +23,288 @@
|
||||
#define ShortName "X5121EA"
|
||||
|
||||
//
|
||||
#include "../Classes/x-saherelm.x5.xea.class.mq5"
|
||||
#include "../Classes/x-saherelm.x5.provider.class.mq5"
|
||||
#include "../Classes/x-saherelm.x121.provider.class.mq5"
|
||||
|
||||
//
|
||||
// a Provider Descriptor which holds
|
||||
// X5 and X121 Provider at the Same time ...
|
||||
struct X5121ProviderDescriptor
|
||||
{
|
||||
//
|
||||
string symbol; // Trading Symbol
|
||||
ENUM_TIMEFRAMES period; // Trading Timeframe
|
||||
bool allowLong; // Allow Long Signals
|
||||
bool allowShort; // Allow Short Signals
|
||||
ENUM_X5_SIGNAL_PROVIDERS signallers[]; // Allowed Signal Providers
|
||||
|
||||
//
|
||||
X5ProviderInputs x5Inputs;
|
||||
XSCX5Provider *x5Provider;
|
||||
|
||||
//
|
||||
X121ProviderInputs x121Inputs;
|
||||
XSCX121Provider *x121Provider;
|
||||
|
||||
//
|
||||
XSignal signal;
|
||||
X5MarketConditions x5Conditions;
|
||||
X121MarketConditions x121Conditions;
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Initial Provider ...
|
||||
//
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = this.Init(
|
||||
this.symbol,
|
||||
this.period,
|
||||
this.signallers,
|
||||
this.allowLong,
|
||||
this.allowShort //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool Init(
|
||||
ENUM_X5_SIGNAL_PROVIDERS &mSignallers[], // Allowed Signal Providers
|
||||
bool mAllowLong = true, // Allow Long Signals
|
||||
bool mAllowShort = true // Allow Short Signals
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = this.Init(
|
||||
this.symbol,
|
||||
this.period,
|
||||
mSignallers,
|
||||
mAllowLong,
|
||||
mAllowShort //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool Init(
|
||||
string mSymbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES mPeriod, // Trading Timeframe
|
||||
ENUM_X5_SIGNAL_PROVIDERS &mSignallers[], // Allowed Signal Providers
|
||||
bool mAllowLong = true, // Allow Long Signals
|
||||
bool mAllowShort = true // Allow Short Signals
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
x5Inputs.IsValid() &&
|
||||
IsValid(mSymbol) &&
|
||||
IsValid(mPeriod) &&
|
||||
(allowLong || allowShort) &&
|
||||
ArraySize(mSignallers) > 0
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
this.symbol = mSymbol;
|
||||
this.period = mPeriod;
|
||||
this.allowLong = mAllowLong;
|
||||
this.allowShort = mAllowShort;
|
||||
|
||||
//
|
||||
ENUM_X5_SIGNAL_PROVIDERS tmp[];
|
||||
Copy(
|
||||
mSignallers,
|
||||
tmp //
|
||||
);
|
||||
Copy(
|
||||
tmp,
|
||||
this.signallers //
|
||||
);
|
||||
|
||||
//
|
||||
// Instantiate Provider ...
|
||||
x5Provider = new XSCX5Provider(
|
||||
this.symbol,
|
||||
this.period //
|
||||
);
|
||||
|
||||
//
|
||||
// Instantiate Provider ...
|
||||
x121Provider = new XSCX121Provider(
|
||||
this.symbol,
|
||||
this.period //
|
||||
);
|
||||
|
||||
//
|
||||
// Set Long/Short State ...
|
||||
|
||||
//
|
||||
x5Provider
|
||||
.SetSignalTypeState(
|
||||
POSITION_TYPE_BUY,
|
||||
this.allowLong //
|
||||
);
|
||||
|
||||
//
|
||||
x5Provider
|
||||
.SetSignalTypeState(
|
||||
POSITION_TYPE_SELL,
|
||||
this.allowShort //
|
||||
);
|
||||
|
||||
//
|
||||
x121Provider
|
||||
.SetSignalTypeState(
|
||||
POSITION_TYPE_BUY,
|
||||
this.allowLong //
|
||||
);
|
||||
|
||||
//
|
||||
x121Provider
|
||||
.SetSignalTypeState(
|
||||
POSITION_TYPE_SELL,
|
||||
this.allowShort //
|
||||
);
|
||||
|
||||
//
|
||||
// Enable Required Signallers ...
|
||||
x5Provider
|
||||
.SetSignalProviderStates(
|
||||
this.signallers,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
// Now Must to Initialize Provider ...
|
||||
result = x5Provider.Init(
|
||||
this.x5Inputs //
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = x121Provider.Init(
|
||||
this.x121Inputs //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
signal.Clean();
|
||||
x5Conditions.Clear();
|
||||
x121Conditions.Clear();
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid(bool validateInputs = true)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
(validateInputs
|
||||
? x5Inputs.IsValid() && x121Inputs.IsValid()
|
||||
: true) &&
|
||||
(allowLong || allowShort) &&
|
||||
ArraySize(signallers) > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal ...
|
||||
bool HasSignal(int barIndex = 0)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = x5Inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = x121Inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Clear Signal and Conditions ...
|
||||
Clean();
|
||||
|
||||
//
|
||||
result = x5Provider
|
||||
.HasSignal(
|
||||
barIndex,
|
||||
signal,
|
||||
x5Conditions //
|
||||
);
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
x121Provider
|
||||
.GetMarketConditions(
|
||||
x121Conditions,
|
||||
barIndex //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// "EURUSDb,USDCHFb,USDJPYb,XAUUSDb"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
long x5EAMagicNumber = 78692110; // Magic Number
|
||||
int x5EASlippage = 10; // Slippgae
|
||||
string x5EASymbols = "EURUSDb,USDCHFb,USDJPYb,XAUUSDb"; // Symbols
|
||||
long x5EAMagicNumber = 78692110; // Magic Number
|
||||
int x5EASlippage = 10; // Slippgae
|
||||
string x5EASymbols = "EURUSDb"; // Symbols
|
||||
//
|
||||
bool x5EAAllowLong = true; // Allow Long Trades
|
||||
bool x5EAAllowShort = true; // Allow Short Trades
|
||||
@@ -54,8 +326,8 @@ ENUM_TIMEFRAMES x5EAPeriod;
|
||||
MqlTick x5EATick;
|
||||
|
||||
//
|
||||
// X5121EA ...
|
||||
XSCX5121EA *mX5121EA;
|
||||
// Providers ...
|
||||
X5121ProviderDescriptor x5121EAProviders[];
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
@@ -85,7 +357,7 @@ int OnInit()
|
||||
|
||||
//
|
||||
// Initial EA ...
|
||||
if (!InitialX5EA())
|
||||
if (!InitialEA())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
@@ -130,7 +402,7 @@ void OnTick()
|
||||
}
|
||||
|
||||
//
|
||||
mX5121EA.OnTick();
|
||||
// mX5121EA.OnTick();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -157,7 +429,7 @@ bool X5121EAValidateInputs()
|
||||
|
||||
//
|
||||
// Initialize Specific Providers ...
|
||||
bool InitialX5EA()
|
||||
bool InitialEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
@@ -193,19 +465,7 @@ bool InitialX5EA()
|
||||
GetAllX5SignalProviders(signallers);
|
||||
|
||||
//
|
||||
// Instantiate X5121EA Class ...
|
||||
mX5121EA = new XSCX5121EA(
|
||||
x5EASlippage, // Slippgae
|
||||
x5EAMagicNumber, // Magic Number
|
||||
x5EAManageInterval, // Manager Check Intervals Seconds
|
||||
x5EAMaxAllowedSpread, // Max Allowed Spred for Opening Trades
|
||||
x5EAMaxAllowedPositions, // Max Allowed Positions
|
||||
x5EAMaxAllowedDrawdownFactor, // Max Allowed Drawdown Factor
|
||||
x5EAAllowLong, // Allow Long Trades
|
||||
x5EAAllowShort, // Allow Short Trades
|
||||
x5EAMinProfitPerTrade, // Min Profit Per Trade based On Volume Factor (Hedge)
|
||||
x5EAMinProfitPerVolumeFactor // Min Volume Factor for Calculating Profit (Hedge)
|
||||
);
|
||||
Clean(x5121EAProviders);
|
||||
|
||||
//
|
||||
// Prepare Providers and Add them into mX5121EA class ...
|
||||
@@ -213,7 +473,7 @@ bool InitialX5EA()
|
||||
{
|
||||
//
|
||||
// Define Structure ...
|
||||
X5ProviderDescriptor iDescriptor;
|
||||
X5121ProviderDescriptor iDescriptor;
|
||||
|
||||
//
|
||||
iDescriptor.symbol = symbols[i];
|
||||
@@ -226,24 +486,220 @@ bool InitialX5EA()
|
||||
|
||||
//
|
||||
// Set Inputs to Default ...
|
||||
iDescriptor.inputs.Default();
|
||||
iDescriptor.x5Inputs.Default();
|
||||
iDescriptor.x121Inputs.Default();
|
||||
|
||||
//
|
||||
// X121 Inputs ...
|
||||
//
|
||||
// Prepare Input Requirements ...
|
||||
|
||||
//
|
||||
// XMC ...
|
||||
iDescriptor.x121Inputs.mcInputs.showFastMa = false;
|
||||
iDescriptor.x121Inputs.mcInputs.showSlowMa = false;
|
||||
iDescriptor.x121Inputs.mcInputs.showVerifierMa = false;
|
||||
|
||||
//
|
||||
// XICH ...
|
||||
iDescriptor.x121Inputs.ichInputs.showKumo = false;
|
||||
iDescriptor.x121Inputs.ichInputs.showKijunSen = false;
|
||||
iDescriptor.x121Inputs.ichInputs.showTenkanSen = false;
|
||||
iDescriptor.x121Inputs.ichInputs.showChikouSpan = false;
|
||||
iDescriptor.x121Inputs.ichInputs.showSenkouSpanA = false;
|
||||
iDescriptor.x121Inputs.ichInputs.showSenkouSpanB = false;
|
||||
iDescriptor.x121Inputs.ichInputs.showKijunSenPlus = false;
|
||||
iDescriptor.x121Inputs.ichInputs.showKijunSenNegative = false;
|
||||
|
||||
//
|
||||
// XSTR ...
|
||||
iDescriptor.x121Inputs.cheInputs.showLongExit1Line = false;
|
||||
iDescriptor.x121Inputs.cheInputs.showShortExit1Line = false;
|
||||
iDescriptor.x121Inputs.cheInputs.showLongExit2Line = false;
|
||||
iDescriptor.x121Inputs.cheInputs.showShortExit2Line = false;
|
||||
|
||||
//
|
||||
// XPV ...
|
||||
iDescriptor.x121Inputs.pvInputs.showPeaksAndVales = true;
|
||||
iDescriptor.x121Inputs.pvInputs.showLevels = false;
|
||||
iDescriptor.x121Inputs.pvInputs.showConsolidations = false;
|
||||
iDescriptor.x121Inputs.pvInputs.showFibo1Levels = false;
|
||||
iDescriptor.x121Inputs.pvInputs.showFibo2Levels = false;
|
||||
iDescriptor.x121Inputs.pvInputs.showFibo3Levels = true;
|
||||
iDescriptor.x121Inputs.pvInputs.showFibo4Levels = false;
|
||||
iDescriptor.x121Inputs.pvInputs.showFibo5Levels = false;
|
||||
|
||||
//
|
||||
// XZG ...
|
||||
iDescriptor.x121Inputs.zgInputs.showZigZag = false;
|
||||
iDescriptor.x121Inputs.zgInputs.showPeaksAndVales = false;
|
||||
|
||||
//
|
||||
// XDON ...
|
||||
iDescriptor.x121Inputs.donInputs.showOpen = true;
|
||||
iDescriptor.x121Inputs.donInputs.showHigh = true;
|
||||
iDescriptor.x121Inputs.donInputs.showClose = true;
|
||||
iDescriptor.x121Inputs.donInputs.showLow = true;
|
||||
|
||||
//
|
||||
// XSTR ...
|
||||
iDescriptor.x121Inputs.strInputs.showTrends = true;
|
||||
iDescriptor.x121Inputs.strInputs.fillTrends = false;
|
||||
|
||||
//
|
||||
iDescriptor.x121Inputs.symbol = iDescriptor.symbol;
|
||||
iDescriptor.x121Inputs.period = iDescriptor.period;
|
||||
|
||||
//
|
||||
// Short MArket ...
|
||||
iDescriptor.x121Inputs.sMarketPeriod = NULL;
|
||||
iDescriptor.x121Inputs.sMarketMethod = X_PERIOD_AUTO;
|
||||
|
||||
//
|
||||
// Medium Market ...
|
||||
iDescriptor.x121Inputs.mMarketPeriod = NULL;
|
||||
iDescriptor.x121Inputs.mMarketMethod = X_PERIOD_AUTO;
|
||||
|
||||
//
|
||||
// Long Market ...
|
||||
iDescriptor.x121Inputs.lMarketPeriod = NULL;
|
||||
iDescriptor.x121Inputs.lMarketMethod = X_PERIOD_AUTO;
|
||||
|
||||
//
|
||||
int fontSize = 12;
|
||||
double fontAngel = 90;
|
||||
string fontName = "Arial";
|
||||
ENUM_ANCHOR_POINT fontAnchor = ANCHOR_LEFT_UPPER;
|
||||
|
||||
//
|
||||
// Hind Market ...
|
||||
iDescriptor.x121Inputs.hMarketPeriod = NULL;
|
||||
iDescriptor.x121Inputs.hMarketMethod = X_PERIOD_AUTO;
|
||||
iDescriptor.x121Inputs.hMarketInputs.drawLabels = false;
|
||||
iDescriptor.x121Inputs.hMarketInputs.drawCBar = true;
|
||||
iDescriptor.x121Inputs.hMarketInputs.drawPBar = true;
|
||||
iDescriptor.x121Inputs.hMarketInputs.drawCBarMid = true;
|
||||
iDescriptor.x121Inputs.hMarketInputs.drawPBarMid = true;
|
||||
iDescriptor.x121Inputs.hMarketInputs.cBarDrawSpecs.Default();
|
||||
iDescriptor.x121Inputs.hMarketInputs.pBarDrawSpecs.Default();
|
||||
|
||||
//
|
||||
iDescriptor.x121Inputs.hMarketInputs.cBarDrawSpecs.openStyle.Label(
|
||||
"C Hind Open",
|
||||
iDescriptor.x121Inputs.hMarketInputs.cBarDrawSpecs.openStyle.clr,
|
||||
fontName,
|
||||
fontSize,
|
||||
fontAnchor,
|
||||
fontAngel //
|
||||
);
|
||||
iDescriptor.x121Inputs.hMarketInputs.cBarDrawSpecs.highStyle.Label(
|
||||
"C Hind High",
|
||||
iDescriptor.x121Inputs.hMarketInputs.cBarDrawSpecs.highStyle.clr,
|
||||
fontName,
|
||||
fontSize,
|
||||
fontAnchor,
|
||||
fontAngel //
|
||||
);
|
||||
iDescriptor.x121Inputs.hMarketInputs.cBarDrawSpecs.closeStyle.Label(
|
||||
"C Hind Close",
|
||||
iDescriptor.x121Inputs.hMarketInputs.cBarDrawSpecs.closeStyle.clr,
|
||||
fontName,
|
||||
fontSize,
|
||||
fontAnchor,
|
||||
fontAngel //
|
||||
);
|
||||
iDescriptor.x121Inputs.hMarketInputs.cBarDrawSpecs.lowStyle.Label(
|
||||
"C Hind Low",
|
||||
iDescriptor.x121Inputs.hMarketInputs.cBarDrawSpecs.lowStyle.clr,
|
||||
fontName,
|
||||
fontSize,
|
||||
fontAnchor,
|
||||
fontAngel //
|
||||
);
|
||||
|
||||
//
|
||||
iDescriptor.x121Inputs.hMarketInputs.pBarDrawSpecs.openStyle.Label(
|
||||
"P Hind Open",
|
||||
iDescriptor.x121Inputs.hMarketInputs.pBarDrawSpecs.openStyle.clr,
|
||||
fontName,
|
||||
fontSize,
|
||||
fontAnchor,
|
||||
fontAngel //
|
||||
);
|
||||
iDescriptor.x121Inputs.hMarketInputs.pBarDrawSpecs.highStyle.Label(
|
||||
"P Hind High",
|
||||
iDescriptor.x121Inputs.hMarketInputs.pBarDrawSpecs.highStyle.clr,
|
||||
fontName,
|
||||
fontSize,
|
||||
fontAnchor,
|
||||
fontAngel //
|
||||
);
|
||||
iDescriptor.x121Inputs.hMarketInputs.pBarDrawSpecs.closeStyle.Label(
|
||||
"P Hind Close",
|
||||
iDescriptor.x121Inputs.hMarketInputs.pBarDrawSpecs.closeStyle.clr,
|
||||
fontName,
|
||||
fontSize,
|
||||
fontAnchor,
|
||||
fontAngel //
|
||||
);
|
||||
iDescriptor.x121Inputs.hMarketInputs.pBarDrawSpecs.lowStyle.Label(
|
||||
"P Hind Low",
|
||||
iDescriptor.x121Inputs.hMarketInputs.pBarDrawSpecs.lowStyle.clr,
|
||||
fontName,
|
||||
fontSize,
|
||||
fontAnchor,
|
||||
fontAngel //
|
||||
);
|
||||
|
||||
iDescriptor.x121Inputs.hMarketInputs.cBarMidDrawSpecs.clr = clrYellow;
|
||||
iDescriptor.x121Inputs.hMarketInputs.cBarMidDrawSpecs.Label(
|
||||
"C Hind Mid",
|
||||
clrYellow,
|
||||
fontName,
|
||||
fontSize,
|
||||
fontAnchor,
|
||||
fontAngel //
|
||||
);
|
||||
iDescriptor.x121Inputs.hMarketInputs.pBarMidDrawSpecs.clr = clrYellow;
|
||||
iDescriptor.x121Inputs.hMarketInputs.pBarMidDrawSpecs.Label(
|
||||
"P Hind Mid",
|
||||
clrYellow,
|
||||
fontName,
|
||||
fontSize,
|
||||
fontAnchor,
|
||||
fontAngel //
|
||||
);
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool isInputsValid = iDescriptor.inputs.IsValid();
|
||||
if (!isInputsValid)
|
||||
bool isX5InputsValid = iDescriptor.x5Inputs.IsValid();
|
||||
if (!isX5InputsValid)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
result = mX5121EA.AddProvider(iDescriptor);
|
||||
if (!result)
|
||||
// Initialize ...
|
||||
|
||||
//
|
||||
bool isDescriptorInitialized = iDescriptor.Init();
|
||||
if (!isDescriptorInitialized)
|
||||
{
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
AddRef(
|
||||
iDescriptor,
|
||||
x5121EAProviders //
|
||||
);
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(x5121EAProviders) == symbolsCount;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user