Files
MQL5Data/Classes/x-saherelm.x5.provider.class.mq5
T

961 lines
19 KiB
Plaintext

///////////////////////////////////////////////////////
//
// 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 ...
XTSInputs tsInputs;
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 = tsInputs.IsValid();
if (!result)
{
return result;
}
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()
{
//
tsInputs.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()
{
//
tsInputs.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, tsInputs.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
{
//
// Public ...
public:
//
// Buffers ...
//
// XTS ...
double tsCurrents[];
double tsNearests[];
double tsMediests[];
double tsFarests[];
//
// XFI ...
double fis[];
//
// XTD ...
double tdBullishs[];
double tdBearishs[];
double tdSignals[];
//
// XLH ...
double lhHhs[];
double lhLls[];
double lhSignals[];
//
// XTM ...
double tms[];
//
// XAMA ...
double amas[];
//
// XOBD ...
double obds[];
//
// XRSI ...
double rsis[];
//
// XCHMA ...
double chmaScFasts[];
double chmaScSlows[];
double chmaMcFasts[];
double chmaMcSlows[];
double chmaLcFasts[];
double chmaLcSlows[];
double chmaHotStates[];
//
// XCHLH ...
double chlhScHHs[];
double chlhScLLs[];
double chlhMcHHs[];
double chlhMcLLs[];
double chlhLcHHs[];
double chlhLcLLs[];
double chlhHotStates[];
//
//
// Conditions ...
void Clear()
{
//
Clean(tsCurrents);
Clean(tsNearests);
Clean(tsMediests);
Clean(tsFarests);
Clean(fis);
Clean(tdBullishs);
Clean(tdBearishs);
Clean(tdSignals);
Clean(lhHhs);
Clean(lhLls);
Clean(lhSignals);
Clean(tms);
Clean(amas);
Clean(obds);
Clean(rsis);
Clean(chmaScFasts);
Clean(chmaScSlows);
Clean(chmaMcFasts);
Clean(chmaMcSlows);
Clean(chmaLcFasts);
Clean(chmaLcSlows);
Clean(chmaHotStates);
Clean(chlhScHHs);
Clean(chlhScLLs);
Clean(chlhMcHHs);
Clean(chlhMcLLs);
Clean(chlhLcHHs);
Clean(chlhLcLLs);
Clean(chlhHotStates);
}
//
// 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 XSCX5Provider : public XSCBaseProvider
{
//
// Public ...
public:
//
// Props ...
XSCXTSHelper *tsHelper;
XSCXFIHelper *fiHelper;
XSCXTDHelper *tdHelper;
XSCXLHHelper *lhHelper;
XSCXTMHelper *tmHelper;
XSCXCCHelper *ccHelper;
XSCXCTHelper *ctHelper;
XSCXOBDHelper *obdHelper;
XSCXRSIHelper *rsiHelper;
XSCXAMAHelper *amaHelper;
XSCXCHMAHelper *chmaHelper;
XSCXCHLHHelper *chlhHelper;
//
// Constructor ...
XSCX5Provider(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period // Trading PEriod
) : XSCBaseProvider(symbol, period)
{
//
tsHelper = new XSCXTSHelper();
fiHelper = new XSCXFIHelper();
tdHelper = new XSCXTDHelper();
lhHelper = new XSCXLHHelper();
tmHelper = new XSCXTMHelper();
ccHelper = new XSCXCCHelper();
ctHelper = new XSCXCTHelper();
obdHelper = new XSCXOBDHelper();
rsiHelper = new XSCXRSIHelper();
amaHelper = new XSCXAMAHelper();
chmaHelper = new XSCXCHMAHelper();
chlhHelper = new XSCXCHLHHelper();
//
mNumberOfItems = 5;
}
//
// 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;
//
string mSymbol = GetSymbol();
ENUM_TIMEFRAMES mPeriod = GetPeriod();
//
result = tsHelper
.Init(
mSymbol,
mPeriod,
mInputs.tsInputs
//
);
if (!result)
{
return result;
}
//
result = fiHelper
.Init(
mSymbol,
mPeriod,
mInputs.fiInputs
//
);
if (!result)
{
return result;
}
//
result = tdHelper
.Init(
mSymbol,
mPeriod,
mInputs.tdInputs
//
);
if (!result)
{
return result;
}
//
result = lhHelper
.Init(
mSymbol,
mPeriod,
mInputs.lhInputs
//
);
if (!result)
{
return result;
}
//
result = tmHelper
.Init(
mSymbol,
mPeriod,
mInputs.tmInputs
//
);
if (!result)
{
return result;
}
//
result = ccHelper
.Init(
mSymbol,
mPeriod,
mInputs.ccInputs
//
);
if (!result)
{
return result;
}
//
result = ctHelper
.Init(
mSymbol,
mPeriod,
mInputs.ctInputs
//
);
if (!result)
{
return result;
}
//
result = obdHelper
.Init(
mSymbol,
mPeriod,
mInputs.obdInputs
//
);
if (!result)
{
return result;
}
//
result = rsiHelper
.Init(
mSymbol,
mPeriod,
mInputs.rsiInputs
//
);
if (!result)
{
return result;
}
//
result = amaHelper
.Init(
mSymbol,
mPeriod,
mInputs.amaInputs
//
);
if (!result)
{
return result;
}
//
result = chmaHelper
.Init(
mSymbol,
mPeriod,
mInputs.chmaInputs
//
);
if (!result)
{
return result;
}
//
result = chlhHelper
.Init(
mSymbol,
mPeriod,
mInputs.chlhInputs
//
);
//
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 ...
//
virtual string GetTag()
{
//
string result = NULL;
//
result =
//
GetToken() +
"[" +
GetSymbol() +
"," +
ToString(GetPeriod()) +
"]"
//
;
//
return result;
}
//
virtual void GetMarketConditions(
X5MarketConditions &mConditions, // Market Conditions Result
int barIndex = 0 // Specified Bar Index
)
{
//
mConditions.Clear();
//
// XTM ...
tmHelper.CopyMain(
barIndex,
mNumberOfItems,
mConditions.tms);
//
// XAMA ...
amaHelper.CopyMain(
barIndex,
mNumberOfItems,
mConditions.amas);
//
// XFI ...
fiHelper.CopyMain(
barIndex,
mNumberOfItems,
mConditions.fis);
//
// XOBD ...
obdHelper.CopyMain(
barIndex,
mNumberOfItems,
mConditions.obds);
//
// XRSI ...
rsiHelper.CopyMain(
barIndex,
mNumberOfItems,
mConditions.rsis);
//
// XLH ...
//
// HH ...
lhHelper.CopyHH(
barIndex,
mNumberOfItems,
mConditions.lhHhs);
//
// LL ...
lhHelper.CopyLL(
barIndex,
mNumberOfItems,
mConditions.lhLls);
//
// Signal ...
lhHelper.CopySignal(
barIndex,
mNumberOfItems,
mConditions.lhSignals);
//
// XTD ...
//
// Bullish ...
tdHelper.CopyBullish(
barIndex,
mNumberOfItems,
mConditions.tdBullishs);
//
// Bearish ...
tdHelper.CopyBearish(
barIndex,
mNumberOfItems,
mConditions.tdBearishs);
//
// Signal ...
tdHelper.CopySignal(
barIndex,
mNumberOfItems,
mConditions.tdSignals);
//
// XTS ...
//
// Current ...
tsHelper.CopyCurrent(
barIndex,
mNumberOfItems,
mConditions.tsCurrents);
//
// Nearest ...
tsHelper.CopyNearest(
barIndex,
mNumberOfItems,
mConditions.tsNearests);
//
// Mediest ...
tsHelper.CopyMediest(
barIndex,
mNumberOfItems,
mConditions.tsMediests);
//
// Farest ...
tsHelper.CopyFarest(
barIndex,
mNumberOfItems,
mConditions.tsFarests);
//
// XCHMA ...
//
// Short ...
//
// Fast ...
chmaHelper.CopySCFast(
barIndex,
mNumberOfItems,
mConditions.chmaScFasts);
//
// Slow ...
chmaHelper.CopySCSlow(
barIndex,
mNumberOfItems,
mConditions.chmaScSlows);
//
// Medium ...
//
// Fast ...
chmaHelper.CopyMCFast(
barIndex,
mNumberOfItems,
mConditions.chmaMcFasts);
//
// Slow ...
chmaHelper.CopyMCSlow(
barIndex,
mNumberOfItems,
mConditions.chmaMcSlows);
//
// Long ...
//
// Fast ...
chmaHelper.CopyLCFast(
barIndex,
mNumberOfItems,
mConditions.chmaLcFasts);
//
// Slow ...
chmaHelper.CopyLCSlow(
barIndex,
mNumberOfItems,
mConditions.chmaLcSlows);
//
// Hot States ...
chmaHelper.CopyHotState(
barIndex,
mNumberOfItems,
mConditions.chmaHotStates);
//
// XCHLH ...
//
// Short ...
//
// HH ...
chlhHelper.CopySCHH(
barIndex,
mNumberOfItems,
mConditions.chlhScHHs);
//
// LL ...
chlhHelper.CopySCLL(
barIndex,
mNumberOfItems,
mConditions.chlhScLLs);
//
// Medium ...
//
// HH ...
chlhHelper.CopyMCHH(
barIndex,
mNumberOfItems,
mConditions.chlhMcHHs);
//
// LL ...
chlhHelper.CopyMCLL(
barIndex,
mNumberOfItems,
mConditions.chlhMcLLs);
//
// Long ...
//
// HH ...
chlhHelper.CopyLCHH(
barIndex,
mNumberOfItems,
mConditions.chlhLcHHs);
//
// LL ...
chlhHelper.CopyLCLL(
barIndex,
mNumberOfItems,
mConditions.chlhLcLLs);
//
// Hot State ...
chlhHelper.CopyHotState(
barIndex,
mNumberOfItems,
mConditions.chlhHotStates);
}
//
// Check Market For Signal ...
virtual bool HasSignal(
int barIndex,
XSignal &mSignal, // Hold's Signal if Exists ...
X5MarketConditions &mConditions // Hold's Market Conditions ...
)
{
//
bool result = false;
//
result = !CanIgnoreProcess();
if (!result)
{
return result;
}
//
GetMarketConditions(mConditions, barIndex);
//
if (result)
{
Print(GetToken() + ", " + GetTag() + ", Salam");
}
//
return result;
}
//
// Protected ...
protected:
//
X5ProviderInputs mInputs;
//
// Private ...
private:
//
// Props ...
int mNumberOfItems; // Number of Buffer Ites Read in Conditions ...
//
// Tools ...
};