start implementing XTrade Handler Class ...

This commit is contained in:
2024-07-22 02:04:16 +03:30
parent d194d85082
commit d1e8daa131
5 changed files with 853 additions and 38 deletions
+84 -18
View File
@@ -46,18 +46,19 @@ public:
//
// Constructors ...
void XSCBaseStrategy(
string _symbol, // Trading Symbol
ENUM_TIMEFRAMES _period, // Trading TimeFrame
double _volume, // Voluem
double _r2r, // Risk/Reward Ratio
int _slippage, // Trader Slippage
long _magicNumber, // Trader Magic Number
bool _useTPSLAsPoint = false, // Converts TP and SL by Provided Points
bool _forceMaxTPSLAsPoint = false, // Force Max TP and SL by Provided Points
double _tpPoint = 0, // TP As Point
double _slPoint = 0, // SL As Point
bool _ignoreTP = false, // TP set to 0
bool _ignoreSL = false, // SL set to 0
string _symbol, // Trading Symbol
ENUM_TIMEFRAMES _period, // Trading TimeFrame
double _volume, // Voluem
double _r2r, // Risk/Reward Ratio
int _slippage, // Trader Slippage
long _magicNumber, // Trader Magic Number
bool _ignoreSignalExecution = false, // Ignore Signal Execution
bool _useTPSLAsPoint = false, // Converts TP and SL by Provided Points
bool _forceMaxTPSLAsPoint = false, // Force Max TP and SL by Provided Points
double _tpPoint = 0, // TP As Point
double _slPoint = 0, // SL As Point
bool _ignoreTP = false, // TP set to 0
bool _ignoreSL = false, // SL set to 0
bool _allowLong = true,
bool _allowShort = true,
int _maxAllowedLongs = 0,
@@ -82,6 +83,7 @@ public:
mMaxAllowedLongs = _maxAllowedLongs;
mMaxAllowedShorts = _maxAllowedShorts;
mForceMaxTPSLAsPoint = _forceMaxTPSLAsPoint;
mIgnoreSignalExecution = _ignoreSignalExecution;
//
mForceDisabled = false;
@@ -371,6 +373,29 @@ public:
mIgnoreSL = value;
}
//
bool IgnoreSignalExecution()
{
return mIgnoreSignalExecution;
}
//
void IgnoreSignalExecution(bool value)
{
mIgnoreSignalExecution = value;
}
//
// On Signal Handlers ...
void AddSignalEventHandler(TOnSignal handler)
{
//
Add(
handler,
mOnSignalEventHandlers //
);
}
//
// Virtual Methods ...
@@ -600,6 +625,18 @@ public:
signal.sl = 0;
}
//
// Notify Signal Event Handler(s) ...
NotifyOnSignalEventHandlers(signal);
//
// Check Signal Execution Enabled or not ...
result = !mIgnoreSignalExecution;
if (!result)
{
return result;
}
//
ENUM_X_SIGNAL_EXECUTION_RESULT state;
result = trader.ExecuteSignal(
@@ -652,12 +689,13 @@ protected:
int mMaxAllowedShorts; // Max Allowed Shorts
//
bool mUseTPSLAsPoint; // Converts TP and SL by Provided Points
bool mForceMaxTPSLAsPoint; // Force Max TP and SL by Provided Points
double mTPPoint; // TP As Point
double mSLPoint; // SL As Point
bool mIgnoreTP; // TP set to 0
bool mIgnoreSL; // SL set to 0
bool mUseTPSLAsPoint; // Converts TP and SL by Provided Points
bool mForceMaxTPSLAsPoint; // Force Max TP and SL by Provided Points
double mTPPoint; // TP As Point
double mSLPoint; // SL As Point
bool mIgnoreTP; // TP set to 0
bool mIgnoreSL; // SL set to 0
bool mIgnoreSignalExecution; // Ignore Signal Execution
//
string mSymbol; // Trading Symbol ...
@@ -687,11 +725,39 @@ protected:
barTracker.Clean();
}
//
// Notified Signal Event Handler(s) ...
void NotifyOnSignalEventHandlers(XSignal &signal)
{
//
if (!signal.IsValid())
{
return;
}
//
int count = ArraySize(mOnSignalEventHandlers);
if (!IsValidSize(count))
{
return;
}
//
for (int i = 0; i < count; i++)
{
mOnSignalEventHandlers[i](signal);
}
}
//
// Private ...
private:
//
// Props ...
//
// On Signal Recieved Event Handler(s) ...
TOnSignal mOnSignalEventHandlers[];
};
//