422 lines
9.2 KiB
Plaintext
422 lines
9.2 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Class Library
|
|
// --------------------------------------
|
|
// Name: XC121SMCExpert
|
|
// Description: provides all based classes for use ...
|
|
//
|
|
//
|
|
// 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.xexpert.class.mq5"
|
|
#include "../Strategy/x-121.smc.ob.strategy.class.mq5"
|
|
#include "../Strategy/x-121.smc.supdem.strategy.class.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
string XC121SMCExpertToken = "XC121SMCEA";
|
|
|
|
//
|
|
// Implementation ...
|
|
|
|
class XC121SMCExpert : public XCBaseExpert
|
|
{
|
|
//
|
|
public:
|
|
//
|
|
|
|
//
|
|
// Override Actions ...
|
|
|
|
/**
|
|
* Apply Default Configurations ...
|
|
*/
|
|
void DefaultConfigure() override
|
|
{
|
|
//
|
|
// Commons ...
|
|
Slippage(10);
|
|
TagPrefix("");
|
|
MagicNumber(1694056);
|
|
|
|
//
|
|
// Symbol ...
|
|
SetSymbol(_Symbol);
|
|
SetPeriod(_Period);
|
|
MultiSymbol(false);
|
|
Symbols("EURUSDb,GBPUSDb,USDJPYb,USDCHFb,DowJones30,XAUUSDb");
|
|
|
|
//
|
|
// Signalling ...
|
|
Disabled(false);
|
|
AllowLomg(true);
|
|
AllowShort(true);
|
|
|
|
//
|
|
string tag = GetTag();
|
|
|
|
//
|
|
// Alert ...
|
|
SetAlertPrefix(tag);
|
|
SetAlertLogAlerts(true);
|
|
SetAlertPushAlerts(true);
|
|
SetAlertMailAlerts(false);
|
|
SetAlertEnableAlerts(true);
|
|
SetAlertTerminalAlerts(false);
|
|
|
|
//
|
|
// Reports ...
|
|
ReportNewDays(true);
|
|
ReportNewWeeks(false);
|
|
ReportNewHours(false);
|
|
ReportNewMonths(false);
|
|
}
|
|
|
|
/**
|
|
* Vaslidate Inputs ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool ValidateInputs() override
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
string errMessage = "";
|
|
|
|
//
|
|
bool isCommonValid = (
|
|
//
|
|
Slippage() > 0 &&
|
|
MagicNumber() > 0
|
|
//
|
|
);
|
|
if (!isCommonValid)
|
|
{
|
|
//
|
|
errMessage += "common configurations error;" + "\n";
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
// Common ...
|
|
isCommonValid &&
|
|
//
|
|
// Otere ...
|
|
true
|
|
//
|
|
;
|
|
|
|
//
|
|
if (!result)
|
|
{
|
|
//
|
|
// Since here Logger not Initiallized, we Use Raw Print Command ...
|
|
errMessage = " Errors: \n" + errMessage;
|
|
Alert(errMessage);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Initializers and DeInitializers ...
|
|
|
|
/**
|
|
* Initial EA Requirements ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool InitEA() override
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Initialize Indicator Helpers ...
|
|
|
|
//
|
|
// Bar Timer ...
|
|
XCTInputs ctInputs;
|
|
ctInputs.Default(); // Default Configurations ...
|
|
mCTHelper = new XSCXCTHelper();
|
|
result = mCTHelper.Init(
|
|
GetSymbol(),
|
|
GetPeriod(),
|
|
ctInputs //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Bar Styles ...
|
|
XCCInputs ccInputs;
|
|
ccInputs.Default(); // Default Configurations ...
|
|
mCCHelper = new XSCXCCHelper();
|
|
result = mCCHelper.Init(
|
|
GetSymbol(),
|
|
GetPeriod(),
|
|
ccInputs //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Create Trader Instance and Configure it ...
|
|
mTrader = new XSCTrade(
|
|
Slippage(),
|
|
MagicNumber() //
|
|
);
|
|
|
|
//
|
|
// Parsers ...
|
|
XSymbolParser _symbolParser;
|
|
|
|
//
|
|
// Single Symbol ...
|
|
if (!MultiSymbol())
|
|
{
|
|
//
|
|
// Register Strategy ...
|
|
|
|
//
|
|
// Create Class Instance ...
|
|
XCX121SMCBaseStrategy *iX121SMCStrategy;
|
|
iX121SMCStrategy = new XCX121SMCOBStrategy(
|
|
_Symbol,
|
|
_Period //
|
|
);
|
|
|
|
//
|
|
iX121SMCStrategy.AddXSignalEventHandler(OnSignalRecieved);
|
|
|
|
//
|
|
ConfigureStrategy(iX121SMCStrategy);
|
|
RegisterStrategy(iX121SMCStrategy);
|
|
}
|
|
//
|
|
// Multi Symbol ...
|
|
else
|
|
{
|
|
//
|
|
// Parse Symbols ...
|
|
string symbols[];
|
|
int symbolsCount = SplitContent(
|
|
symbols,
|
|
eaSymbols //
|
|
);
|
|
result = IsValidSize(symbolsCount);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
for (int i = 0; i < symbolsCount; i++)
|
|
{
|
|
//
|
|
// Select Symbol ...
|
|
string iSymbol = symbols[i];
|
|
|
|
//
|
|
// Register Strategy Based On Symbol ...
|
|
|
|
//
|
|
// Parse Symbol ...
|
|
bool isEURUSD = _symbolParser.IsEURUSD(_Symbol);
|
|
bool isGBPUSD = _symbolParser.IsGBPUSD(_Symbol);
|
|
bool isEURGBP = _symbolParser.IsEURGBP(_Symbol);
|
|
bool isUSDCHF = _symbolParser.IsUSDCHF(_Symbol);
|
|
bool isEURCHF = _symbolParser.IsEURCHF(_Symbol);
|
|
bool isUSDJPY = _symbolParser.IsUSDJPY(_Symbol);
|
|
bool isEURJPY = _symbolParser.IsEURJPY(_Symbol);
|
|
bool isUSDCAD = _symbolParser.IsUSDCAD(_Symbol);
|
|
bool isEURCAD = _symbolParser.IsEURCAD(_Symbol);
|
|
bool isAUDUSD = _symbolParser.IsAUDUSD(_Symbol);
|
|
bool isEURAUD = _symbolParser.IsEURAUD(_Symbol);
|
|
bool isNZDUSD = _symbolParser.IsNZDUSD(_Symbol);
|
|
bool isEURNZD = _symbolParser.IsEURNZD(_Symbol);
|
|
|
|
//
|
|
// Check Symbol Can Register or not ...
|
|
bool canRegisterStrategy = true;
|
|
|
|
//
|
|
if (canRegisterStrategy)
|
|
{
|
|
//
|
|
// Create Class Instance ...
|
|
XCX121SMCBaseStrategy *iX121SMCStrategy;
|
|
iX121SMCStrategy = new XCX121SMCOBStrategy(
|
|
iSymbol,
|
|
_Period //
|
|
);
|
|
|
|
//
|
|
iX121SMCStrategy.AddXSignalEventHandler(OnSignalRecieved);
|
|
|
|
//
|
|
// Register Strategy ...
|
|
ConfigureStrategy(iX121SMCStrategy);
|
|
RegisterStrategy(iX121SMCStrategy);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
|
|
/**
|
|
* Generate Identifier Tag ...
|
|
*
|
|
* @return ( string )
|
|
*/
|
|
string GetTag() override
|
|
{
|
|
//
|
|
string result = NULL;
|
|
|
|
//
|
|
string tagPrefix = TagPrefix();
|
|
if (IsValid(tagPrefix))
|
|
{
|
|
result = tagPrefix;
|
|
}
|
|
else
|
|
{
|
|
result = "";
|
|
}
|
|
|
|
//
|
|
result =
|
|
XCBaseExpertToken + result;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
protected:
|
|
//
|
|
|
|
//
|
|
// Props ...
|
|
XCX121SMCBaseStrategy *mStrategies[]; // Registere Strategies in EA ...
|
|
|
|
//
|
|
// Actions ...
|
|
|
|
/**
|
|
* Configure Startegy ...
|
|
*/
|
|
void ConfigureStrategy(XCX121SMCBaseStrategy *&strategy)
|
|
{
|
|
//
|
|
if (strategy == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Configure Alerts ...
|
|
strategy.SetAlertPrefix(GetTag());
|
|
strategy.SetAlertLogAlerts(GetAlertLogAlerts());
|
|
strategy.SetAlertMailAlerts(GetAlertMailAlerts());
|
|
strategy.SetAlertPushAlerts(GetAlertPushAlerts());
|
|
strategy.SetAlertEnableAlerts(GetAlertEnableAlerts());
|
|
strategy.SetAlertTerminalAlerts(GetAlertTerminalAlerts());
|
|
|
|
//
|
|
// Confiugre Signalling ...
|
|
|
|
//
|
|
strategy.AllowLong(AllowLomg());
|
|
strategy.AllowShort(AllowShort());
|
|
|
|
//
|
|
if (Disabled())
|
|
{
|
|
strategy.Disable();
|
|
}
|
|
else
|
|
{
|
|
strategy.Enable();
|
|
}
|
|
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Register an Strategy in EA ...
|
|
*
|
|
* @param strategy: XCX121SMCBaseStrategy instance ...
|
|
*/
|
|
void RegisterStrategy(XCX121SMCBaseStrategy *strategy)
|
|
{
|
|
//
|
|
if (strategy == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
ArrayResize(
|
|
mStrategies,
|
|
ArraySize(mStrategies) + 1 //
|
|
);
|
|
|
|
//
|
|
mStrategies[ArraySize(mStrategies) - 1] = strategy;
|
|
}
|
|
|
|
/**
|
|
* Re Configure All Registered Strategies ...
|
|
*/
|
|
void ReConfigureAllStrategies()
|
|
{
|
|
//
|
|
int count = ArraySize(eaStrategies);
|
|
if (!IsValidSize(count))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
ConfigureStrategy(eaStrategies[i]);
|
|
}
|
|
}
|
|
|
|
//
|
|
private:
|
|
//
|
|
|
|
//
|
|
};
|
|
|
|
// |