void CheckDrawdownActivation()
{
double ddVal = DD_UsePercent ? CalculateDrawdownPercent() : CalculateDrawdownMoney();
double actLvl = DD_UsePercent ? DrawdownActivation : DrawdownActivationMoney;
if(actLvl <= 0) { g_IsActive = true; return; }
if(!g_IsActive && ddVal >= actLvl)
{
g_IsActive = true; g_CycleInProgress = true;
if(UseMainLogic && Main_MagicNumber != 0) StartNewCycle();
}
else if(g_IsActive && !g_CycleInProgress && ddVal < actLvl)
g_IsActive = false;
}
double CalculateDrawdownPercent() { return g_MaxBalance > 0 ? MathMax(0, (g_MaxBalance - AccountEquity()) / g_MaxBalance * 100.0) : 0; }
double CalculateDrawdownMoney() { return MathMax(0, g_MaxBalance - AccountEquity()); }
void ProcessMainLogic()
{
double bal = AccountBalance();
bool reached = Main_UsePercent ? (bal >= g_TargetBalance && g_TargetBalance > 0) : ((bal - g_CycleStartBalance) >= g_TargetProfit && g_TargetProfit > 0);
if(!reached) return;
int wTkt; double wLoss; string wSym; int wType; double wLots;
FindWorstOrder(wTkt, wLoss, wSym, wType, wLots, Main_AllSymbols, Main_MagicNumber);
if(wTkt == -1 || wLoss >= 0) { g_LockedProfit += bal - g_CycleStartBalance; CompleteCycle(); return; }
double excess = Main_UsePercent ? (bal - g_TargetBalance) : ((bal - g_CycleStartBalance) - g_TargetProfit);
if(excess >= MathAbs(wLoss))
{
if(CloseOrderFully(wTkt, wSym, wType, wLots))
{
g_TotalSavedLoss += MathAbs(wLoss);
g_ClosedOrdersCount++;
g_LockedProfit += Main_UsePercent ? (g_TargetBalance - g_CycleStartBalance) : g_TargetProfit;
CompleteCycle();
}
}
}
void StartNewCycle()
{
g_CycleNumber++;
g_CycleStartBalance = AccountBalance();
if(Main_UsePercent)
{ g_TargetBalance = g_CycleStartBalance * (1.0 + SafeProfitPercent / 100.0); g_TargetProfit = g_TargetBalance - g_CycleStartBalance; }
else
{ g_TargetProfit = SafeProfitMoney; g_TargetBalance = g_CycleStartBalance + SafeProfitMoney; }
g_CycleInProgress = true;
}
void CompleteCycle()
{
g_CycleInProgress = false;
double ddVal = DD_UsePercent ? CalculateDrawdownPercent() : CalculateDrawdownMoney();
double actLvl = DD_UsePercent ? DrawdownActivation : DrawdownActivationMoney;
if(UseDrawdownControl && actLvl > 0 && ddVal < actLvl) g_IsActive = false;
else StartNewCycle();
}
void FindWorstOrder(int &tkt, double &loss, string &sym, int &type, double &lots, bool allS, int magF)
{
tkt = -1; loss = 0; sym = ""; type = -1; lots = 0;
for(int i = 0; i < OrdersTotal(); i++)
{
if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if(magF == 0) continue;
if(!allS && OrderSymbol() != Symbol()) continue;
if(magF != -1 && OrderMagicNumber() != magF) continue;
if(OrderType() > OP_SELL) continue;
double pl = OrderProfit() + OrderSwap() + OrderCommission();
if(pl < loss) { loss = pl; tkt = OrderTicket(); sym = OrderSymbol(); type = OrderType(); lots = OrderLots(); }
}
}
Прочитай и пойми сука мой аргумент что ты невъебическое тупое уёбище