last works ...

This commit is contained in:
2024-05-22 13:15:20 +03:30
parent 23c989f083
commit 4a69e7edf8
17 changed files with 6815 additions and 78 deletions
File diff suppressed because it is too large Load Diff
+329
View File
@@ -0,0 +1,329 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCX121EA
// Description: provides all X121 EA requirements ...
// - X5 Provider;
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
#include "../Classes/x-saherelm.xea.class.mq5"
#include "../Classes/x-saherelm.x121.provider.class.mq5"
//
// Define On Signal Event Handler Type Specified for X5 ...
typedef void (*TX121OnSignal)(X121ProviderDescriptor &descriptor);
//
// Class Definition ...
class XSCX121EA : public XSCBaseEA
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCX121EA(
//
// XTrade Class Requirements ...
int slippage, // Specify Slippage
ulong magicNumber, // Specify Magic Number
int manageInterval, // Manager Check Intervals Seconds
double maxAllowedSpread, // Max Allowed Spred for Opening Trades
int maxAllowedPositions, // Max Allowed Positions
double maxAllowedDrawdownFactor, // Max Allowed Drawdown Factor
//
// Position Management ...
bool allowLong = true, // Allow Long Trades
bool allowShort = true, // Allow Short Trades
double minProfitPerTrade = 0, // Min Profit Per Trade based On Volume Factor (Hedge)
double minProfitPerVolumeFactor = 0, // Min Volume Factor for Calculating Profit (Hedge)
//
// Event Handlers ...
TOnStopLoss onStopLossTriggered = NULL, // On StopLoass Triggered Event Handler
TOnTakeProfit onTakeProfitTriggered = NULL, // On TakeProfit Triggered Event Handler
TOnDealsChanged onDealsChangedHandler = NULL, // On Deals Changed Event Handler
TOnOrdersChanged onOrdersChangedHandler = NULL, // On Orders Changed Event Handler
TOnPositionsChanged onPositionsChangedHandler = NULL, // On Positions Changed Event Handler
TOnTradeStateChanged onTradeStateChangedHandler = NULL, // On Trade State Changed Event Handler
//
TOnSignal onSignalHandler = NULL, // On Signal Event Handler
//
// Log Handler ...
bool enableAlerts = true, // Enable Alerts
bool logAlerts = true, // Log Alerts
bool terminalAlerts = false, // Terminal Alerts
bool mailAlerts = false, // Mail Alerts
bool pushAlerts = false // Push Alerts
) : XSCBaseEA(slippage,
magicNumber,
manageInterval,
maxAllowedSpread,
maxAllowedPositions,
maxAllowedDrawdownFactor,
allowLong,
allowShort,
minProfitPerTrade,
minProfitPerVolumeFactor,
onStopLossTriggered,
onTakeProfitTriggered,
onDealsChangedHandler,
onOrdersChangedHandler,
onPositionsChangedHandler,
onTradeStateChangedHandler,
enableAlerts,
logAlerts,
terminalAlerts,
mailAlerts,
pushAlerts //
)
{
}
//
// Deconstructor ...
~XSCX121EA() {}
//
// Properties Getter(s) / Setter(s) ...
//
// Add X5 Specified Signal Event Handler ...
void AddOnSignalEventHandler(TX121OnSignal listener)
{
//
Add(
listener,
mX121OnSignalEventHandlers
//
);
}
//
// Add Specified X5 Provider ...
bool AddProvider(X121ProviderDescriptor &descriptor)
{
//
bool result = false;
//
// Validate Inputs ...
result = descriptor.Init();
if (!result)
{
return result;
}
//
AddRef(
descriptor,
mDescriptors //
);
//
return result;
}
//
// Overrides ...
//
// Customize Token ...
string GetToken() override
{
return GetSpecificToken(this);
}
//
string GetTag() override
{
return this.GetToken();
}
//
void Draw() override
{
//
int descriptorsCount = CountDescriptors();
if (descriptorsCount <= 0)
{
return;
}
//
for (int i = 0; i < descriptorsCount; i++)
{
//
X121ProviderDescriptor iDescriptor = mDescriptors[i];
//
iDescriptor.provider.Draw();
}
}
//
// Check Provider for any Guards ...
bool CheckForGuard(XGuard &guards[]) override
{
//
// TODO: Implement this ...
return false;
}
//
// Request Provider to Collect all
// Potentially Signals and then
// filters theme here and passed them
// for Executing ...
int RequestForSignal(
XSignal &signals[] // Holds Signals ...
) override
{
//
bool result = 0;
//
Clean(signals);
//
int descriptorsCount = CountDescriptors();
if (descriptorsCount <= 0)
{
return result;
}
//
for (int i = 0; i < descriptorsCount; i++)
{
//
X121ProviderDescriptor iDescriptor = mDescriptors[i];
//
bool iHasSignal = iDescriptor.HasSignal();
if (iHasSignal)
{
//
// Here we Can double check Signals by Conditions
// for Score Base Filtering ...
//
AddRef(
iDescriptor.signal,
signals
//
);
//
NotifyX121OnSignalEventHandlers(iDescriptor);
}
}
//
result = ArraySize(signals);
//
return result;
}
//
// Handl Management Actions ...
// if returns true, it is going to prevent for processing forward ...
bool HandleStateManagement() override
{
//
// TODO: Implement this ...
return false;
}
//
// Request for Support Signals using Guard ...
bool RequestForSupport(
XSignal &support, // Holds Support Signal, if Provided
string provider, // Positions Provided by Specific Provider
string symbol, // Trading Symbol
ENUM_POSITION_TYPE type, // Trading Type
ENUM_TIMEFRAMES period // Specified Time Frame
) override
{
//
// TODO: Implement this ...
return false;
}
//
// Tools ...
//
// Protected ...
protected:
//
// Tools ...
//
void NotifyX121OnSignalEventHandlers(X121ProviderDescriptor &descriptor)
{
//
int listenersCount = ArraySize(mX121OnSignalEventHandlers);
if (listenersCount <= 0)
{
return;
}
//
for (int i = 0; i < listenersCount; i++)
{
//
TX121OnSignal iListener = mX121OnSignalEventHandlers[i];
//
iListener(descriptor);
}
}
//
// Private ...
private:
//
// Props ...
//
// Collection of Signal Event Listeners ...
TX121OnSignal mX121OnSignalEventHandlers[];
//
// a Collection of X5 Provider Descriptors ...
X121ProviderDescriptor mDescriptors[];
//
int CountDescriptors()
{
return ArraySize(mDescriptors);
}
//
// Tools ...
};
//
// Tools ...
//
File diff suppressed because it is too large Load Diff
+150 -35
View File
@@ -2,7 +2,7 @@
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCBaseX5Provider
// Name: XSCX5Provider
// Description: provides all Base Provider
// requirements For X5 ...
//
@@ -547,6 +547,7 @@ public:
bool isXCHMALCFastCrossedUnderSlow;
//
// Tools ...
//
// Conditions ...
@@ -1757,6 +1758,41 @@ public:
//
string result = NULL;
//
result = GenerateSummaryBody(
onlySummary,
multiplier,
separator,
ignoreFalseConditions
//
);
//
// Generating Full Result by Combining parts ...
result =
//
"[" + GetToken() + "]" + separator +
"-----------------------------" + separator +
result +
""
//
;
//
return result;
}
//
string GenerateSummaryBody(
const bool onlySummary = false, // Only Generate Conditions Summary
double multiplier = 1, // Score Multiplier
const string separator = "\n", // Separator
const bool ignoreFalseConditions = true // Ignore False Conditions
)
{
//
string result = NULL;
//
double bullScore = 0;
double bearScore = 0;
@@ -2007,8 +2043,6 @@ public:
// Generating Full Result by Combining parts ...
result =
//
"[" + GetToken() + "]" + separator +
"-----------------------------" + separator +
commonStr +
(onlySummary
? ""
@@ -2031,6 +2065,43 @@ public:
return result;
}
//
string GenerateSummary(
string provided, // Additional Info about Type, Provider and Symbol
const bool onlySummary = false, // Only Generate Conditions Summary
double multiplier = 1, // Score Multiplier
const string separator = "\n", // Separator
const bool ignoreFalseConditions = true // Ignore False Conditions
)
{
//
string result = NULL;
//
result = GenerateSummaryBody(
onlySummary,
multiplier,
separator,
ignoreFalseConditions
//
);
//
// Generating Full Result by Combining parts ...
result =
//
"[" + GetToken() + "]" + separator +
provided + separator +
"-----------------------------" + separator +
result +
""
//
;
//
return result;
}
//
// For Data Collector ...
string GetToken()
@@ -2109,11 +2180,33 @@ public:
// Properties Gettr(s) / Setter(s) ...
//
// Inheritance ...
// Overrides ...
//
// DeInit all Requirements ...
void DeInit() override
{
//
delete tsHelper;
delete fiHelper;
delete tdHelper;
delete lhHelper;
delete tmHelper;
delete ccHelper;
delete ctHelper;
delete obdHelper;
delete rsiHelper;
delete amaHelper;
delete chmaHelper;
delete chlhHelper;
}
//
// Functions ...
//
// Init all Requirements ...
virtual bool Init(X5ProviderInputs &inputs)
bool Init(X5ProviderInputs &inputs)
{
//
bool result = false;
@@ -2289,28 +2382,6 @@ public:
return result;
}
//
// DeInit all Requirements ...
virtual void DeInit()
{
//
delete tsHelper;
delete fiHelper;
delete tdHelper;
delete lhHelper;
delete tmHelper;
delete ccHelper;
delete ctHelper;
delete obdHelper;
delete rsiHelper;
delete amaHelper;
delete chmaHelper;
delete chlhHelper;
}
//
// Functions ...
//
// Set Default Position's Type ...
// Enable / Disable Long (Buy), Short (Sell) ...
@@ -2783,16 +2854,59 @@ public:
if (result)
{
//
mWaitsUntilNewBar = true;
// Here We Have to Prepare Signal ...
//
string mConditionsStr = mConditions.GenerateSummary(true);
// TODO: Make this Configurable ...
string symbol = GetSymbol();
ENUM_TIMEFRAMES period = GetPeriod();
double tpPoint = 30;
double volume = 0.01;
double tpPrice = PointToPrice(
tpPoint,
symbol //
);
ENUM_POSITION_TYPE type = hasLong
? POSITION_TYPE_BUY
: POSITION_TYPE_SELL;
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
double entry = GetEntry(
symbol,
type //
);
double tp = hasLong
? entry + tpPrice
: entry - tpPrice;
double sl = 0;
ENUM_X_SIGNAL_MANAGING_ACTIONS action = X_SIGNAL_USE_NOTHING;
//
string providerTypeStr = GetSymbol() + ", " + provider + "(" + (hasLong ? "Long" : "Short") + ")";
mConditionsStr = providerTypeStr + "\n" + mConditionsStr;
mConditionsCollector.Add(mConditionsStr);
Print(mConditionsStr);
result = mSignal.Prepare(
symbol,
provider,
period,
type,
mode,
entry,
volume,
action,
sl,
tp
//
);
//
if (result)
{
//
mWaitsUntilNewBar = true;
//
string providerTypeStr = GetSymbol() + ", " + provider + "(" + (hasLong ? "Long" : "Short") + ")";
string mConditionsStr = mConditions.GenerateSummary(providerTypeStr, true);
mConditionsCollector.Add(mConditionsStr);
Print(mConditionsStr);
}
}
//
@@ -95066,7 +95180,7 @@ struct X5ProviderDescriptor
//
ENUM_X5_SIGNAL_PROVIDERS tmp[];
Copy(
mSignallers,
mSignallers,
tmp //
);
Copy(
@@ -95171,7 +95285,8 @@ struct X5ProviderDescriptor
result = provider.HasSignal(
barIndex,
signal,
conditions);
conditions //
);
//
return result;
+3
View File
@@ -210,6 +210,9 @@ public:
signals
//
);
//
NotifyX5OnSignalEventHandlers(iDescriptor);
}
}
+20
View File
@@ -385,6 +385,10 @@ public:
// OnTick Handler ...
virtual void OnTick()
{
//
// Draw ...
Draw();
//
// Check Trade Events ...
OnTrade();
@@ -528,6 +532,10 @@ public:
// TODO: Implement this ...
}
//
// Draw On Chart if anything is required ...
virtual void Draw() {}
//
// Check For any Guard Actions ...
virtual bool CheckForGuard(XGuard &guards[])
@@ -628,7 +636,19 @@ public:
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)
{
+420
View File
@@ -0,0 +1,420 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center X121EA MQL5 Expert Advisor
// -------------------------------------------------
// Name: X121EA
// Description: an Exper Advisor which used RSI and MA
// to Analyse Market ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////x
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X121EA"
#property strict
//
#define ShortName "X121EA"
//
#include "../Classes/x-saherelm.x121.xea.class.mq5"
//
// "EURUSDb,USDCHFb,USDJPYb,XAUUSDb"
//
// Inputs ...
long x121EAMagicNumber = 78692110; // Magic Number
int x121EASlippage = 10; // Slippgae
string x121EASymbols = "EURUSDb,USDCHFb"; // Symbols
//
bool x121EAAllowLong = true; // Allow Long Trades
bool x121EAAllowShort = true; // Allow Short Trades
int x121EAManageInterval = 5; // Manager Check Intervals Seconds
int x121EAMaxAllowedPositions = 15; // Max Allowed Positions
double x121EAMaxAllowedSpread = 0; // Max Allowed Spred for Opening Trades
double x121EAMinProfitPerTrade = 0; // Min Profit Per Trade based On Volume Factor (Hedge)
double x121EAMinProfitPerVolumeFactor = 0; // Min Volume Factor for Calculating Profit (Hedge)
double x121EAMaxAllowedDrawdownFactor = 0; // Max Allowed Drawdown Factor
//
double x121EAVolume = 0.01;
//
// Vars ...
string x121EASymbol;
ENUM_TIMEFRAMES x121EAPeriod;
//
MqlTick x121EATick;
//
// X121EA ...
XSCX121EA *mX121EA;
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
if (x121EASymbol == NULL || StringLen(x121EASymbol) <= 0)
{
x121EASymbol = _Symbol;
}
//
if (x121EAPeriod == NULL)
{
x121EAPeriod = _Period;
}
//
// Validate Inputs ...
if (!X121EAValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initial EA ...
if (!InitialEA())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// TesterHideIndicators(true);
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// De Initialize X121EA Providers ...
}
//
// On Tick Handler ...
void OnTick()
{
//
// Reading Tick ...
if (!SymbolInfoTick(x121EASymbol, x121EATick))
{
return;
}
//
mX121EA.OnTick();
}
//
// Custom Functions ...
//
// Validate Variables nd Inputs ...
bool X121EAValidateInputs()
{
//
bool result = false;
//
result =
//
x121EASlippage > 0 &&
x121EAMagicNumber > 0
//
;
//
return result;
}
//
// Initialize Specific Providers ...
bool InitialEA()
{
//
bool result = false;
//
// Here We Have to Initial 4 instance of X5Provider ...
// - EURUSD/M5;
// - USDCHF/M5;
// - USDJPY/M5;
// - XAUUSD/M5;
//
result = IsValid(x121EASymbols);
if (!result)
{
return result;
}
//
string symbols[];
int symbolsCount = SplitContent(
symbols,
x121EASymbols);
result = symbolsCount > 0;
if (!result)
{
return result;
}
//
// Define Signallers ...
ENUM_X121_SIGNAL_PROVIDERS signallers[];
GetAllX121SignalProviders(signallers);
//
// Instantiate X121EA Class ...
mX121EA = new XSCX121EA(
x121EASlippage, // Slippgae
x121EAMagicNumber, // Magic Number
x121EAManageInterval, // Manager Check Intervals Seconds
x121EAMaxAllowedSpread, // Max Allowed Spred for Opening Trades
x121EAMaxAllowedPositions, // Max Allowed Positions
x121EAMaxAllowedDrawdownFactor, // Max Allowed Drawdown Factor
x121EAAllowLong, // Allow Long Trades
x121EAAllowShort, // Allow Short Trades
x121EAMinProfitPerTrade, // Min Profit Per Trade based On Volume Factor (Hedge)
x121EAMinProfitPerVolumeFactor // Min Volume Factor for Calculating Profit (Hedge)
);
//
// Prepare Providers and Add them into mX121EA class ...
for (int i = 0; i < symbolsCount; i++)
{
//
// Requirements ...
string iSymbol = symbols[i];
ENUM_TIMEFRAMES iPeriod = PERIOD_M5;
//
// Define Structure ...
X121ProviderDescriptor iDescriptor;
//
iDescriptor.symbol = iSymbol;
iDescriptor.period = iPeriod;
iDescriptor.allowLong = x121EAAllowLong;
iDescriptor.allowShort = x121EAAllowShort;
Copy(
signallers,
iDescriptor.signallers);
//
// Set Inputs to Default ...
iDescriptor.inputs.Default();
//
// Prepare Input Requirements ...
//
// XMC ...
iDescriptor.inputs.mcInputs.showFastMa = false;
iDescriptor.inputs.mcInputs.showSlowMa = false;
iDescriptor.inputs.mcInputs.showVerifierMa = false;
//
// XICH ...
iDescriptor.inputs.ichInputs.showKumo = false;
iDescriptor.inputs.ichInputs.showKijunSen = false;
iDescriptor.inputs.ichInputs.showTenkanSen = false;
iDescriptor.inputs.ichInputs.showChikouSpan = false;
iDescriptor.inputs.ichInputs.showSenkouSpanA = false;
iDescriptor.inputs.ichInputs.showSenkouSpanB = false;
iDescriptor.inputs.ichInputs.showKijunSenPlus = false;
iDescriptor.inputs.ichInputs.showKijunSenNegative = false;
//
// XSTR ...
iDescriptor.inputs.cheInputs.showLongExit1Line = false;
iDescriptor.inputs.cheInputs.showShortExit1Line = false;
iDescriptor.inputs.cheInputs.showLongExit2Line = false;
iDescriptor.inputs.cheInputs.showShortExit2Line = false;
//
// XSTR ...
iDescriptor.inputs.strInputs.showTrends = false;
iDescriptor.inputs.strInputs.fillTrends = false;
//
iDescriptor.inputs.symbol = iSymbol;
iDescriptor.inputs.period = iPeriod;
//
// Short MArket ...
iDescriptor.inputs.sMarketPeriod = NULL;
iDescriptor.inputs.sMarketMethod = X_PERIOD_AUTO;
//
// Medium Market ...
iDescriptor.inputs.mMarketPeriod = NULL;
iDescriptor.inputs.mMarketMethod = X_PERIOD_AUTO;
//
// Long Market ...
iDescriptor.inputs.lMarketPeriod = NULL;
iDescriptor.inputs.lMarketMethod = X_PERIOD_AUTO;
//
int fontSize = 12;
double fontAngel = 90;
string fontName = "Arial";
ENUM_ANCHOR_POINT fontAnchor = ANCHOR_LEFT_UPPER;
//
// Hind Market ...
iDescriptor.inputs.hMarketPeriod = NULL;
iDescriptor.inputs.hMarketMethod = X_PERIOD_AUTO;
iDescriptor.inputs.hMarketInputs.drawLabels = true;
iDescriptor.inputs.hMarketInputs.drawCBar = true;
iDescriptor.inputs.hMarketInputs.drawPBar = true;
iDescriptor.inputs.hMarketInputs.drawCBarMid = true;
iDescriptor.inputs.hMarketInputs.drawPBarMid = true;
iDescriptor.inputs.hMarketInputs.cBarDrawSpecs.Default();
iDescriptor.inputs.hMarketInputs.pBarDrawSpecs.Default();
//
iDescriptor.inputs.hMarketInputs.cBarDrawSpecs.openStyle.Label(
"C Hind Open",
iDescriptor.inputs.hMarketInputs.cBarDrawSpecs.openStyle.clr,
fontName,
fontSize,
fontAnchor,
fontAngel //
);
iDescriptor.inputs.hMarketInputs.cBarDrawSpecs.highStyle.Label(
"C Hind High",
iDescriptor.inputs.hMarketInputs.cBarDrawSpecs.highStyle.clr,
fontName,
fontSize,
fontAnchor,
fontAngel //
);
iDescriptor.inputs.hMarketInputs.cBarDrawSpecs.closeStyle.Label(
"C Hind Close",
iDescriptor.inputs.hMarketInputs.cBarDrawSpecs.closeStyle.clr,
fontName,
fontSize,
fontAnchor,
fontAngel //
);
iDescriptor.inputs.hMarketInputs.cBarDrawSpecs.lowStyle.Label(
"C Hind Low",
iDescriptor.inputs.hMarketInputs.cBarDrawSpecs.lowStyle.clr,
fontName,
fontSize,
fontAnchor,
fontAngel //
);
//
iDescriptor.inputs.hMarketInputs.pBarDrawSpecs.openStyle.Label(
"P Hind Open",
iDescriptor.inputs.hMarketInputs.pBarDrawSpecs.openStyle.clr,
fontName,
fontSize,
fontAnchor,
fontAngel //
);
iDescriptor.inputs.hMarketInputs.pBarDrawSpecs.highStyle.Label(
"P Hind High",
iDescriptor.inputs.hMarketInputs.pBarDrawSpecs.highStyle.clr,
fontName,
fontSize,
fontAnchor,
fontAngel //
);
iDescriptor.inputs.hMarketInputs.pBarDrawSpecs.closeStyle.Label(
"P Hind Close",
iDescriptor.inputs.hMarketInputs.pBarDrawSpecs.closeStyle.clr,
fontName,
fontSize,
fontAnchor,
fontAngel //
);
iDescriptor.inputs.hMarketInputs.pBarDrawSpecs.lowStyle.Label(
"P Hind Low",
iDescriptor.inputs.hMarketInputs.pBarDrawSpecs.lowStyle.clr,
fontName,
fontSize,
fontAnchor,
fontAngel //
);
iDescriptor.inputs.hMarketInputs.cBarMidDrawSpecs.clr = clrYellow;
iDescriptor.inputs.hMarketInputs.cBarMidDrawSpecs.Label(
"C Hind Mid",
clrYellow,
fontName,
fontSize,
fontAnchor,
fontAngel //
);
iDescriptor.inputs.hMarketInputs.pBarMidDrawSpecs.clr = clrYellow;
iDescriptor.inputs.hMarketInputs.pBarMidDrawSpecs.Label(
"P Hind Mid",
clrYellow,
fontName,
fontSize,
fontAnchor,
fontAngel //
);
//
// Init Inputs ...
result = iDescriptor.inputs.Init();
if (!result)
{
return result;
}
//
// Validate Inputs ...
bool isInputsValid = iDescriptor.inputs.IsValid();
if (!isInputsValid)
{
continue;
}
//
result = mX121EA.AddProvider(iDescriptor);
if (!result)
{
break;
}
}
//
return result;
}
//
+251
View File
@@ -0,0 +1,251 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center X5121EA MQL5 Expert Advisor
// -------------------------------------------------
// Name: X5121EA and X121EA
// Description: an Exper Advisor which used RSI and MA
// to Analyse Market ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////x
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X5121EA"
#property strict
//
#define ShortName "X5121EA"
//
#include "../Classes/x-saherelm.x5.xea.class.mq5"
//
// "EURUSDb,USDCHFb,USDJPYb,XAUUSDb"
//
// Inputs ...
long x5EAMagicNumber = 78692110; // Magic Number
int x5EASlippage = 10; // Slippgae
string x5EASymbols = "EURUSDb,USDCHFb,USDJPYb,XAUUSDb"; // Symbols
//
bool x5EAAllowLong = true; // Allow Long Trades
bool x5EAAllowShort = true; // Allow Short Trades
int x5EAManageInterval = 5; // Manager Check Intervals Seconds
int x5EAMaxAllowedPositions = 15; // Max Allowed Positions
double x5EAMaxAllowedSpread = 0; // Max Allowed Spred for Opening Trades
double x5EAMinProfitPerTrade = 0; // Min Profit Per Trade based On Volume Factor (Hedge)
double x5EAMinProfitPerVolumeFactor = 0; // Min Volume Factor for Calculating Profit (Hedge)
double x5EAMaxAllowedDrawdownFactor = 0; // Max Allowed Drawdown Factor
//
double x5EAVolume = 0.01;
//
// Vars ...
string x5EASymbol;
ENUM_TIMEFRAMES x5EAPeriod;
//
MqlTick x5EATick;
//
// X5121EA ...
XSCX5121EA *mX5121EA;
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
if (x5EASymbol == NULL || StringLen(x5EASymbol) <= 0)
{
x5EASymbol = _Symbol;
}
//
if (x5EAPeriod == NULL)
{
x5EAPeriod = _Period;
}
//
// Validate Inputs ...
if (!X5121EAValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initial EA ...
if (!InitialX5EA())
{
return INIT_PARAMETERS_INCORRECT;
}
//
TesterHideIndicators(true);
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// De Initialize X5121EA Providers ...
}
//
// On Tick Handler ...
void OnTick()
{
//
// Reading Tick ...
if (!SymbolInfoTick(x5EASymbol, x5EATick))
{
return;
}
//
mX5121EA.OnTick();
}
//
// Custom Functions ...
//
// Validate Variables nd Inputs ...
bool X5121EAValidateInputs()
{
//
bool result = false;
//
result =
//
x5EASlippage > 0 &&
x5EAMagicNumber > 0
//
;
//
return result;
}
//
// Initialize Specific Providers ...
bool InitialX5EA()
{
//
bool result = false;
//
// Here We Have to Initial 4 instance of X5Provider ...
// - EURUSD/M5;
// - USDCHF/M5;
// - USDJPY/M5;
// - XAUUSD/M5;
//
result = IsValid(x5EASymbols);
if (!result)
{
return result;
}
//
string symbols[];
int symbolsCount = SplitContent(
symbols,
x5EASymbols);
result = symbolsCount > 0;
if (!result)
{
return result;
}
//
// Define Signallers ...
ENUM_X5_SIGNAL_PROVIDERS signallers[];
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)
);
//
// Prepare Providers and Add them into mX5121EA class ...
for (int i = 0; i < symbolsCount; i++)
{
//
// Define Structure ...
X5ProviderDescriptor iDescriptor;
//
iDescriptor.symbol = symbols[i];
iDescriptor.period = PERIOD_M5;
iDescriptor.allowLong = x5EAAllowLong;
iDescriptor.allowShort = x5EAAllowShort;
Copy(
signallers,
iDescriptor.signallers);
//
// Set Inputs to Default ...
iDescriptor.inputs.Default();
//
// Validate Inputs ...
bool isInputsValid = iDescriptor.inputs.IsValid();
if (!isInputsValid)
{
continue;
}
//
result = mX5121EA.AddProvider(iDescriptor);
if (!result)
{
break;
}
}
//
return result;
}
//
+14 -11
View File
@@ -30,18 +30,18 @@
//
// Inputs ...
long x5EAMagicNumber = 78692110; // Magic Number
int x5EASlippage = 10; // Slippgae
string x5EASymbols = "EURUSDb"; // Symbols
long x5EAMagicNumber = 78692110; // Magic Number
int x5EASlippage = 10; // Slippgae
string x5EASymbols = "EURUSDb,USDCHFb,USDJPYb,XAUUSDb"; // Symbols
//
bool x5EAAllowLong = true; // Allow Long Trades
bool x5EAAllowShort = true; // Allow Short Trades
int x5EAManageInterval = 5; // Manager Check Intervals Seconds
int x5EAMaxAllowedPositions = 15; // Max Allowed Positions
double x5EAMaxAllowedSpread = 15; // Max Allowed Spred for Opening Trades
double x5EAMinProfitPerTrade = 0; // Min Profit Per Trade based On Volume Factor (Hedge)
double x5EAMinProfitPerVolumeFactor = 0; // Min Volume Factor for Calculating Profit (Hedge)
double x5EAMaxAllowedDrawdownFactor = 0.015; // Max Allowed Drawdown Factor
bool x5EAAllowLong = true; // Allow Long Trades
bool x5EAAllowShort = true; // Allow Short Trades
int x5EAManageInterval = 5; // Manager Check Intervals Seconds
int x5EAMaxAllowedPositions = 15; // Max Allowed Positions
double x5EAMaxAllowedSpread = 0; // Max Allowed Spred for Opening Trades
double x5EAMinProfitPerTrade = 0; // Min Profit Per Trade based On Volume Factor (Hedge)
double x5EAMinProfitPerVolumeFactor = 0; // Min Volume Factor for Calculating Profit (Hedge)
double x5EAMaxAllowedDrawdownFactor = 0; // Max Allowed Drawdown Factor
//
double x5EAVolume = 0.01;
@@ -90,6 +90,9 @@ int OnInit()
return INIT_PARAMETERS_INCORRECT;
}
//
TesterHideIndicators(true);
//
// Init Succeed ...
return INIT_SUCCEEDED;
+6 -6
View File
@@ -217,8 +217,8 @@ struct XCHLHInputs
lcHHColor = clrAqua;
lcLLColor = clrFuchsia;
// LC Drawings ...
lcDrawHH = true;
lcDrawLL = true;
lcDrawHH = false;
lcDrawLL = false;
//
// Medium Cycle ...
@@ -234,8 +234,8 @@ struct XCHLHInputs
mcHHColor = clrLime;
mcLLColor = clrRed;
// MC Drawings ...
mcDrawHH = true;
mcDrawLL = true;
mcDrawHH = false;
mcDrawLL = false;
//
// Short Cycle ...
@@ -251,8 +251,8 @@ struct XCHLHInputs
scHHColor = clrLightBlue;
scLLColor = clrLightSalmon;
// SC Drawings ...
scDrawHH = true;
scDrawLL = true;
scDrawHH = false;
scDrawLL = false;
}
//
+6 -6
View File
@@ -218,8 +218,8 @@ struct XCHMAInputs
lcFastColor = clrAqua;
lcSlowColor = clrFuchsia;
// LC Drawings ...
lcDrawFast = true;
lcDrawSlow = true;
lcDrawFast = false;
lcDrawSlow = false;
lcDrawCrosses = false;
//
@@ -236,8 +236,8 @@ struct XCHMAInputs
mcFastColor = clrLime;
mcSlowColor = clrRed;
// MC Drawings ...
mcDrawFast = true;
mcDrawSlow = true;
mcDrawFast = false;
mcDrawSlow = false;
mcDrawCrosses = false;
//
@@ -254,8 +254,8 @@ struct XCHMAInputs
scFastColor = clrLightBlue;
scSlowColor = clrLightSalmon;
// SC Drawings ...
scDrawFast = true;
scDrawSlow = true;
scDrawFast = false;
scDrawSlow = false;
scDrawCrosses = false;
}
+4 -4
View File
@@ -68,9 +68,9 @@ struct XOBDInputs
{
//
length = 0;
swingHighArrowCode = 108;
swingHighArrowCode = 0;
swingHighArrowColor = CLR_NONE;
swingLowArrowCode = 108;
swingLowArrowCode = 0;
swingLowArrowColor = CLR_NONE;
}
@@ -80,9 +80,9 @@ struct XOBDInputs
{
//
length = 5;
swingHighArrowCode = 108;
swingHighArrowCode = 0;
swingHighArrowColor = CLR_NONE;
swingLowArrowCode = 108;
swingLowArrowCode = 0;
swingLowArrowColor = CLR_NONE;
}
+5 -2
View File
@@ -242,7 +242,10 @@ struct XPVInputs
//
result =
//
false
IsValid(scMethod, scPeriod) &&
IsValid(mcMethod, mcPeriod) &&
IsValid(lcMethod, lcPeriod) &&
IsValid(hcMethod, hcPeriod)
//
;
@@ -290,7 +293,7 @@ public:
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XPVInputs &inputs // Inputs
XPVInputs &inputs // Inputs
)
{
//
+2 -2
View File
@@ -72,7 +72,7 @@ struct XTDInputs
{
//
length = 0;
drawCrosses = true;
drawCrosses = false;
//
// Bullish ...
@@ -91,7 +91,7 @@ struct XTDInputs
{
//
length = 14;
drawCrosses = true;
drawCrosses = false;
//
// Bullish ...
+8
View File
@@ -350,6 +350,14 @@ void DrawSwingArrow(
{
//
bool isSwingHigh = type == 1;
//
if ((isSwingHigh && swingHighArrowCode == 0) ||
(!isSwingHigh && swingLowArrowCode == 0))
{
return;
}
XOHCL candle;
candle.Init(
_Symbol,
+25 -3
View File
@@ -2477,6 +2477,11 @@ bool IsValid(string value)
//
return result;
}
bool IsSpecifiedValid(string value)
{
return IsValid(value);
}
//
// Validate a Date ...
@@ -2509,6 +2514,11 @@ bool IsValid(ENUM_TIMEFRAMES value)
//
return result;
}
bool IsSpecifiedValid(ENUM_TIMEFRAMES value)
{
//
return IsValid(value);
}
//
// Validate Specified Cycle ...
@@ -2556,6 +2566,17 @@ bool IsValid(
return result;
}
//
bool IsSpecifiedValid(
ENUM_X_PERIOD_METHOD mMethod, // Period Select Method
ENUM_TIMEFRAMES mPeriod // Selected Period
)
{
return IsValid(mMethod,
mPeriod //
);
}
//
// Validate Swing Mode ...
bool IsValid(ENUM_X_SWING_TYPE value)
@@ -2633,16 +2654,17 @@ bool IsRunningOnTestMode()
//
// Find Chart ID ...
ulong FindChartID(
long FindChartID(
string mSymbol = NULL, // Trading Symbol
ENUM_TIMEFRAMES mPeriod = NULL // Trading Period
)
{
//
ulong result = ChartFirst();
long result = ChartFirst();
long first = result;
//
while (result >= 0)
while (result > 0)
{
//
string chSymbol = ChartSymbol(result);
+29 -9
View File
@@ -218,15 +218,16 @@ struct XSignal
//
bool Prepare(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
ENUM_POSITION_TYPE mType, // Long (Buy) or Short (Sell)
ENUM_X_ORDER_MODES mMode, // Execution Mode
double mEntry, // Entry Price
double mVolume, // Volume
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
ENUM_POSITION_TYPE mType, // Long (Buy) or Short (Sell)
ENUM_X_ORDER_MODES mMode, // Execution Mode
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
{
//
@@ -284,6 +285,9 @@ struct XSignal
entry = mEntry;
volume = mVolume;
//
action = mAction;
//
Add(
sl,
@@ -313,6 +317,7 @@ struct XSignal
ENUM_X_ORDER_MODES mMode, // Execution Mode
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
@@ -326,6 +331,7 @@ struct XSignal
mMode,
mEntry,
mVolume,
mAction,
sl,
tp
//
@@ -340,6 +346,7 @@ struct XSignal
ENUM_X_ORDER_MODES mMode, // Execution Mode
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
@@ -353,6 +360,7 @@ struct XSignal
mMode,
mEntry,
mVolume,
mAction,
sl,
tp
//
@@ -369,6 +377,7 @@ struct XSignal
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
@@ -381,6 +390,7 @@ struct XSignal
X_ORDER_MODE_MARKET,
mEntry,
mVolume,
mAction,
sl,
tp
//
@@ -394,6 +404,7 @@ struct XSignal
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
@@ -406,6 +417,7 @@ struct XSignal
X_ORDER_MODE_MARKET,
mEntry,
mVolume,
mAction,
sl,
tp
//
@@ -422,6 +434,7 @@ struct XSignal
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
@@ -434,6 +447,7 @@ struct XSignal
X_ORDER_MODE_STOP,
mEntry,
mVolume,
mAction,
sl,
tp
//
@@ -447,6 +461,7 @@ struct XSignal
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
@@ -459,6 +474,7 @@ struct XSignal
X_ORDER_MODE_STOP,
mEntry,
mVolume,
mAction,
sl,
tp
//
@@ -475,6 +491,7 @@ struct XSignal
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
@@ -487,6 +504,7 @@ struct XSignal
X_ORDER_MODE_LIMIT,
mEntry,
mVolume,
mAction,
sl,
tp
//
@@ -500,6 +518,7 @@ struct XSignal
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
@@ -512,6 +531,7 @@ struct XSignal
X_ORDER_MODE_LIMIT,
mEntry,
mVolume,
mAction,
sl,
tp
//