This commit is contained in:
2024-07-17 19:23:17 +03:30
parent 3294ea9f21
commit b4bc3774b0
6 changed files with 1355 additions and 131 deletions
+149 -6
View File
@@ -21,6 +21,7 @@
//
/// Imports ...
#include "../Libraries/x-saherelm.tools.lib.mq5"
#include "../Classes/x-saherelm.xtrade.class.mq5"
#include "../Classes/x-saherelm.xalert.class.mq5"
@@ -45,12 +46,16 @@ 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
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 _allowLong = true,
bool _allowShort = true,
int _maxAllowedLongs = 0,
@@ -63,12 +68,16 @@ public:
mVolume = _volume;
mSymbol = _symbol;
mPeriod = _period;
mTPPoint = _tpPoint;
mSLPoint = _slPoint;
mSlippage = _slippage;
mAllowLong = _allowLong;
mAllowShort = _allowShort;
mMagicNumber = _magicNumber;
mUseTPSLAsPoint = _useTPSLAsPoint;
mMaxAllowedLongs = _maxAllowedLongs;
mMaxAllowedShorts = _maxAllowedShorts;
mForceMaxTPSLAsPoint = _forceMaxTPSLAsPoint;
//
mForceDisabled = false;
@@ -272,6 +281,68 @@ public:
mRequiredShoulders = value;
}
//
bool UseTPSLAsPoint()
{
return mUseTPSLAsPoint;
}
//
void UseTPSLAsPoint(bool value)
{
mUseTPSLAsPoint = value;
}
//
bool ForceMaxTPSLAsPoint()
{
return mForceMaxTPSLAsPoint;
}
//
void ForceMaxTPSLAsPoint(bool value)
{
mForceMaxTPSLAsPoint = value;
}
//
double TPPoint()
{
return mTPPoint;
}
//
void TPPoint(double value)
{
//
if (value < 0)
{
value = 0;
}
//
mTPPoint = value;
}
//
double SLPoint()
{
return mSLPoint;
}
//
void SLPoint(double value)
{
//
if (value < 0)
{
value = 0;
}
//
mSLPoint = value;
}
//
// Virtual Methods ...
@@ -423,6 +494,72 @@ public:
}
}
//
// Check TP and SL ...
double points = GetPoints(signal.symbol);
if (mUseTPSLAsPoint)
{
//
double sl = 0;
double tp = 0;
bool isCalculated = !(mSLPoint > 0 || mTPPoint > 0)
? false
: CalculateTPSLByPoint(
sl,
tp,
signal.type,
signal.entry,
points,
mR2R,
mSLPoint,
mTPPoint //
);
if (isCalculated)
{
//
signal.sl = sl;
signal.tp = tp;
}
}
else if (mForceMaxTPSLAsPoint)
{
//
if (mSLPoint > 0)
{
//
double risk = signal.GetRisk();
double riskPoints = risk / points;
//
if (riskPoints > mSLPoint)
{
//
signal.sl =
isLong
? signal.entry - (mSLPoint * points)
: signal.entry + (mSLPoint * points);
}
}
//
if (mTPPoint > 0)
{
//
double reward = signal.GetReward();
double rewardPoints = reward / points;
//
if (rewardPoints > mTPPoint)
{
//
signal.tp =
isLong
? signal.entry + (mTPPoint * points)
: signal.entry - (mTPPoint * points);
}
}
}
//
ENUM_X_SIGNAL_EXECUTION_RESULT state;
result = trader.ExecuteSignal(
@@ -474,6 +611,12 @@ protected:
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
//
string mSymbol; // Trading Symbol ...
ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame ...