last refactor ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,200 @@
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
// Last Bar ...
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
position.symbol,
|
||||
position.period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Previous Bar of Last Bar ...
|
||||
XOHCL pBar;
|
||||
result = cBar.GetPreviousBar(pBar);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Last Swing Low Bar ...
|
||||
XOHCL lastSwingLow;
|
||||
result = cBar.FindLastSwingLow(lastSwingLow);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Last Swing High Bar ...
|
||||
XOHCL lastSwingHigh;
|
||||
result = cBar.FindLastSwingHigh(lastSwingHigh);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Common Conditions For Bullish and Bearish Powers ...
|
||||
|
||||
//
|
||||
// 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 //
|
||||
);
|
||||
bool isBullishTrend1 = cBar.HasBullishTrend(
|
||||
tmpHSW,
|
||||
tmpLSW,
|
||||
false //
|
||||
);
|
||||
bool hasBullishTrend =
|
||||
//
|
||||
isBullishTrend
|
||||
//
|
||||
||
|
||||
//
|
||||
isBullishTrend1
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
bool hasBearishPower = cBar.HasBearishPower();
|
||||
bool hasBearishPattern = HasBearishPattern(cBar);
|
||||
bool hasBearishPressure = cBar.HasBearishPressure();
|
||||
bool isBearishTrend = cBar.HasBearishTrend(
|
||||
tmpHSW,
|
||||
tmpLSW,
|
||||
true //
|
||||
);
|
||||
bool isBearishTrend1 = cBar.HasBearishTrend(
|
||||
tmpHSW,
|
||||
tmpLSW,
|
||||
false //
|
||||
);
|
||||
bool hasBearishTrend =
|
||||
//
|
||||
isBearishTrend
|
||||
//
|
||||
||
|
||||
//
|
||||
isBearishTrend1
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
MqlTick ticks[];
|
||||
int ticksCount = CopyTicks(
|
||||
position.symbol,
|
||||
ticks,
|
||||
COPY_TICKS_ALL,
|
||||
0,
|
||||
5 //
|
||||
);
|
||||
|
||||
//
|
||||
// TODO: Check Volume if Required ...
|
||||
|
||||
//
|
||||
bool isTicksBullishForLong =
|
||||
//
|
||||
GetTickExit(ticks[0], POSITION_TYPE_BUY, position.symbol) > GetTickExit(ticks[1], POSITION_TYPE_BUY, position.symbol) &&
|
||||
GetTickExit(ticks[1], POSITION_TYPE_BUY, position.symbol) > GetTickExit(ticks[2], POSITION_TYPE_BUY, position.symbol) &&
|
||||
GetTickExit(ticks[2], POSITION_TYPE_BUY, position.symbol) > GetTickExit(ticks[3], POSITION_TYPE_BUY, position.symbol)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isTicksBearishForLong =
|
||||
//
|
||||
GetTickExit(ticks[0], POSITION_TYPE_BUY, position.symbol) < GetTickExit(ticks[1], POSITION_TYPE_BUY, position.symbol) &&
|
||||
GetTickExit(ticks[1], POSITION_TYPE_BUY, position.symbol) < GetTickExit(ticks[2], POSITION_TYPE_BUY, position.symbol) &&
|
||||
GetTickExit(ticks[2], POSITION_TYPE_BUY, position.symbol) < GetTickExit(ticks[3], POSITION_TYPE_BUY, position.symbol)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isTicksBullishForShort =
|
||||
//
|
||||
GetTickExit(ticks[0], POSITION_TYPE_SELL, position.symbol) > GetTickExit(ticks[1], POSITION_TYPE_SELL, position.symbol) &&
|
||||
GetTickExit(ticks[1], POSITION_TYPE_SELL, position.symbol) > GetTickExit(ticks[2], POSITION_TYPE_SELL, position.symbol) &&
|
||||
GetTickExit(ticks[2], POSITION_TYPE_SELL, position.symbol) > GetTickExit(ticks[3], POSITION_TYPE_SELL, position.symbol)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isTicksBearishForShort =
|
||||
//
|
||||
GetTickExit(ticks[0], POSITION_TYPE_SELL, position.symbol) < GetTickExit(ticks[1], POSITION_TYPE_SELL, position.symbol) &&
|
||||
GetTickExit(ticks[1], POSITION_TYPE_SELL, position.symbol) < GetTickExit(ticks[2], POSITION_TYPE_SELL, position.symbol) &&
|
||||
GetTickExit(ticks[2], POSITION_TYPE_SELL, position.symbol) < GetTickExit(ticks[3], POSITION_TYPE_SELL, position.symbol)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool hasBullishDecision =
|
||||
//
|
||||
cBar.IsBullishDecision()
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool hasBearishDecision =
|
||||
//
|
||||
cBar.IsBearishDecision()
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool hasBullishConditions =
|
||||
//
|
||||
(
|
||||
//
|
||||
hasBullishTrend &&
|
||||
hasBullishDecision &&
|
||||
(hasBullishPower ||
|
||||
hasBullishPattern ||
|
||||
hasBullishPressure)
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool hasBearishConditions =
|
||||
//
|
||||
(
|
||||
//
|
||||
hasBearishTrend &&
|
||||
hasBearishDecision &&
|
||||
(hasBearishPower ||
|
||||
hasBearishPattern ||
|
||||
hasBearishPressure)
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
@@ -0,0 +1,601 @@
|
||||
|
||||
//
|
||||
// In Profit ...
|
||||
// When a Position running in Profit, we have to look pressures by Same Direction
|
||||
// of Main Position. for eaxmple if it is long, we look for Bullish Pressures and
|
||||
// if it is short we look for Bearish Pressures.
|
||||
// when pressure happens we must Trail position Stop ...
|
||||
if (isInProfit)
|
||||
{
|
||||
//
|
||||
// Do In Profit Protection Mechanism ...
|
||||
|
||||
//
|
||||
// Trail Stops ...
|
||||
// Remove Trailed Positions TP ...
|
||||
bool allowTrailStop = AllowTrailStopInProfits();
|
||||
double trailStep = TrailStopStepsInPoint();
|
||||
bool allowOnlyUnprotecteds = OnlyTrailUnprotectedPositions();
|
||||
bool isProtectionTrailPassed = !allowOnlyUnprotecteds
|
||||
? true
|
||||
: supportsCount == 0;
|
||||
if (allowTrailStop && trailStep > 0 && isProtectionTrailPassed)
|
||||
{
|
||||
//
|
||||
// Temp Vaiables ...
|
||||
bool canTrailStop = false;
|
||||
|
||||
//
|
||||
if (isLong)
|
||||
{
|
||||
//
|
||||
// Check Conditions ...
|
||||
canTrailStop = isTicksBullishForLong &&
|
||||
hasBullishConditions;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Check Conditions ...
|
||||
canTrailStop = isTicksBearishForShort &&
|
||||
hasBearishConditions;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Stop Trailling ...
|
||||
if (canTrailStop)
|
||||
{
|
||||
//
|
||||
int lastTrailedStep = mData[iDX].trailStep;
|
||||
|
||||
//
|
||||
double entry = position.entry;
|
||||
double pointValue = position.GetPointsValue();
|
||||
double profitInPoint = position.GetProfitInPoint();
|
||||
|
||||
//
|
||||
double requiredProfit =
|
||||
lastTrailedStep == 0
|
||||
? ProtectorStartDistanceInPoint()
|
||||
: ProtectorStartDistanceInPoint() + (lastTrailedStep * trailStep);
|
||||
|
||||
//
|
||||
bool isProfitsPassed = profitInPoint > requiredProfit;
|
||||
if (isProfitsPassed)
|
||||
{
|
||||
//
|
||||
double delta = (requiredProfit * pointValue);
|
||||
|
||||
//
|
||||
double sl =
|
||||
isLong
|
||||
? entry + delta
|
||||
: entry - delta;
|
||||
|
||||
//
|
||||
string comment = "EQM Trail Stop ...";
|
||||
|
||||
//
|
||||
// Try to Modify Position ...
|
||||
result = mTrader.Modify(
|
||||
position.ticket,
|
||||
sl,
|
||||
position.tp,
|
||||
comment //
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
mData[iDX].trailStep++;
|
||||
|
||||
//
|
||||
string message = "EQM Trail (" + ToString(position.ticket) + ") Stop ...";
|
||||
Alert(message);
|
||||
|
||||
//
|
||||
XPosition trailedPosition;
|
||||
bool hasPosition = mTrader.GetPosition(
|
||||
position.ticket,
|
||||
trailedPosition //
|
||||
);
|
||||
|
||||
//
|
||||
// Check Remove Trailed Positions TP Conditions ...
|
||||
int removeTPOnTrailStep = RmoveTPOnTrailStep();
|
||||
if (removeTPOnTrailStep > 0 && mData[iDX].trailStep == removeTPOnTrailStep && trailedPosition.tp != 0)
|
||||
{
|
||||
//
|
||||
string comment = "EQM Removes TP ...";
|
||||
|
||||
//
|
||||
// Remove Position's TP ...
|
||||
result = mTrader.Modify(
|
||||
trailedPosition.ticket,
|
||||
trailedPosition.sl,
|
||||
0,
|
||||
comment //
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
string message = "EQM Removes (" + ToString(trailedPosition.ticket) + ") TP ...";
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool allowRecover = AllowRecoverInDrawdowns();
|
||||
double volumeMultiplier = RecoveryMultiplier();
|
||||
if (allowRecover && !canFreeze && volumeMultiplier > 0 && supportsCount > 0)
|
||||
{
|
||||
//
|
||||
bool canRecover = false;
|
||||
int delayMinutes = RecoveryDelayInMinute();
|
||||
double recoveryDistancePoint = RecoveryDistanceInPoint();
|
||||
|
||||
//
|
||||
// Temparory Requirement for Recover Signal ...
|
||||
double sl = 0;
|
||||
double tp = 0;
|
||||
double entry = 0;
|
||||
ENUM_POSITION_TYPE type = NULL;
|
||||
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
|
||||
double lastStep = mData[iDX].protectionStep;
|
||||
double volume = position.volume * volumeMultiplier;
|
||||
bool applyLevel = ApplyRecoveryLevelOnVolume();
|
||||
if (applyLevel)
|
||||
{
|
||||
//
|
||||
volume = supportsCount <= 0
|
||||
? position.volume * volumeMultiplier
|
||||
: position.volume * ((supportsCount + 1) * volumeMultiplier);
|
||||
}
|
||||
|
||||
//
|
||||
datetime currentTime = TimeCurrent();
|
||||
double currentProfit = position.GetProfitInPoint();
|
||||
datetime lastProtectedOn = mData[iDX].lastProtectedOn;
|
||||
double lastProtectedProfit = mData[iDX].lastProtectedInProfit;
|
||||
bool isRecoveryConditionsPassed =
|
||||
//
|
||||
// Check Regular Conditions ...
|
||||
delayMinutes > 0 &&
|
||||
recoveryDistancePoint > 0 &&
|
||||
IsValid(lastProtectedOn) &&
|
||||
//
|
||||
// Check Time Delay Passed ...
|
||||
(TimeToSeconds(currentTime) - TimeToSeconds(lastProtectedOn)) >= ulong(delayMinutes * 60) &&
|
||||
//
|
||||
// Check Recovery Distance Passed ...
|
||||
MathAbs(currentProfit) - MathAbs(lastProtectedProfit) >= recoveryDistancePoint;
|
||||
|
||||
//
|
||||
if (isRecoveryConditionsPassed)
|
||||
{
|
||||
//
|
||||
// Long Recovery ...
|
||||
if (isLong)
|
||||
{
|
||||
//
|
||||
// Same Direction ...
|
||||
canRecover =
|
||||
//
|
||||
isTicksBullishForLong &&
|
||||
hasBullishTrend &&
|
||||
(hasBullishPower ||
|
||||
hasBullishPattern ||
|
||||
hasBullishPressure)
|
||||
//
|
||||
;
|
||||
if (canRecover)
|
||||
{
|
||||
//
|
||||
sl = position.sl;
|
||||
tp = position.tp;
|
||||
type = POSITION_TYPE_BUY;
|
||||
}
|
||||
}
|
||||
//
|
||||
// Short Recovery ...
|
||||
else
|
||||
{
|
||||
//
|
||||
// Same Direction ...
|
||||
canRecover =
|
||||
//
|
||||
isTicksBearishForShort &&
|
||||
hasBearishTrend &&
|
||||
(hasBearishPower ||
|
||||
hasBearishPattern ||
|
||||
hasBearishPressure)
|
||||
//
|
||||
;
|
||||
if (canRecover)
|
||||
{
|
||||
//
|
||||
sl = position.sl;
|
||||
tp = position.tp;
|
||||
type = POSITION_TYPE_SELL;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (canRecover)
|
||||
{
|
||||
//
|
||||
XSignal signal;
|
||||
entry = GetEntry(
|
||||
position.symbol,
|
||||
type //
|
||||
);
|
||||
|
||||
//
|
||||
// Prepare Signal ...
|
||||
result = signal.Prepare(
|
||||
position.symbol,
|
||||
position.provider,
|
||||
position.period,
|
||||
type,
|
||||
mode,
|
||||
entry,
|
||||
volume,
|
||||
sl,
|
||||
tp //
|
||||
);
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Generate Comment for Recover and Support ...
|
||||
string comment = GenerateSupportTag(position.ticket);
|
||||
|
||||
//
|
||||
signal.comment = comment;
|
||||
|
||||
//
|
||||
ENUM_X_SIGNAL_EXECUTION_RESULT state;
|
||||
result = ExecuteSignal(
|
||||
signal,
|
||||
state,
|
||||
true // Support Signal need to Ignore Policies ...
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
mData[iDX].protectionStep++;
|
||||
mData[iDX].lastProtectedOn = currentTime;
|
||||
mData[iDX].lastProtectedInProfit = currentProfit;
|
||||
|
||||
//
|
||||
string message = "EQM Open " + (IsLong(type) ? "Long" : "Short") + " Recovery Position in Level: " +
|
||||
ToString(lastStep + 1) +
|
||||
" for (" + ToString(position.ticket) + ")";
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check Points of Profit and Do Partial Closing ...
|
||||
double partialCloseVolume = PartialCloseVolumeInProfit();
|
||||
double partialCloseProfitPoint = PartialCloseOnSpecificPointOfProfit();
|
||||
if (partialCloseVolume > 0 && partialCloseProfitPoint > 0)
|
||||
{
|
||||
//
|
||||
double profitPoints = position.GetProfitInPoint();
|
||||
if (profitPoints >= partialCloseProfitPoint && !mData[iDX].partiallyClosed)
|
||||
{
|
||||
//
|
||||
string comment = "EQM Partial Close ...";
|
||||
|
||||
//
|
||||
// Do Partial Closing ...
|
||||
result = mTrader.ClosePartial(
|
||||
position.ticket,
|
||||
partialCloseVolume,
|
||||
comment //
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
mData[iDX].partiallyClosed = true;
|
||||
|
||||
//
|
||||
string message = "EQM Partially Closed " + ToString(partialCloseVolume) + " of (" + ToString(position.ticket) + ")";
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// In Drawdown ...
|
||||
// When a Position running in Drawdown, we have to look for pressures by Indirection
|
||||
// of Main Position. for example if it is long, we Look For Bearish Pressures and if
|
||||
// it is short we Look for Bullish Pressure.
|
||||
// when indirectional pressure found we must Open a Recovery Position.
|
||||
// also if Same Direction Pressure Found we try to Recover Same Direction using Grid ...
|
||||
else
|
||||
{
|
||||
//
|
||||
bool allowRecover = AllowRecoverInDrawdowns();
|
||||
double volumeMultiplier = RecoveryMultiplier();
|
||||
if (allowRecover && !canFreeze && volumeMultiplier > 0)
|
||||
{
|
||||
//
|
||||
bool canRecover = false;
|
||||
int delayMinutes = RecoveryDelayInMinute();
|
||||
double recoveryDistancePoint = RecoveryDistanceInPoint();
|
||||
|
||||
//
|
||||
// Temparory Requirement for Recover Signal ...
|
||||
double sl = 0;
|
||||
double tp = 0;
|
||||
double entry = 0;
|
||||
ENUM_POSITION_TYPE type = NULL;
|
||||
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
|
||||
double lastStep = mData[iDX].protectionStep;
|
||||
double volume = position.volume * volumeMultiplier;
|
||||
bool applyLevel = ApplyRecoveryLevelOnVolume();
|
||||
if (applyLevel)
|
||||
{
|
||||
//
|
||||
volume = supportsCount <= 0
|
||||
? position.volume * volumeMultiplier
|
||||
: position.volume * ((supportsCount + 1) * volumeMultiplier);
|
||||
}
|
||||
|
||||
//
|
||||
datetime currentTime = TimeCurrent();
|
||||
double currentDrawdown = position.GetProfitInPoint();
|
||||
datetime lastProtectedOn = mData[iDX].lastProtectedOn;
|
||||
double lastProtectedDrawdown = mData[iDX].lastProtectedInDrawdown;
|
||||
bool isRecoveryConditionsPassed = supportsCount <= 0
|
||||
? true
|
||||
:
|
||||
//
|
||||
// Check Regular Conditions ...
|
||||
delayMinutes > 0 &&
|
||||
recoveryDistancePoint > 0 &&
|
||||
IsValid(lastProtectedOn) &&
|
||||
lastProtectedDrawdown < 0 &&
|
||||
//
|
||||
// Check Time Delay Passed ...
|
||||
(TimeToSeconds(currentTime) - TimeToSeconds(lastProtectedOn)) >= ulong(delayMinutes * 60) &&
|
||||
//
|
||||
// Check Recovery Distance Passed ...
|
||||
MathAbs(currentDrawdown) - MathAbs(lastProtectedDrawdown) >= recoveryDistancePoint;
|
||||
|
||||
//
|
||||
if (isRecoveryConditionsPassed)
|
||||
{
|
||||
//
|
||||
// Long Recovery ...
|
||||
if (isLong)
|
||||
{
|
||||
//
|
||||
// Opposit Direction ...
|
||||
canRecover =
|
||||
//
|
||||
isTicksBearishForShort &&
|
||||
hasBearishTrend &&
|
||||
(hasBearishPower ||
|
||||
hasBearishPattern ||
|
||||
hasBearishPressure)
|
||||
//
|
||||
;
|
||||
if (canRecover)
|
||||
{
|
||||
//
|
||||
sl = position.tp;
|
||||
tp = position.sl;
|
||||
type = POSITION_TYPE_SELL;
|
||||
}
|
||||
}
|
||||
//
|
||||
// Short Recovery ...
|
||||
else
|
||||
{
|
||||
//
|
||||
// Opposit Direction ...
|
||||
canRecover =
|
||||
//
|
||||
isTicksBullishForLong &&
|
||||
hasBullishTrend &&
|
||||
(hasBullishPower ||
|
||||
hasBullishPattern ||
|
||||
hasBullishPressure)
|
||||
//
|
||||
;
|
||||
if (canRecover)
|
||||
{
|
||||
//
|
||||
sl = position.tp;
|
||||
tp = position.sl;
|
||||
type = POSITION_TYPE_BUY;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (canRecover)
|
||||
{
|
||||
//
|
||||
XSignal signal;
|
||||
entry = GetEntry(
|
||||
position.symbol,
|
||||
type //
|
||||
);
|
||||
|
||||
//
|
||||
// Prepare Signal ...
|
||||
result = signal.Prepare(
|
||||
position.symbol,
|
||||
position.provider,
|
||||
position.period,
|
||||
type,
|
||||
mode,
|
||||
entry,
|
||||
volume,
|
||||
sl,
|
||||
tp //
|
||||
);
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Generate Comment for Recover and Support ...
|
||||
string comment = GenerateSupportTag(position.ticket);
|
||||
|
||||
//
|
||||
signal.comment = comment;
|
||||
|
||||
//
|
||||
ENUM_X_SIGNAL_EXECUTION_RESULT state;
|
||||
result = ExecuteSignal(
|
||||
signal,
|
||||
state,
|
||||
true // Support Signal need to Ignore Policies ...
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
mData[iDX].protectionStep++;
|
||||
mData[iDX].lastProtectedOn = currentTime;
|
||||
mData[iDX].lastProtectedInDrawdown = currentDrawdown;
|
||||
|
||||
//
|
||||
string message = "EQM Open " + (IsLong(type) ? "Long" : "Short") + " Recovery Position in Level: " +
|
||||
ToString(lastStep + 1) +
|
||||
" for (" + ToString(position.ticket) + ")";
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (canFreeze &&
|
||||
supportsCount <= 0 &&
|
||||
position.profit < 0 &&
|
||||
!mData[iDX].freezed &&
|
||||
MathAbs(profitInPoint) >= freezePoint)
|
||||
{
|
||||
//
|
||||
bool removeTPSL = RemoveFreezedPositionsTPSL();
|
||||
//
|
||||
// Temparory Requirement for Recover Signal ...
|
||||
double sl = removeTPSL ? 0 : position.tp;
|
||||
double tp = removeTPSL ? 0 : position.sl;
|
||||
ENUM_POSITION_TYPE type = isLong
|
||||
? POSITION_TYPE_SELL
|
||||
: POSITION_TYPE_BUY;
|
||||
double entry = GetEntry(
|
||||
position.symbol,
|
||||
type //
|
||||
);
|
||||
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
|
||||
double volume = position.volume * freezeVolumeMultiplier;
|
||||
|
||||
//
|
||||
XSignal signal;
|
||||
|
||||
//
|
||||
// Prepare Signal ...
|
||||
result = signal.Prepare(
|
||||
position.symbol,
|
||||
position.provider,
|
||||
position.period,
|
||||
type,
|
||||
mode,
|
||||
entry,
|
||||
volume,
|
||||
sl,
|
||||
tp //
|
||||
);
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Generate Comment for Recover and Support ...
|
||||
string comment = GenerateSupportTag(position.ticket);
|
||||
|
||||
//
|
||||
signal.comment = comment;
|
||||
|
||||
//
|
||||
ENUM_X_SIGNAL_EXECUTION_RESULT state;
|
||||
result = ExecuteSignal(
|
||||
signal,
|
||||
state,
|
||||
true // Support Signal need to Ignore Policies ...
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
mData[iDX].freezed = true;
|
||||
|
||||
//
|
||||
string message = "EQM Open " + (IsLong(type) ? "Long" : "Short") + " Freeze Position for (" + ToString(position.ticket) + ")";
|
||||
Alert(message);
|
||||
|
||||
//
|
||||
string comment = "EQM Removes Freezed TP/SL ...";
|
||||
result = mTrader.Modify(
|
||||
position.ticket,
|
||||
0,
|
||||
0,
|
||||
comment //
|
||||
);
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
string message = "EQM Remove Freezed Position (" + ToString(position.ticket) + ") TP/SL ..";
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check Points of Drawdown and Do Partial Closing ...
|
||||
double partialCloseVolume = PartialCloseVolumeInDrawdown();
|
||||
double partialCloseDrawdownPoint = PartialCloseOnSpecificPointOfDrawdown();
|
||||
if (partialCloseVolume > 0 && partialCloseDrawdownPoint > 0)
|
||||
{
|
||||
//
|
||||
double profitPoints = position.GetProfitInPoint();
|
||||
if (profitPoints < 0 && MathAbs(profitPoints) >= partialCloseDrawdownPoint && !mData[iDX].partiallyClosed)
|
||||
{
|
||||
//
|
||||
string comment = "EQM Partial Close ...";
|
||||
|
||||
//
|
||||
// Do Partial Closing ...
|
||||
result = mTrader.ClosePartial(
|
||||
position.ticket,
|
||||
partialCloseVolume,
|
||||
comment //
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
mData[iDX].partiallyClosed = true;
|
||||
|
||||
//
|
||||
string message = "EQM Partially Closed " + ToString(partialCloseVolume) + " of (" + ToString(position.ticket) + ")";
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -100,27 +100,48 @@ input double eaHedgeBEMinProfitPerVolumeStep = 0.1; // Minimum Required Profit F
|
||||
//
|
||||
// Protector > In Profit Positions Protecting ...
|
||||
input group "In Profit Positions Protecting";
|
||||
input bool eaAllowTrailStopInProfits = true; // Allow Trail Stops for In Profit Positions
|
||||
input bool eaOnlyTrailUnprotectedPositions = true; // Only Trail UnProtected Positions
|
||||
input double eaTrailStopStepsInPoint = 10; // Trail Stop Steps in Point
|
||||
input int eaRmoveTPOnTrailStep = 5; // Remove Position TP if Trailed specific times
|
||||
input double eaPartialCloseOnSpecificPointOfProfit = 0; // Partial Close Position on Specific Points of Profit
|
||||
input double eaPartialCloseVolumeInProfit = 0; // Partial Close Volume
|
||||
|
||||
//
|
||||
// Trail ...
|
||||
input group "Trail";
|
||||
input bool eaAllowTrail = true; // Allow Trail Stop for Positions
|
||||
input double eaTrailStartDistance = 35; // Specify Trail Start in Point
|
||||
input double eaTrailStep = 10; // Trail Step in Point
|
||||
input bool eaOnlyTrailUnprotected = true; // Only Trail Unprotected Positionss
|
||||
|
||||
//
|
||||
// Partial Close (In Profit) ...
|
||||
input group "Partial Close";
|
||||
input double eaPartialCloseInProfitDistance = 0; // Specify Partial Close Profit in Point
|
||||
input double eaPartialCloseInProfitVolume = 0; // Specify Partial Close in Profit Volume
|
||||
|
||||
//
|
||||
// Protector > In Drawdown Positions Protecting ...
|
||||
input group "In Drawdown Positions Protecting";
|
||||
input bool eaFreezeInDrawdon = true; // Freeze In Drawdown Position by Lock it
|
||||
input double eaFreezePoint = 100; // Freezing Drawdown Point
|
||||
input double eaFreezeVolume = 2; // Freezing Volume Multiplier
|
||||
input bool eaRemoveFreezedPositionsTPSL = true; // Removes Freezed Positions TP and SL
|
||||
input bool eaAllowRecoverInDrawdowns = false; // Allow Recovery For In Drawdown Positions
|
||||
input double eaRecoveryMultiplier = 1; // Recovery Volume Multiplier
|
||||
input bool eaApplyRecoveryLevelOnVolume = false; // Apply Recovery Level on Volume Calculation
|
||||
input int eaRecoveryDelayInMinute = 1; // Delay Between Two Recovery in Minutes
|
||||
input double eaRecoveryDistanceInPoint = 30; // Distance Between Two Recovery in Point
|
||||
input double eaPartialCloseOnSpecificPointOfDrawdown = 0; // Partial Close Position on Specific Points of Drawdown
|
||||
input double eaPartialCloseVolumeInDrawdown = 0; // Partial Close Volume
|
||||
|
||||
//
|
||||
// Freeze ...
|
||||
input group "Freeze";
|
||||
input bool eaAllowFreeze = false; // Allow Freezing
|
||||
input double eaFreezeDistance = 100; // Specify Freeze Start Drawdown in Point
|
||||
input bool eaRemoveFreezedPositionTPSL = true; // Remove Freezed Positions TPSL
|
||||
input bool eaDisableTrailWhenFreezedPosition = true; // Disable Trail when has Freezed Position
|
||||
|
||||
//
|
||||
// Support ...
|
||||
input group "Support";
|
||||
input bool eaAllowSupport = false; // Allow Support
|
||||
input double eaSupportStartDistance = 0; // Specify Start Support Drawdown in Point
|
||||
input double eaSupportVolumeMultiplier = 1; // Specify Support Volume Multiplier
|
||||
input bool eaMultiplySupportLevelOnVolume = false; // Multiply Support Level on Volume Multiplier
|
||||
input bool eaDoSupportOnConditions = true; // Do Support on Conditions
|
||||
input int eaDelayBetweenTwoSupport = 60; // Delay Between To Support in Second
|
||||
|
||||
//
|
||||
// Partial Close (In Drawdown) ...
|
||||
input group "Partial Close";
|
||||
input double eaPartialCloseInDrawdownDistance = 0; // Specify Partial Close Drawdown in Point
|
||||
input double eaPartialCloseInDrawdownVolume = 0; // Specify Partial Close in Drawdown Volume
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
@@ -483,7 +504,6 @@ bool InitialEA()
|
||||
|
||||
//
|
||||
eaTradeHandler.DelayBarBetweenTwoSameSignal(eaDelayBarBetweenTwoSameSignal);
|
||||
eaTradeHandler.ProtectorStartDistanceInPoint(eaProtectorStartDistanceInPoint);
|
||||
|
||||
//
|
||||
// Configure Hedging ...
|
||||
@@ -495,29 +515,42 @@ bool InitialEA()
|
||||
|
||||
//
|
||||
// In Profit Position Protecting ...
|
||||
eaTradeHandler.AllowTrailStopInProfits(eaAllowTrailStopInProfits);
|
||||
eaTradeHandler.OnlyTrailUnprotectedPositions(eaOnlyTrailUnprotectedPositions);
|
||||
eaTradeHandler.TrailStopStepsInPoint(eaTrailStopStepsInPoint);
|
||||
eaTradeHandler.RmoveTPOnTrailStep(eaRmoveTPOnTrailStep);
|
||||
eaTradeHandler.PartialCloseOnSpecificPointOfProfit(eaPartialCloseOnSpecificPointOfProfit);
|
||||
eaTradeHandler.PartialCloseVolumeInProfit(eaPartialCloseVolumeInProfit);
|
||||
|
||||
//
|
||||
// Protector > In Drawdown Positions Protecting ...
|
||||
eaTradeHandler.FreezeInDrawdon(eaFreezeInDrawdon);
|
||||
eaTradeHandler.FreezePoint(eaFreezePoint);
|
||||
eaTradeHandler.FreezeVolume(eaFreezeVolume);
|
||||
eaTradeHandler.RemoveFreezedPositionsTPSL(eaRemoveFreezedPositionsTPSL);
|
||||
eaTradeHandler.AllowRecoverInDrawdowns(eaAllowRecoverInDrawdowns);
|
||||
eaTradeHandler.RecoveryMultiplier(eaRecoveryMultiplier);
|
||||
eaTradeHandler.ApplyRecoveryLevelOnVolume(eaApplyRecoveryLevelOnVolume);
|
||||
eaTradeHandler.RecoveryDelayInMinute(eaRecoveryDelayInMinute);
|
||||
eaTradeHandler.RecoveryDistanceInPoint(eaRecoveryDistanceInPoint);
|
||||
eaTradeHandler.PartialCloseOnSpecificPointOfDrawdown(eaPartialCloseOnSpecificPointOfDrawdown);
|
||||
eaTradeHandler.PartialCloseVolumeInDrawdown(eaPartialCloseVolumeInDrawdown);
|
||||
// Trail ...
|
||||
eaTradeHandler.AllowTrail(eaAllowTrail);
|
||||
eaTradeHandler.TrailStartDistance(eaTrailStartDistance);
|
||||
eaTradeHandler.TrailStep(eaTrailStep);
|
||||
eaTradeHandler.OnlyTrailUnprotected(eaOnlyTrailUnprotected);
|
||||
|
||||
//
|
||||
// TODO: Implement ...
|
||||
// Partial Close (In Profit) ...
|
||||
eaTradeHandler.PartialCloseInProfitDistance(eaPartialCloseInProfitDistance);
|
||||
eaTradeHandler.PartialCloseInProfitVolume(eaPartialCloseInProfitVolume);
|
||||
|
||||
//
|
||||
// In Drawdown Positions Protecting ...
|
||||
|
||||
//
|
||||
// Freeze ...
|
||||
eaTradeHandler.AllowFreeze(eaAllowFreeze);
|
||||
eaTradeHandler.FreezeDistance(eaFreezeDistance);
|
||||
eaTradeHandler.RemoveFreezedPositionTPSL(eaRemoveFreezedPositionTPSL);
|
||||
eaTradeHandler.DisableTrailWhenFreezedPosition(eaDisableTrailWhenFreezedPosition);
|
||||
|
||||
//
|
||||
// Support ...
|
||||
eaTradeHandler.AllowSupport(eaAllowSupport);
|
||||
eaTradeHandler.SupportStartDistance(eaSupportStartDistance);
|
||||
eaTradeHandler.SupportVolumeMultiplier(eaSupportVolumeMultiplier);
|
||||
eaTradeHandler.MultiplySupportLevelOnVolume(eaMultiplySupportLevelOnVolume);
|
||||
eaTradeHandler.DoSupportOnConditions(eaDoSupportOnConditions);
|
||||
eaTradeHandler.DelayBetweenTwoSupport(eaDelayBetweenTwoSupport);
|
||||
|
||||
//
|
||||
// Partial Close (In Profit) ...
|
||||
eaTradeHandler.PartialCloseInDrawdownDistance(eaPartialCloseInDrawdownDistance);
|
||||
eaTradeHandler.PartialCloseInDrawdownVolume(eaPartialCloseInDrawdownVolume);
|
||||
|
||||
//
|
||||
// Configure Strategies ...
|
||||
@@ -906,6 +939,10 @@ void OnSignalRecieved(
|
||||
{
|
||||
signal.volume = dVolume;
|
||||
}
|
||||
else
|
||||
{
|
||||
signal.volume = eaVolume;
|
||||
}
|
||||
|
||||
//
|
||||
eaTradeHandler.UpdateSignal(signal);
|
||||
|
||||
@@ -7274,7 +7274,7 @@ bool GetTick(
|
||||
/**
|
||||
* Retrieve Tick Entry ...
|
||||
*/
|
||||
double GetTickEnty(
|
||||
double GetTickEntry(
|
||||
MqlTick &mTick,
|
||||
ENUM_POSITION_TYPE type,
|
||||
string mSymbol = NULL //
|
||||
|
||||
Reference in New Issue
Block a user