refactor some typos on helper classes and implement base classes for providers and start x5 provider ...

This commit is contained in:
2024-05-19 01:55:13 +03:30
parent 2777f56d78
commit 9c6cd61f2b
29 changed files with 5672 additions and 235 deletions
+396
View File
@@ -0,0 +1,396 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCBaseX5Provider
// Description: provides all Base Provider
// requirements For X5 ...
//
//
// 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 "../Helpers/x-saherelm.xct.helper.mq5"
#include "../Helpers/x-saherelm.xcc.helper.mq5"
#include "../Helpers/x-saherelm.xtm.helper.mq5"
#include "../Helpers/x-saherelm.xama.helper.mq5"
#include "../Helpers/x-saherelm.xlh.helper.mq5"
#include "../Helpers/x-saherelm.xtd.helper.mq5"
#include "../Helpers/x-saherelm.xfi.helper.mq5"
#include "../Helpers/x-saherelm.xts.helper.mq5"
#include "../Helpers/x-saherelm.xrsi.helper.mq5"
#include "../Helpers/x-saherelm.xobd.helper.mq5"
#include "../Helpers/x-saherelm.xchlh.helper.mq5"
#include "../Helpers/x-saherelm.xchma.helper.mq5"
//
#include "../Classes/x-saherelm.xprovider.class.mq5"
//
// Definitions ...
//
enum ENUM_X5_SIGNAL_PROVIDERS
{
//
// XSP Expert Support Mechanism ...
XSP,
//
// XTD ...
XTD,
//
// XTAM ...
XTAM,
//
// XSI ...
XSI,
//
// XTSFI ...
XTSFI,
//
// XOBDLH ...
XOBDLH,
//
// XCHMACC ...
XCHMACC,
//
// XCHMACMN ...
XCHMAMN,
//
// XCHMACMX ...
XCHMAMX,
};
//
// X5 Provider Inputs ...
class X5ProviderInputs : public XSCBaseProviderInpts
{
//
// Public ...
public:
//
// Props ...
XTMInputs tmInputs;
XLHInputs lhInputs;
XTDInputs tdInputs;
XFIInputs fiInputs;
XCTInputs ctInputs;
XCCInputs ccInputs;
XOBDInputs obdInputs;
XAMAInputs amaInputs;
XRSIInputs rsiInputs;
XCHLHInputs chlhInputs;
XCHMAInputs chmaInputs;
//
// Tools ...
//
// Validate ...
virtual bool IsValid()
{
//
bool result = false;
//
result = ctInputs.IsValid();
if (!result)
{
return result;
}
//
result = ccInputs.IsValid();
if (!result)
{
return result;
}
//
result = tmInputs.IsValid();
if (!result)
{
return result;
}
//
result = lhInputs.IsValid();
if (!result)
{
return result;
}
//
result = tdInputs.IsValid();
if (!result)
{
return result;
}
//
result = fiInputs.IsValid();
if (!result)
{
return result;
}
//
result = obdInputs.IsValid();
if (!result)
{
return result;
}
//
result = amaInputs.IsValid();
if (!result)
{
return result;
}
//
result = rsiInputs.IsValid();
if (!result)
{
return result;
}
//
result = chlhInputs.IsValid();
if (!result)
{
return result;
}
//
result = chmaInputs.IsValid();
//
return result;
}
//
// Cleanup ...
virtual void Clean()
{
//
ctInputs.Clean();
ccInputs.Clean();
tmInputs.Clean();
lhInputs.Clean();
tdInputs.Clean();
fiInputs.Clean();
obdInputs.Clean();
amaInputs.Clean();
rsiInputs.Clean();
chlhInputs.Clean();
chmaInputs.Clean();
}
//
// Default ...
virtual void Default()
{
//
ctInputs.Default();
ccInputs.Default();
tmInputs.Default();
lhInputs.Default();
tdInputs.Default();
fiInputs.Default();
obdInputs.Default();
amaInputs.Default();
rsiInputs.Default();
chlhInputs.Default();
chmaInputs.Default();
}
//
// Max ...
virtual int Max()
{
//
int result = 0;
//
result = MathMax(lhInputs.Max(), tmInputs.Max());
//
result = MathMax(result, ctInputs.Max());
result = MathMax(result, ccInputs.Max());
result = MathMax(result, tdInputs.Max());
result = MathMax(result, fiInputs.Max());
result = MathMax(result, obdInputs.Max());
result = MathMax(result, amaInputs.Max());
result = MathMax(result, rsiInputs.Max());
result = MathMax(result, chlhInputs.Max());
result = MathMax(result, chmaInputs.Max());
//
return result;
}
};
//
// X5 Provider Market Conditions ...
class X5MarketConditions : public XSCBaseProviderMarketConditions
{
//
// Buffers ...
//
// Conditions ...
//
// Generate Score ...
virtual void GenerateScore(
double &bullishScore, // Bullish Score
double &bearishScore, // Bearish Score
const double multiplier = 1 // Score Multiplier
)
{
}
//
// Generate Summary ...
virtual string GenerateSummary(
const double multiplier = 1, // Score Multiplier
const bool ignoreFalseConditions = true // Ignore False Conditions
)
{
//
string result = NULL;
//
return result;
}
};
//
// Class ...
//
// X5 Provider Class ...
class XSC5Provider : public XSCBaseProvider
{
//
// Public ...
public:
//
// Props ...
XSCXTSHelper *tsHelper;
XSCXFIHelper *fiHelper;
XSCXTDHelper *tdHelper;
XSCXLHHelper *lhHelper;
XSCXTMHelper *tmHelper;
XSCXOBDHelper *obdHelper;
XSCXRSIHelper *rsiHelper;
XSCXAMAHelper *amaHelper;
XSCXCHMAHelper *chmaHelper;
XSCXCHLHHelper *chlhHelper;
//
// Constructor ...
XSC5Provider(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period // Trading PEriod
) : XSCBaseProvider(symbol, period)
{
//
}
//
// Properties Gettr(s) / Setter(s) ...
//
// Inheritance ...
//
// Init all Requirements ...
virtual bool Init(X5ProviderInputs &inputs)
{
//
bool result = false;
//
// Validate ...
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
return result;
}
//
// DeInit all Requirements ...
virtual void DeInit()
{
}
//
// Functions ...
//
virtual bool GetMarketConditions(
X5MarketConditions &conditions, // Market Conditions Result
int barIndex = 0 // Specified Bar Index
)
{
//
bool result = false;
//
return result;
}
//
// Check Market For Signal ...
virtual bool HasSignal(
int barIndex,
XSignal &signal, // Hold's Signal if Exists ...
X5MarketConditions &conditions // Hold's Market Conditions ...
)
{
//
bool result = false;
//
return result;
}
//
// Protected ...
protected:
//
// X5MarketConditions mInputs;
//
// Private ...
private:
//
// Props ...
//
// Tools ...
};
+398
View File
@@ -0,0 +1,398 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCAccount
// Description: provides all Account requirements ...
//
//
// 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
//
// START Definitions ...
//
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include <Trade/AccountInfo.mqh>
#include "../Classes/x-saherelm.base.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Manage Account ...
class XSCAccount : public XSCBase
{
//
// Public ...
public:
//
// Constructor ...
void XSCAccount()
{
//
mAccountInfo = new CAccountInfo();
}
//
// Deconstructor ...
void ~XSCAccount()
{
}
//
// START Provided Functions ...
//
//
// User Account ...
long GetUserAccount()
{
return mAccountInfo.Login();
}
//
// Account Leverage ...
long GetLeverage()
{
return mAccountInfo.Leverage();
}
//
// Get Trade Expert State ...
bool CanExpertTrade()
{
return mAccountInfo.TradeExpert();
}
//
// User Account Trade Mopde (ENUM_ACCOUNT_TRADE_MODE) ...
// --------------------------
// ACCOUNT_TRADE_MODE_DEMO
// ACCOUNT_TRADE_MODE_CONTEST
// ACCOUNT_TRADE_MODE_REAL
ENUM_ACCOUNT_TRADE_MODE GetTradeMode()
{
return mAccountInfo.TradeMode();
}
//
// Get Account Balance ...
double GetBalance()
{
return mAccountInfo.Balance();
}
//
// Get the amount of give Credit ...
double GetCredit()
{
return mAccountInfo.Credit();
}
//
// Get the amount of current Profit on account ...
double GetProfit()
{
return mAccountInfo.Profit();
}
//
// Get the amount of current Equity on account ...
double GetEquity()
{
return mAccountInfo.Equity();
}
//
// Get the amount of reserved Margin ...
double GetMargin()
{
return mAccountInfo.Margin();
}
//
// Get the amount of free Margin ...
double GetFreeMargin()
{
return mAccountInfo.FreeMargin();
}
//
// Get the Level of Margin ...
double GetMarginLevel()
{
return mAccountInfo.MarginLevel();
}
//
// Get the Level Of Margin for a Deposit ...
double GetMarginCall()
{
return mAccountInfo.MarginCall();
}
//
// Get the Level of Margin for Stop out ...
double GetMarginStopOut()
{
return mAccountInfo.MarginStopOut();
}
//
// Get the Client Name ...
string GetName()
{
return mAccountInfo.Name();
}
//
// Get the Trade Server Name ...
string GetServerName()
{
return mAccountInfo.Server();
}
//
// Get deposit Currency Name ...
string GetCurrency()
{
return mAccountInfo.Currency();
}
//
// Get the Company Name that serves an Account ...
string GetCompany()
{
return mAccountInfo.Company();
}
//
// Calculate Profits for the current account based on passed parameters ...
double CalculateTradeProfit(
const string symbol, // trading symbol
ENUM_ORDER_TYPE type, // order type
double volume, // volume
double entry, // open price
double exit // close price
)
{
//
double result = mAccountInfo.OrderProfitCheck(
symbol,
type,
volume,
entry,
exit);
//
return result;
}
//
// Calculate amount of margin which required for trade operation ...
double CalculateMarging(
const string symbol, // trading symbol
ENUM_ORDER_TYPE type, // order type
double volume, // volume
double entry // open price
)
{
//
double result = mAccountInfo.MarginCheck(
symbol,
type,
volume,
entry);
//
return result;
}
//
// Calculate amount of free margin left after trade operation ...
double CalculateFreeMarging(
const string symbol, // trading symbol
ENUM_ORDER_TYPE type, // order type
double volume, // volume
double entry // open price
)
{
//
double result = mAccountInfo.FreeMarginCheck(
symbol,
type,
volume,
entry);
//
return result;
}
//
// Calculate the Maximum possible volume of trade operation ...
double CalculateMaxVolume(
const string symbol, // trading symbol
ENUM_ORDER_TYPE type, // order type
double entry, // open price
double percent = 100 // percent of available margin
)
{
//
double result = mAccountInfo.MaxLotCheck(
symbol,
type,
entry,
percent);
//
return result;
}
//
// Calculate Point Value for Given Symbol based on Account ...
double GetPointValue(
string symbol // trading symbol
)
{
//
double result = 0;
//
double tickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
double tickValue = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE);
double point = SymbolInfoDouble(symbol, SYMBOL_POINT);
//
double ticksPerPoint = tickSize / point;
//
result = tickValue / ticksPerPoint;
//
return result;
}
//
// Calculate Risk Amount based on account Currency by Providing:
// Points and Volume ...
double CalculateRiskAmount(
string symbol, // trading symbol
double points, // amount of Risk Points
double volume // position Volume
)
{
//
double result = 0;
//
double pointValue = GetPointValue(symbol);
//
result = pointValue * volume * points;
//
return result;
}
//
// Calculate Risk Points based on account Currency by Providing:
// Volume and Amount ...
double CalculateRiskPoints(
string symbol, // trading symbol
double volume, // position Volume
double amount // amount of Risk based on Account Currency
)
{
//
double result = 0;
//
double pointValue = GetPointValue(symbol);
//
result = amount / (pointValue * volume);
//
return result;
}
//
// Calculate Volume based on account Currency by Providing:
// Amount and Risk Points ...
double CalculateVolume(
string symbol, // trading symbol
double amount, // amount of Risk based on Account Currency
double points // amount of Risk Points
)
{
//
double result = 0;
//
points =
points <= 0
? 10
: points;
//
double pointValue = GetPointValue(symbol);
//
result = amount / (pointValue * points);
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Account Info ...
CAccountInfo mAccountInfo;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//
+264
View File
@@ -0,0 +1,264 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCBaseProvider
// Description: provides all Base Provider
// requirements ...
//
//
// 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
//
// Includes ...
#include "../Classes/x-saherelm.base.class.mq5"
#include "../Libraries/x-saherelm.xtrade.lib.mq5"
//
// Definitions ...
//
// Base Provider Inputs ...
class XSCBaseProviderInpts : public XSCBase
{
//
// Public ...
public:
//
// Validate Input ...
virtual bool IsValid();
//
// Cleanup ...
virtual void Clean();
//
// Default ...
virtual void Default();
//
// Max ...
virtual int Max();
};
//
// Base Market Conditions Class ...
class XSCBaseProviderMarketConditions : public XSCBase
{
//
// Public ...
public:
//
// Props ...
XOHCL bars[]; // Number of Bars ...
//
// Buffers ...
//
// Conditions ...
//
// Generate Score ...
virtual void GenerateScore(
double &bullishScore, // Bullish Score
double &bearishScore, // Bearish Score
const double multiplier = 1 // Score Multiplier
);
//
// Generate Summary ...
virtual string GenerateSummary(
const double multiplier = 1, // Score Multiplier
const bool ignoreFalseConditions = true // Ignore False Conditions
);
};
//
// Class ...
//
// Base Provider Class ...
class XSCBaseProvider : public XSCBase
{
//
// Public ...
public:
//
// Props ...
//
// Constructor ...
XSCBaseProvider(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period // Trading Period
)
{
//
// Initialize Cycle ...
mCycle.Init(
symbol,
period,
X_MARKET_CYCLE_UNKNOWN,
X_PERIOD_NOTHING,
period,
"HOST Period"
//
);
}
//
// Deconstructor ...
~XSCBaseProvider()
{
DeInit();
}
//
// Properties Gettr(s) / Setter(s) ...
//
// Inheritance ...
//
// Init all Requirements ...
virtual bool Init(XSCBaseProviderInpts &inputs)
{
//
mInputs = inputs;
//
bool result = false;
//
return result;
}
//
// Get Inputs ...
virtual void GetInputs(XSCBaseProviderInpts &inputs)
{
inputs = mInputs;
}
//
// Set Inputs and Reinitial ...
virtual bool setInputs(XSCBaseProviderInpts &inputs)
{
return Init(inputs);
}
//
// DeInit all Requirements ...
virtual void DeInit();
//
virtual bool GetMarketConditions(
XSCBaseProviderMarketConditions &conditions, // Market Conditions Result
int barIndex = 0 // Specified Bar Index
);
//
// Check Market For Signal ...
virtual bool HasSignal(
int barIndex,
XSignal &signal, // Hold's Signal if Exists ...
XSCBaseProviderMarketConditions &conditions // Hold's Market Conditions ...
);
//
// Functions ...
//
string GetSymbol()
{
return mCycle.symbol;
}
//
ENUM_TIMEFRAMES GetPeriod()
{
return mCycle.hostPeriod;
}
//
// Count Bars ...
int CountBars()
{
//
return mCycle
.CountBars();
}
//
// Check New Bar ...
bool IsNewBar()
{
//
return mCycle
.IsNewBar();
}
//
// Protected ...
protected:
//
// Props ...
//
XMarketCycle mCycle;
XSCBaseProviderInpts mInputs;
//
bool mWaitsUntilNewBar;
//
// Can Ignore Process ...
bool CanIgnoreProcess()
{
//
bool result = false;
//
result =
//
IsRunningOnTestMode()
? !IsNewBar()
: !IsNewBar() && mWaitsUntilNewBar
//
;
//
return result;
}
//
// Toggle Waititng Until New Candle ...
void ToggleWaitingUntilNewBar()
{
mWaitsUntilNewBar = !mWaitsUntilNewBar;
}
//
// Private ...
private:
//
// Props ...
//
// Tools ...
};
//
// Tools ...
File diff suppressed because it is too large Load Diff