add guard for protecting Margin ...
This commit is contained in:
@@ -5289,7 +5289,43 @@ protected:
|
||||
|
||||
//
|
||||
// Additional Works on Force States ...
|
||||
// TODO: Complete this ...
|
||||
|
||||
//
|
||||
double drawdown = GetDrawdownPercent();
|
||||
double margin = mTrader.mAccount.GetMargin();
|
||||
double callMargin = mTrader.mAccount.GetMarginCall();
|
||||
double stopoutMargin = mTrader.mAccount.GetMarginStopOut();
|
||||
|
||||
//
|
||||
double workingMargin = MathMax(callMargin, stopoutMargin) * 0.75;
|
||||
|
||||
//
|
||||
// Checking Call Margin ...
|
||||
if (drawdown > workingMargin)
|
||||
{
|
||||
//
|
||||
int maxInDPIDX = FindMaxDrawdownIndex(
|
||||
positions //
|
||||
);
|
||||
if (IsValidIndex(maxInDPIDX))
|
||||
{
|
||||
//
|
||||
// We Close Max In Drawdown Position to Guard Account ...
|
||||
const comment = XEQMSupportToken + " Close Max Due Guard ...";
|
||||
bool isClosed = Close(
|
||||
positions[maxInDPIDX].ticket,
|
||||
comment //
|
||||
);
|
||||
if (isClosed)
|
||||
{
|
||||
//
|
||||
string message = XEQMSupportToken + " Close Position (" + ToString(positions[maxInDPIDX].ticket) + ") Due Guard Account ...";
|
||||
|
||||
//
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -154,6 +154,10 @@ int OnInit()
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
double call = x121EA.mTrader.mAccount.GetMarginCall();
|
||||
double stopout = x121EA.mTrader.mAccount.GetMarginStopOut();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
|
||||
Reference in New Issue
Block a user