last ...
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -5477,7 +5477,7 @@ public:
|
||||
|
||||
//
|
||||
bool ExecuteSignal(
|
||||
XSignal &signal, // Signal for Execution
|
||||
XSignal &signal, // Signal for Execution
|
||||
ENUM_X_SIGNAL_EXECUTION_RESULT &state, // Execution State
|
||||
bool ignorePolicies = false // Ignore Execution Policies
|
||||
)
|
||||
@@ -5621,6 +5621,7 @@ public:
|
||||
//
|
||||
string msg = (signal.type == POSITION_TYPE_BUY ? "Long" : "Short") +
|
||||
" Signal Provided by: " + signal.provider +
|
||||
(signal.pushers > 1 ? " Pushers: " + ToString(signal.pushers) : "") +
|
||||
" on: " + signal.symbol +
|
||||
" in: " + ToString(signal.period) +
|
||||
" Executed Successfully ...";
|
||||
|
||||
@@ -1241,19 +1241,34 @@ public:
|
||||
sl,
|
||||
tp //
|
||||
);
|
||||
if (result)
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
signal.pushers = pushers;
|
||||
|
||||
//
|
||||
// Notify XCH Specified Signal Event Handlers ...
|
||||
NotifyOnXCHSignalEventHandlers(
|
||||
signal,
|
||||
conditions //
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
signal.pushers = pushers;
|
||||
|
||||
//
|
||||
// Prepare and Normalize Signal for Execution in Strategy ...
|
||||
result = PrepareSignal(signal);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Notify XCH Specified Signal Event Handlers ...
|
||||
NotifyOnXCHSignalEventHandlers(
|
||||
signal,
|
||||
conditions //
|
||||
);
|
||||
|
||||
//
|
||||
// Since we Ignore Signal Execution in this Strategy ...
|
||||
// Make it the result false here for Preventing Double Execution ...
|
||||
result = false;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user