Files

966 lines
23 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCX121Provider
// Description: X121 Signal 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
//
// START Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Classes/x-saherelm.xprovider.class.mq5"
#include "../Helpers/x-saherelm.x121.xcc.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xhk.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xtm.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xpv.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xama.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xmrb.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xche.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xich.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xtrnd.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xsslc.helper.class.mq5"
#include "../Helpers/x-saherelm.x121.xhull.helper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// Here we Have to Define an Input Structure Model
// for Provider Class to Handle Helpers Definitions ...
struct X121ProviderInputs
{
//
// XCC ...
// Candle Styling ...
XCCInputs xccConfig;
//
// XHK ...
// HikenAshi Candle Representing ...
XHKInputs xhkConfig;
//
// XTM ...
// Trend Magic ...
XTMInputs xtmConfig;
//
// XPV ...
// Peaks And Vales ...
XPVInputs xpvConfig;
//
// XAMA ...
// Adaptive Moving Average ...
XAMAInputs xamaConfig;
//
// XMRB ...
// Moving Average Ribbon ...
XMRBInputs xmrbConfig;
//
// XCHE ...
// Chandelier Exit Points ...
XCHEInputs xcheConfig;
//
// XICH ...
// Ichimopku Kinko Hyo ...
XICHInputs xichConfig;
//
// XTRND ...
// Trend Detector ...
XTRNDInputs xtrndConfig;
//
// XSSLC ...
// SSL Channel ...
XSSLCInputs xsslcConfig;
//
// XHULL ...
// Hull Trend Detection Channel ...
XHULLInputs xhullConfig;
};
//
// Model Market Sense based On Current Captured conditions ...
struct X121MarketConditions
{
//
// Commonly Used Info ...
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Check Current Market Condition has Signal or not ...
bool hasSignal;
//
// If has any Signal, Models it's related info here ...
XSignalInfo signal;
//
// INDICATORS Market Sense ...
//
// XCC ...
// there is not any Info provided here ...
//
// XHK ...
XHKInfo xhkInfo;
//
// XTM ...
XTMInfo xtmInfo;
//
// XPV ...
XPVInfo xpvInfo;
//
// XAMA ...
XAMAInfo xamaInfo;
//
// XMRB ...
XMRBInfo xmrbInfo;
//
// XCHE ...
XCHEInfo xcheInfo;
//
// XICH ...
XICHInfo xichInfo;
//
// XTRND ...
XTRNDInfo xtrndInfo;
//
// XSSLC ...
XSSLCInfo xsslcInfo;
//
// XHULL ...
XHULLInfo xhullInfo;
};
//
// Notified a Signal was Appears ...
typedef void (*TOnSignalConditions)(
X121MarketConditions &info);
//
// END Definitions ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Base Class for All of our EA's ...
class XSCX121Provider : public XSCEABaseProvider
{
//
// Public ...
public:
//
// Props ...
X121ProviderInputs providedConfig;
X121ProviderInputs currentConfig;
X121ProviderInputs cleanConfig;
//
// Indicator Helper Classes Instance ...
//
// XCC ...
XSCXCCHelper *mXCCHelper;
//
// XHK ...
XSCXHKHelper *mXHKHelper;
//
// XTM ...
XSCXTMHelper *mXTMHelper;
//
// XPV ...
XSCXPVHelper *mXPVHelper;
//
// XAMA ...
XSCXAMAHelper *mXAMAHelper;
//
// XMRB ...
XSCXMRBHelper *mXMRBHelper;
//
// XCHE ...
XSCXCHEHelper *mXCHEHelper;
//
// XICH ...
XSCXICHHelper *mXICHHelper;
//
// XTRND ...
XSCXTRNDHelper *mXTRNDHelper;
//
// XSSLC ...
XSCXSSLCHelper *mXSSLCHelper;
//
// XHULL ...
XSCXHULLHelper *mXHULLHelper;
//
// Define Helpers ...
//
// Constructor ...
void XSCX121Provider() : XSCEABaseProvider(_Symbol, _Period){};
void XSCX121Provider(
string symbol, // Trading Symbol ...
ENUM_TIMEFRAMES period // Trading Time Frame ...
) : XSCEABaseProvider(symbol, period)
{
//
// Prepare Default and Clean Config ...
// in this Config non of Indicators doesn't Draw anything on chart ...
X121ProviderInputs configs;
//
// XCC ...
// Candle Styling ...
configs.xccConfig.upColor = clrLime;
configs.xccConfig.downColor = clrRed;
configs.xccConfig.lineColor = clrLime;
configs.xccConfig.bearishColor = clrRed;
configs.xccConfig.bullishColor = clrLime;
configs.xccConfig.volumesColor = clrGreen;
configs.xccConfig.showCandles = true;
//
// XHK ...
// HikenAshi Candle Representing ...
configs.xhkConfig.drawCandles = false;
configs.xhkConfig.drawCandleLines = false;
//
// XTM ...
// Trend Magic ...
configs.xtmConfig.length = 35;
configs.xtmConfig.shift = 0;
configs.xtmConfig.method = MODE_SMA;
configs.xtmConfig.appliedTo = PRICE_LOW;
configs.xtmConfig.showLine = false;
//
// XPV ...
// Peaks And Vales ...
configs.xpvConfig.shortLength = 9;
configs.xpvConfig.mediumLength = 17;
configs.xpvConfig.longLength = 26;
configs.xpvConfig.hindLength = 35;
configs.xpvConfig.hhMode = MODE_HIGH;
configs.xpvConfig.llMode = MODE_LOW;
configs.xpvConfig.showPeaksAndVales = false;
configs.xpvConfig.showLevels = false;
//
// XAMA ...
// Adaptive Moving Average ...
configs.xamaConfig.length = 52;
configs.xamaConfig.fastEMA = 2;
configs.xamaConfig.slowEMA = 30;
configs.xamaConfig.maShift = 0;
configs.xamaConfig.appliedTo = PRICE_LOW;
configs.xamaConfig.showLine = false;
//
// XMRB ...
// Moving Average Ribbon ...
configs.xmrbConfig.fast1Length = 3;
configs.xmrbConfig.slow1Length = 5;
configs.xmrbConfig.fast2Length = 8;
configs.xmrbConfig.slow2Length = 13;
configs.xmrbConfig.fast3Length = 21;
configs.xmrbConfig.slow3Length = 34;
configs.xmrbConfig.fast4Length = 55;
configs.xmrbConfig.slow4Length = 89;
configs.xmrbConfig.fast5Length = 144;
configs.xmrbConfig.slow5Length = 233;
configs.xmrbConfig.ribbonMode = MODE_EMA;
configs.xmrbConfig.ribbonAppliedTo = PRICE_CLOSE;
configs.xmrbConfig.showFastMa = false;
configs.xmrbConfig.showSlowMa = false;
configs.xmrbConfig.showRibbon = false;
//
// XCHE ...
// Chandelier Exit Points ...
configs.xcheConfig.length = 35;
configs.xcheConfig.loopback = 26;
configs.xcheConfig.multiplier1 = 3;
configs.xcheConfig.multiplier2 = 3;
configs.xcheConfig.upAppliedTo = PRICE_HIGH;
configs.xcheConfig.downAppliedTo = PRICE_LOW;
configs.xcheConfig.showLongExit1Line = false;
configs.xcheConfig.showShortExit1Line = false;
configs.xcheConfig.showLongExit2Line = false;
configs.xcheConfig.showShortExit2Line = false;
//
// XICH ...
// Ichimopku Kinko Hyo ...
configs.xichConfig.tenkanSenLength = 9;
configs.xichConfig.tenkanSenMode = X_XICH_HH_LL_MODE;
configs.xichConfig.kijunSenLength = 26;
configs.xichConfig.kijunSenMode = X_XICH_HH_LL_MODE;
configs.xichConfig.senkouSpanBLength = 52;
configs.xichConfig.senkouSpanBMode = X_XICH_HH_LL_MODE;
configs.xichConfig.chikuoSpanAppliedTo = PRICE_CLOSE;
configs.xichConfig.showTenkanSen = false;
configs.xichConfig.showKijunSen = false;
configs.xichConfig.showKijunSenPlus = false;
configs.xichConfig.showKijunSenNegative = false;
configs.xichConfig.showChikouSpan = false;
configs.xichConfig.showSenkouSpanA = false;
configs.xichConfig.showSenkouSpanB = false;
configs.xichConfig.showKumo = false;
configs.xichConfig.shiftKumo = true;
//
// XTRND ...
// Trend Detector ...
configs.xtrndConfig.cycleLength = 2;
configs.xtrndConfig.numberOfVerifications = 2;
configs.xtrndConfig.hhMode = MODE_HIGH;
configs.xtrndConfig.llMode = MODE_LOW;
configs.xtrndConfig.l1Method = X_PERIOD_AUTO;
configs.xtrndConfig.l1Period = NULL;
configs.xtrndConfig.l2Method = X_PERIOD_AUTO;
configs.xtrndConfig.l2Period = NULL;
configs.xtrndConfig.l3Method = X_PERIOD_AUTO;
configs.xtrndConfig.l3Period = NULL;
configs.xtrndConfig.showConsolidations = false;
configs.xtrndConfig.showTrend = false;
configs.xtrndConfig.showL1Trend = false;
configs.xtrndConfig.showL2Trend = false;
configs.xtrndConfig.showL3Trend = false;
//
// XSSLC ...
// SSL Channel ...
configs.xsslcConfig.length = 36;
configs.xsslcConfig.method = MODE_SMA;
configs.xsslcConfig.upAppliedTo = PRICE_HIGH;
configs.xsslcConfig.downAppliedTo = PRICE_LOW;
configs.xsslcConfig.showUp = false;
configs.xsslcConfig.showDown = false;
//
// XHULL ...
// Hull Trend Detection Channel ...
configs.xhullConfig.length = 72;
configs.xhullConfig.divisor = 2;
configs.xhullConfig.upAppliedTo = PRICE_HIGH;
configs.xhullConfig.downAppliedTo = PRICE_LOW;
configs.xhullConfig.showUpZone = false;
configs.xhullConfig.showDownZone = false;
//
// Clean Config ...
cleanConfig = configs;
//
XSCX121Provider(symbol, period, configs);
}
void XSCX121Provider(
string symbol, // Trading Symbol ...
ENUM_TIMEFRAMES period, // Trading Time Frame ...
X121ProviderInputs &config // Configs ...
)
{
//
mTag = "X121Provider|" + mSymbol + "," + ToString(mPeriod);
// //
// mCTimerHandler = iCustom(
// mSymbol,
// mPeriod,
// "x-saherelm.x121.xct",
// //
// // Inputs ...
// clrYellow,
// CORNER_RIGHT_LOWER,
// true
// //
// );
//
currentConfig = config;
providedConfig = config;
//
// Here we Have to Make Provided Config in Clean Style ...
PrepareCleanConfig();
}
//
// Deconstructor ...
void ~XSCX121Provider()
{
//
IndicatorRelease(mCTimerHandler);
//
// De construct Helpers ...
delete mXCCHelper;
delete mXHKHelper;
delete mXTMHelper;
delete mXPVHelper;
delete mXAMAHelper;
delete mXMRBHelper;
delete mXCHEHelper;
delete mXICHHelper;
delete mXTRNDHelper;
delete mXSSLCHelper;
delete mXHULLHelper;
}
//
bool Init()
{
//
bool result = false;
//
// Instantiate all Indicators Helper Classes ...
//
// // XCC ...
// mXCCHelper = new XSCXCCHelper(
// mSymbol,
// mPeriod,
// currentConfig.xccConfig);
// result = mXCCHelper.Init();
// if (!result)
// {
// return result;
// }
// //
// // XHK ...
// mXHKHelper = new XSCXHKHelper(
// mSymbol,
// mPeriod,
// currentConfig.xhkConfig);
// result = mXHKHelper.Init();
// if (!result)
// {
// return result;
// };
//
// XTM ...
// mXTMHelper = new XSCXTMHelper(
// mSymbol,
// mPeriod,
// currentConfig.xtmConfig);
// result = mXTMHelper.Init();
// if (!result)
// {
// return result;
// };
// //
// // XPV ...
// mXPVHelper = new XSCXPVHelper(
// mSymbol,
// mPeriod,
// currentConfig.xpvConfig);
// result = mXPVHelper.Init();
// if (!result)
// {
// LogMessage("XPV Error: ");
// return result;
// };
// //
// // XAMA ...
// mXAMAHelper = new XSCXAMAHelper(
// mSymbol,
// mPeriod,
// currentConfig.xamaConfig);
// result = mXAMAHelper.Init();
// if (!result)
// {
// return result;
// };
// //
// // XMRB ...
// mXMRBHelper = new XSCXMRBHelper(
// mSymbol,
// mPeriod,
// currentConfig.xmrbConfig);
// result = mXMRBHelper.Init();
// if (!result)
// {
// return result;
// };
// //
// // XCHE ...
// mXCHEHelper = new XSCXCHEHelper(
// mSymbol,
// mPeriod,
// currentConfig.xcheConfig);
// result = mXCHEHelper.Init();
// if (!result)
// {
// return result;
// };
// //
// // XICH ...
// mXICHHelper = new XSCXICHHelper(
// mSymbol,
// mPeriod,
// currentConfig.xichConfig);
// result = mXICHHelper.Init();
// if (!result)
// {
// return result;
// };
// //
// // XTRND ...
// mXTRNDHelper = new XSCXTRNDHelper(
// mSymbol,
// mPeriod,
// currentConfig.xtrndConfig);
// result = mXTRNDHelper.Init();
// if (!result)
// {
// return result;
// };
// //
// // XSSLC ...
// mXSSLCHelper = new XSCXSSLCHelper(
// mSymbol,
// mPeriod,
// currentConfig.xsslcConfig);
// result = mXSSLCHelper.Init();
// if (!result)
// {
// return result;
// };
// //
// // XHULL ...
// mXHULLHelper = new XSCXHULLHelper(
// mSymbol,
// mPeriod,
// currentConfig.xhullConfig);
// result = mXHULLHelper.Init();
// if (!result)
// {
// return result;
// };
//
return result;
}
//
virtual void ProcessBuffers()
{
}
//
virtual void ProcessTick()
{
ProcessSignals();
}
//
// Generate Market Sense ...
X121MarketConditions GetMarketConditions(
int barIndex // Specified Bar Index
)
{
//
X121MarketConditions result;
//
// Fill Common Data ...
result.symbol = mSymbol;
result.period = mPeriod;
result.barIndex = barIndex;
//
datetime barTime = GetCandleTime(
mSymbol,
mPeriod,
barIndex);
result.barTime = barTime;
//
result.xhkInfo = mXHKHelper.GetInfo(barIndex);
result.xtmInfo = mXTMHelper.GetInfo(barIndex);
result.xpvInfo = mXPVHelper.GetInfo(barIndex);
result.xamaInfo = mXAMAHelper.GetInfo(barIndex);
result.xmrbInfo = mXMRBHelper.GetInfo(barIndex);
result.xcheInfo = mXCHEHelper.GetInfo(barIndex);
result.xichInfo = mXICHHelper.GetInfo(barIndex);
result.xtrndInfo = mXTRNDHelper.GetInfo(barIndex);
result.xsslcInfo = mXSSLCHelper.GetInfo(barIndex);
result.xhullInfo = mXHULLHelper.GetInfo(barIndex);
//
return result;
}
//
// Add Specific On SignalConditions Event Handler ...
int AddOnSignalConditionEventHandler(TOnSignalConditions handler)
{
//
ArrayResize(
mSignalConditionsEventHandlers,
ArraySize(mSignalConditionsEventHandlers) + 1);
//
int result = ArraySize(mSignalConditionsEventHandlers) - 1;
mSignalConditionsEventHandlers[result] = handler;
//
return result;
}
//
// Remove All On Signal Event Handler ...
void ReoveOnSignalEventHandlers()
{
//
ArrayFree(mSignalConditionsEventHandlers);
}
//
// Notify a Signal Found on all Event Listeners ...
void NotifyOnSignalConditionsEvent(X121MarketConditions &info)
{
//
int listenerCount = ArraySize(mSignalConditionsEventHandlers);
if (listenerCount <= 0)
{
return;
}
//
// Loop Through Listeners ...
for (int i = 0; i < listenerCount; i++)
{
//
TOnSignalConditions listener = mSignalConditionsEventHandlers[i];
//
listener(info);
}
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// CCandle Timer ...
int mCTimerHandler;
//
// Signal Event Handlers ...
TOnSignalConditions mSignalConditionsEventHandlers[];
//
// Make Provided Config in Clean Style ...
void PrepareCleanConfig()
{
//
cleanConfig = providedConfig;
//
// XCC ...
// Candle Styling ...
cleanConfig.xccConfig.showCandles = true;
//
// XHK ...
// HikenAshi Candle Representing ...
cleanConfig.xhkConfig.drawCandles = false;
cleanConfig.xhkConfig.drawCandleLines = false;
//
// XTM ...
// Trend Magic ...
cleanConfig.xtmConfig.showLine = false;
//
// XPV ...
// Peaks And Vales ...
cleanConfig.xpvConfig.showPeaksAndVales = false;
cleanConfig.xpvConfig.showLevels = false;
//
// XAMA ...
// Adaptive Moving Average ...
cleanConfig.xamaConfig.showLine = false;
//
// XMRB ...
// Moving Average Ribbon ...
cleanConfig.xmrbConfig.showFastMa = false;
cleanConfig.xmrbConfig.showSlowMa = false;
cleanConfig.xmrbConfig.showRibbon = false;
//
// XCHE ...
// Chandelier Exit Points ...
cleanConfig.xcheConfig.showLongExit1Line = false;
cleanConfig.xcheConfig.showShortExit1Line = false;
cleanConfig.xcheConfig.showLongExit2Line = false;
cleanConfig.xcheConfig.showShortExit2Line = false;
//
// XICH ...
// Ichimopku Kinko Hyo ...
cleanConfig.xichConfig.showTenkanSen = false;
cleanConfig.xichConfig.showKijunSen = false;
cleanConfig.xichConfig.showKijunSenPlus = false;
cleanConfig.xichConfig.showKijunSenNegative = false;
cleanConfig.xichConfig.showChikouSpan = false;
cleanConfig.xichConfig.showSenkouSpanA = false;
cleanConfig.xichConfig.showSenkouSpanB = false;
cleanConfig.xichConfig.showKumo = false;
//
// XTRND ...
// Trend Detector ...
cleanConfig.xtrndConfig.showConsolidations = false;
cleanConfig.xtrndConfig.showTrend = false;
cleanConfig.xtrndConfig.showL1Trend = false;
cleanConfig.xtrndConfig.showL2Trend = false;
cleanConfig.xtrndConfig.showL3Trend = false;
//
// XSSLC ...
// SSL Channel ...
cleanConfig.xsslcConfig.showUp = false;
cleanConfig.xsslcConfig.showDown = false;
//
// XHULL ...
// Hull Trend Detection Channel ...
cleanConfig.xhullConfig.showUpZone = false;
cleanConfig.xhullConfig.showDownZone = false;
}
//
// Here we are Capture Conditions and Check Signals ...
// The Signals Must be Unique for each providers ...
void ProcessSignals()
{
//
X121MarketConditions conditions = GetMarketConditions(1);
//
// BUY ...
//
Clean(conditions.signal);
bool hasLongSignal = HasLongSignal(conditions);
if (hasLongSignal)
{
//
NotifyOnSignalEvent(
conditions.signal);
NotifyOnSignalConditionsEvent(conditions);
mWaitUntilNewCandle = true;
return;
}
//
// SELL ...
//
Clean(conditions.signal);
bool hasShortignal = HasShortSignal(conditions);
if (hasShortignal)
{
//
NotifyOnSignalEvent(
conditions.signal);
NotifyOnSignalConditionsEvent(conditions);
mWaitUntilNewCandle = true;
return;
}
}
//
// Check has Long Signal on Each Strategies ...
bool HasLongSignal(X121MarketConditions &conditions)
{
//
bool result = false;
//
if (result)
{
}
//
return result;
}
//
// Check has Short Signal on Each Strategies ...
bool HasShortSignal(X121MarketConditions &conditions)
{
//
bool result = false;
//
if (result)
{
}
//
return result;
}
};
//
// START Definitions ...
//
//
// Model Signal Providers Definitions ...
struct X121SignalProvider
{
//
// Provider use Which Symbol ...
string symbol;
//
// Provider use Which Time Frame ...
ENUM_TIMEFRAMES period;
//
// Risk Amount Per Trades Related to Time Frames ...
// Percent of Available Balance ...
double riskAmount;
//
// Desired Magic Number ...
ulong magicNumber;
//
// Provider ...
XSCX121Provider provider;
};
//
// END Definitions ...
//
//
// START Usefull Functions ...
//
//
// Add Specific Provider to List ...
void Add(
X121SignalProvider &item, // item want to add
X121SignalProvider &buffer[] // Destination buffer
)
{
//
ArrayResize(
buffer,
ArraySize(buffer) + 1);
//
buffer[ArraySize(buffer) - 1] = item;
}
//
// Generate Identifier Tag ...
string GenerateTag(X121SignalProvider &descriptor)
{
//
string result = "";
//
result = descriptor.symbol + "," + ToString(descriptor.period);
//
return result;
}
//
// END Usefull Functions ...
//