This commit is contained in:
2024-08-01 02:55:30 +03:30
parent 3a2ef261b5
commit a6905cbf98
3 changed files with 154 additions and 118 deletions
+127 -107
View File
@@ -716,6 +716,125 @@ public:
bool result = false;
//
// Prepare and Normalize Signal ...
result = PrepareSignal(signal);
if (!result)
{
return result;
}
//
// Notify Signal Event Handler(s) ...
NotifyOnSignalEventHandlers(signal);
//
// Check Signal Execution Enabled or not ...
result = !mIgnoreSignalExecution;
if (!result)
{
return result;
}
//
bool isLong = IsLong(signal.type);
//
ENUM_X_SIGNAL_EXECUTION_RESULT state;
result = trader.ExecuteSignal(
signal,
state //
);
if (result)
{
//
string message = "Execute " + (isLong ? "Long" : "Short") + " " + signal.symbol + "/" + ToString(signal.period) + " ...";
Alert(message);
//
OnSignalExecuted(signal);
}
else
{
OnSignalExecutionFailed(signal, state);
}
//
return result;
}
//
// Calls When a Signal Executed Successfully ...
virtual void OnSignalExecuted(XSignal &signal)
{
}
//
// Calls When a Signal Execution Failed ...
virtual void OnSignalExecutionFailed(
XSignal &signal,
ENUM_X_SIGNAL_EXECUTION_RESULT result //
)
{
}
//
// Protected ...
protected:
//
int mSlippage; // Trader Slippage
long mMagicNumber; // Trader Magic Number
bool mForceDisabled; // Force Disabled
bool mAllowLong; // Allow Long Signals
bool mAllowShort; // Allow Short Signals
int mMaxAllowedLongs; // Max Allowed Longs
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 mIgnoreSignalExecution; // Ignore Signal Execution
//
string mSymbol; // Trading Symbol ...
ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame ...
//
double mR2R; // Risk/Rewar Ratio ...
double mVolume; // Static Volume Per Trades ...
//
XBarTracker barTracker; // Strategy Time Tracker ...
//
// Trend Detecting ...
int mRequiredPivots; // Required Pivots For Trend Detecting ...
int mRequiredShoulders; // Required Pivots Shoulders ...
//
XSCTrade *trader;
//
MqlTick lastTick;
//
void Reset()
{
barTracker.Clean();
}
//
// Prepare and Normalize Signal for Execution in Strategy ...
bool PrepareSignal(XSignal &signal)
{
//
bool result = false;
//
// Check Strategy Is Enables ...
result = !IsDisabled();
if (!result)
{
@@ -723,6 +842,7 @@ public:
}
//
// Validate Signal ...
result = signal.IsValid();
if (!result)
{
@@ -733,6 +853,7 @@ public:
bool isLong = IsLong(signal.type);
//
// Check Type Enabled ...
result =
//
isLong
@@ -756,20 +877,15 @@ public:
//
// Get and Count Positions ...
XPosition positions[];
int positionsCount = trader.GetPositions(
positions //
XPosition longs[];
XPosition shorts[];
trader.GetPositions(
longs,
shorts,
signal.symbol //
);
//
// Get and Count Lng and Short Positions ...
XPosition longs[];
XPosition shorts[];
ExtractPositions(
positions,
longs,
shorts //
);
int longsCount = ArraySize(longs);
int shortsCount = ArraySize(shorts);
@@ -865,106 +981,10 @@ 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(
signal,
state //
);
if (result)
{
//
string message = "Execute " + (isLong ? "Long" : "Short") + " " + signal.symbol + "/" + ToString(signal.period) + " ...";
Alert(message);
//
OnSignalExecuted(signal);
}
else
{
OnSignalExecutionFailed(signal, state);
}
//
return result;
}
//
// Calls When a Signal Executed Successfully ...
virtual void OnSignalExecuted(XSignal &signal)
{
}
//
// Calls When a Signal Execution Failed ...
virtual void OnSignalExecutionFailed(
XSignal &signal,
ENUM_X_SIGNAL_EXECUTION_RESULT result //
)
{
}
//
// Protected ...
protected:
//
int mSlippage; // Trader Slippage
long mMagicNumber; // Trader Magic Number
bool mForceDisabled; // Force Disabled
bool mAllowLong; // Allow Long Signals
bool mAllowShort; // Allow Short Signals
int mMaxAllowedLongs; // Max Allowed Longs
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 mIgnoreSignalExecution; // Ignore Signal Execution
//
string mSymbol; // Trading Symbol ...
ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame ...
//
double mR2R; // Risk/Rewar Ratio ...
double mVolume; // Static Volume Per Trades ...
//
XBarTracker barTracker; // Strategy Time Tracker ...
//
// Trend Detecting ...
int mRequiredPivots; // Required Pivots For Trend Detecting ...
int mRequiredShoulders; // Required Pivots Shoulders ...
//
XSCTrade *trader;
//
MqlTick lastTick;
//
void Reset()
{
barTracker.Clean();
}
//
// Notified Signal Event Handler(s) ...
void NotifyOnSignalEventHandlers(XSignal &signal)