This commit is contained in:
2024-06-11 09:42:31 +03:30
parent aef558f9dc
commit 53cfae7f99
3 changed files with 571 additions and 22 deletions
@@ -0,0 +1,342 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCX121SetupCycle
// Description: provides implementation of X121
// Setup on Specified Market Cycle ...
//
//
// 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.x121.setup.class.mq5"
//
// Definitions ...
//
// Inputs ...
struct X121SetupCycleInputs
{
//
// Props ...
//
XMarketCycle cycle; // Market Cycle
//
X121SetupInputs inputs; // Inputs
//
XSCX121Setup *setup; // Setup
//
// Constructor ...
void X121SetupCycleInputs()
{
}
//
// Initialization ...
bool Init(
X121SetupInputs &_inputs, // Configurations
ENUM_TIMEFRAMES _hostPeriod, // Host Period
ENUM_X_MARKET_CYCLES _cycle, // Init Cycle
ENUM_X_PERIOD_METHOD _method, // Period Selection Method
ENUM_TIMEFRAMES _period, // Provided Period
string _prefix = "" // Prefix
)
{
//
bool result = false;
//
// Validate Inputs ...
result =
//
IsValid(_inputs.symbol)
//
;
if (!result)
{
return result;
}
//
// Init Cycle ...
result = cycle.Init(
inputs.symbol,
_hostPeriod,
_cycle,
_method,
_period,
_prefix //
);
if (!result)
{
return result;
}
//
cycle.Update(0);
//
_inputs.period = cycle.period;
//
result = _inputs.IsValid();
if (!result)
{
return result;
}
//
this.inputs = _inputs;
//
setup = new XSCX121Setup();
result = setup.Init(
inputs //
);
//
return result;
}
//
// Tools ...
//
string GetSymbol()
{
return inputs.symbol;
}
//
ENUM_TIMEFRAMES GetPeriod()
{
return inputs.period;
}
//
bool GetConsitions(
X121SetupConditions &conditions, //
int barIndex = 0, //
int loopback = 5 //
)
{
//
bool result = false;
//
result = cycle.Update(
barIndex //
);
//
result = setup.GetConditions(
conditions,
barIndex,
loopback //
);
//
return result;
}
};
//
// Class ...
class XSCX121SetupCycles : public XSCBaseAlert
{
//
// Public ...
public:
//
// Props ...
//
// Constructor(s) ...
void XSCX121SetupCycles() {}
//
// Deconstructor ...
void ~XSCX121SetupCycles() {}
//
// Initialized ...
bool Init(
X121SetupInputs &_inputs, // Configurations
string _symbol, // Trading Symbol
ENUM_TIMEFRAMES _hostPeriod, // Host Period
ENUM_X_PERIOD_METHOD _sMethod = X_PERIOD_AUTO, // Short Period Selection Method
ENUM_TIMEFRAMES _sPeriod = NULL, // Short Provided Period
ENUM_X_PERIOD_METHOD _mMethod = X_PERIOD_AUTO, // Medium Period Selection Method
ENUM_TIMEFRAMES _mPeriod = NULL, // Medium Provided Period
ENUM_X_PERIOD_METHOD _lMethod = X_PERIOD_AUTO, // Long Period Selection Method
ENUM_TIMEFRAMES _lPeriod = NULL, // Long Provided Period
ENUM_X_PERIOD_METHOD _hMethod = X_PERIOD_AUTO, // Hind Period Selection Method
ENUM_TIMEFRAMES _hPeriod = NULL // Hind Provided Period
)
{
//
bool result = false;
//
// Check Validation of Symbol and Period ...
result =
//
IsValid(_symbol) &&
IsValid(_hostPeriod)
//
;
if (!result)
{
return result;
}
//
// Initialize Market Cycles ...
//
// Current ...
_inputs.symbol = _symbol;
result = cCycle.Init(
_inputs,
_hostPeriod,
X_MARKET_CYCLE_SHORT,
X_PERIOD_MANUALLY,
_hostPeriod,
"CURR" //
);
if (!result)
{
return result;
}
//
// Short ...
result = sCycle.Init(
_inputs,
_hostPeriod,
X_MARKET_CYCLE_SHORT,
_sMethod,
_sPeriod //
);
if (!result)
{
return result;
}
//
// Medium ...
result = mCycle.Init(
_inputs,
_hostPeriod,
X_MARKET_CYCLE_MEDIUM,
_mMethod,
_mPeriod //
);
if (!result)
{
return result;
}
//
// Long ...
result = lCycle.Init(
_inputs,
_hostPeriod,
X_MARKET_CYCLE_LONG,
_lMethod,
_lPeriod //
);
if (!result)
{
return result;
}
//
// Hind ...
result = hCycle.Init(
_inputs,
_hostPeriod,
X_MARKET_CYCLE_HIND,
_hMethod,
_hPeriod //
);
if (!result)
{
return result;
}
//
_inputs.period = cCycle.GetPeriod();
//
this.inputs = _inputs;
result = inputs.IsValid();
//
return result;
}
//
// Getter(s) / Setter(s) ...
//
X121SetupInputs GetInputs()
{
return this.inputs;
}
//
bool SetInputs(
X121SetupInputs &_inputs // Cycles Configurations
)
{
//
bool result = Init(
_inputs,
_inputs.symbol,
_inputs.period //
);
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
//
X121SetupInputs inputs; // Cycles Configurations
//
X121SetupCycleInputs cCycle; // Current (Host) Cycle
X121SetupCycleInputs sCycle; // Short Cycle
X121SetupCycleInputs mCycle; // Medium Cycle
X121SetupCycleInputs lCycle; // Long Cycle
X121SetupCycleInputs hCycle; // Hind Cycle
}
+220
View File
@@ -0,0 +1,220 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCX121SetupCycle
// Description: provides implementation of X121
// Setup on Specified Market Cycle ...
//
//
// 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.setup.class.mq5"
//
// Definitions ...
//
// Class ...
class XSCX121SetupEA : public XSCBaseEA
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCX121SetupEA(
//
// XTrade Class Requirements ...
int slippage, // Specify Slippage
ulong magicNumber, // Specify Magic Number
//
// XSCTrade 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
) : XSCBaseEA(slippage,
magicNumber,
onStopLossTriggered,
onTakeProfitTriggered,
onDealsChangedHandler,
onOrdersChangedHandler,
onPositionsChangedHandler,
onTradeStateChangedHandler //
)
{
//
}
//
// Deconstructor ...
~XSCX121SetupEA()
{
}
//
// Overrides ...
//
// Customize Token ...
string GetToken() override
{
return GetSpecificToken(this);
}
//
string GetTag() override
{
return this.GetToken();
}
//
// Check Provider for any Guards ...
bool CheckForGuard(XGuard &guards[]) override
{
//
bool result = false;
//
return result;
}
//
// 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);
//
// IMPLEMENT ...
//
result = ArraySize(signals);
//
return result;
}
//
// Here we Manage Signals for Executing ...
// - Check Policies based on their Signaller ...
// - Check Same Time Open Positions ...
// - Check Signal Age for new Trade ...
// and etc ...
int HandleSignalManagement(XSignal &signals[]) override
{
//
int result = 0;
//
int signalsCount = ArraySize(signals);
if (!IsValidSize(signalsCount))
{
return result;
}
//
XSignal tmpSignals[];
Copy(
signals,
tmpSignals //
);
//
Clean(signals);
//
for (int i = 0; i < signalsCount; i++)
{
//
XSignal iSignal = tmpSignals[i];
//
AddRef(
iSignal,
signals //
);
}
//
result = ArraySize(signals);
//
return result;
}
//
// Handle State Management ....
// here we can manage current state ...
// - Check for Long Positions for each Signaller to Close ...
// - Handle Hedging Signaller's Positions if it's enabled ...
// - Force Closing Position when Specified Time reached ...
// - Check Start and End time or Trading Dates ...
// - handle Trailing or Risk free Signals based on several conditions ...
// and etc ...
bool HandleStateManagement(XSignal &signals[]) override
{
//
const bool result = false;
//
// Here we Implement Account Protector ...
HandleAccountProtect();
//
// Do all State Management here ...
//
// if Returns true, Signal Execution failed ...
return result;
}
//
// Protected ...
protected:
//
// Tools ...
//
// Do All Protection Senarios here ...
void HandleAccountProtect()
{
}
//
// Private ...
private:
};
//
+8 -21
View File
@@ -21,11 +21,7 @@
//
// Imports ...
#include "../Libraries/x-saherelm.draw.lib.mq5"
#include "../Classes/x-saherelm.xalert.class.mq5"
#include "../Classes/x-saherelm.xtrade.class.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.x121.setup.class.mq5"
#include "../Classes/x-saherelm.x121.setup.xea.mq5"
//
#define ShortName "XTESTXXX"
@@ -53,15 +49,7 @@ int eaReuiredVerifications = 1; // Required Verifications for Signals
// Local Variables ...
//
XSCAlert *mAlert;
XSCTrade *mTrader;
//
XSCX121Setup *mSetup;
X121SignalGenerator mSignalGenerator;
//
XBarTracker xBarTracker;
XSCX121SetupEA *mEA;
//
// Event Handlers ...
@@ -220,13 +208,12 @@ bool InitialEA()
TesterHideIndicators(true);
//
mAlert = new XSCAlert();
mAlert.SetLogAlerts(true);
mAlert.SetPrefix(ShortName);
mAlert.SetEnableAlerts(true);
mAlert.SetPushAlerts(false);
mAlert.SetMailAlerts(false);
mAlert.SetTerminalAlerts(false);
SetLogAlerts(true);
SetPrefix(ShortName);
SetEnableAlerts(true);
SetPushAlerts(false);
SetMailAlerts(false);
SetTerminalAlerts(false);
//
mTrader = new XSCTrade(