add guard for protecting Margin ...

This commit is contained in:
2024-06-30 13:11:44 +03:30
parent 821e97d1d7
commit 493820dd41
2 changed files with 41 additions and 1 deletions
+37 -1
View File
@@ -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);
}
}
}
}
//
+4
View File
@@ -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;