last ...
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.base.class.mq5"
|
||||
#include "../Libraries/x-saherelm.tools.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xalert.class.mq5"
|
||||
#include "../Libraries/x-saherelm.xtrade.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xaccount.class.mq5"
|
||||
@@ -4232,6 +4233,109 @@ public:
|
||||
mTrailBasedOnProfit = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Recovery ...
|
||||
|
||||
//
|
||||
bool AllowRecover()
|
||||
{
|
||||
return mAllowRecover;
|
||||
}
|
||||
|
||||
//
|
||||
void AllowRecover(bool value)
|
||||
{
|
||||
mAllowRecover = value;
|
||||
}
|
||||
|
||||
//
|
||||
double RecoveryTPPoint()
|
||||
{
|
||||
return mRecoveryTPPoint;
|
||||
}
|
||||
|
||||
//
|
||||
void RecoveryTPPoint(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mRecoveryTPPoint = value;
|
||||
}
|
||||
|
||||
//
|
||||
double RecoverySLPoint()
|
||||
{
|
||||
return mRecoverySLPoint;
|
||||
}
|
||||
|
||||
//
|
||||
void RecoverySLPoint(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mRecoverySLPoint = value;
|
||||
}
|
||||
|
||||
//
|
||||
bool RecoverBasedOnPressures()
|
||||
{
|
||||
return mRecoverBasedOnPressures;
|
||||
}
|
||||
|
||||
//
|
||||
void RecoverBasedOnPressures(bool value)
|
||||
{
|
||||
mRecoverBasedOnPressures = value;
|
||||
}
|
||||
|
||||
//
|
||||
int MaxAllowedRecover()
|
||||
{
|
||||
return mMaxAllowedRecover;
|
||||
}
|
||||
|
||||
//
|
||||
void MaxAllowedRecover(int value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mMaxAllowedRecover = value;
|
||||
}
|
||||
|
||||
//
|
||||
double RecoveryVolumeMultiplier()
|
||||
{
|
||||
return mRecoveryVolumeMultiplier;
|
||||
}
|
||||
|
||||
//
|
||||
void RecoveryVolumeMultiplier(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mRecoveryVolumeMultiplier = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Hedging ...
|
||||
|
||||
@@ -4304,9 +4408,10 @@ public:
|
||||
// First Step of Trade Handling ...
|
||||
// Since Must Call when a Signal Executed ...
|
||||
void AddData(
|
||||
XSignal &signal, // Executed Signal
|
||||
double commission = 0, // Commission
|
||||
bool forceTrail = false //
|
||||
XSignal &signal, // Executed Signal
|
||||
double commission = 0, // Commission
|
||||
bool forceTrail = false, // Force Signal Trailling Stop
|
||||
bool forceRecover = false // Force Signal Recovery
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -4345,6 +4450,22 @@ public:
|
||||
item.trailBasedOnProfit = mTrailBasedOnProfit;
|
||||
}
|
||||
|
||||
//
|
||||
// Recovery Configuration ...
|
||||
|
||||
//
|
||||
// Force Recovery used to implement Recovery for
|
||||
// Custom Positions ...
|
||||
if (mAllowRecover || forceRecover)
|
||||
{
|
||||
//
|
||||
item.allowRecover = true;
|
||||
|
||||
//
|
||||
item.recoveryTPPoint = mRecoveryTPPoint;
|
||||
item.recoverySLPoint = mRecoverySLPoint;
|
||||
}
|
||||
|
||||
//
|
||||
Add(item);
|
||||
|
||||
@@ -4585,6 +4706,8 @@ public:
|
||||
double trailStepInPoints = mData[i].trailStepInPoint;
|
||||
double trailStartInPoint = mData[i].trailStartInPoint;
|
||||
bool trailBasedOnProfit = mData[i].trailBasedOnProfit;
|
||||
double recoveryTPPoint = mData[i].recoveryTPPoint;
|
||||
double recoverySLPoint = mData[i].recoverySLPoint;
|
||||
|
||||
//
|
||||
XPosition iPosition;
|
||||
@@ -4608,6 +4731,49 @@ public:
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Retriece CIndex Bar ...
|
||||
XOHCL cBar;
|
||||
bool isBarInited = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
1 //
|
||||
);
|
||||
if (!isBarInited)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// For Trend ...
|
||||
XOHCL tmpHSW[];
|
||||
XOHCL tmpLSW[];
|
||||
|
||||
//
|
||||
// Detect Bullish/Bearish Patterns and Trends ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
bool hasBullishPower = cBar.HasBullishPower();
|
||||
bool hasBullishPattern = HasBullishPattern(cBar);
|
||||
bool hasBullishPressure = cBar.HasBullishPressure();
|
||||
bool isBullishTrend = cBar.HasBullishTrend(
|
||||
tmpHSW,
|
||||
tmpLSW,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
bool hasBearishPower = cBar.HasBearishPower();
|
||||
bool hasBearishPattern = HasBearishPattern(cBar);
|
||||
bool hasBearishPressure = cBar.HasBearishPressure();
|
||||
bool isBearishTrend = cBar.HasBearishTrend(
|
||||
tmpHSW,
|
||||
tmpLSW,
|
||||
false //
|
||||
);
|
||||
|
||||
//
|
||||
// Trail ...
|
||||
if (mData[i].allowTrailStop)
|
||||
@@ -4779,7 +4945,79 @@ public:
|
||||
}
|
||||
|
||||
//
|
||||
// Grid ...
|
||||
// Recovery ...
|
||||
if (mData[i].allowRecover)
|
||||
{
|
||||
//
|
||||
// Do Recovery ...
|
||||
|
||||
//
|
||||
// Profit Must be Negative ...
|
||||
if (
|
||||
profit < 0 &&
|
||||
recoveryTPPoint > 0 &&
|
||||
recoverySLPoint > 0)
|
||||
{
|
||||
//
|
||||
// Current Profit ...
|
||||
double drawdownInPoints = (MathAbs(profit) / volume);
|
||||
|
||||
//
|
||||
// Try to Remove SL of Recovery Signals ...
|
||||
if (iPosition.sl > 0)
|
||||
{
|
||||
//
|
||||
string comment = "EQM Recover Remove SL";
|
||||
bool isSLRemoved = mTrader.Modify(
|
||||
ticket,
|
||||
0,
|
||||
iPosition.tp,
|
||||
comment //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Check Position TP ...
|
||||
double rewardInPoints = iPosition.GetReward() / points;
|
||||
if (rewardInPoints != recoveryTPPoint)
|
||||
{
|
||||
//
|
||||
double reward = recoveryTPPoint * points;
|
||||
double tp =
|
||||
isLong
|
||||
? iPosition.entry + reward
|
||||
: iPosition.entry - reward;
|
||||
string comment = "EQM Recover Fix TP";
|
||||
bool isSLRemoved = mTrader.Modify(
|
||||
ticket,
|
||||
iPosition.sl,
|
||||
tp,
|
||||
comment //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Check Price Distance For Recovery ...
|
||||
bool canLookForPressure =
|
||||
//
|
||||
// in 75% ...
|
||||
drawdownInPoints > ((recoverySLPoint / 3) * 2)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (canLookForPressure)
|
||||
{
|
||||
//
|
||||
// Looking for Signal Direction and
|
||||
// Founding Pressure ...
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4802,6 +5040,7 @@ public:
|
||||
// TODO:
|
||||
// Here we can apply Same type or Opposit Type
|
||||
// Signals behaviour ...
|
||||
// also Implement Signal Filtering ...
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -4829,6 +5068,15 @@ protected:
|
||||
double mTrailStartInPoint; // Trail Starts in Points of Profit
|
||||
double mTrailStepInPoint; // Profit Must Grows Point to do Trailling
|
||||
|
||||
//
|
||||
// Recovery ...
|
||||
bool mAllowRecover; // Allow Signal Recovery
|
||||
int mMaxAllowedRecover; // Max Allowed Recovery
|
||||
double mRecoveryTPPoint; // Recovery TP in Points
|
||||
double mRecoverySLPoint; // Recovery SL in Points
|
||||
bool mRecoverBasedOnPressures; // Do Recovery based on Market Pressures
|
||||
double mRecoveryVolumeMultiplier; // Recovery Volume Multiplier
|
||||
|
||||
//
|
||||
// Hedging ...
|
||||
bool mAllowHedging; // Hedge Trades
|
||||
|
||||
Reference in New Issue
Block a user