Minus Minus Risk -> Plus for this code?

 
I would like to check with you to make sure that the net balance and risk code works in both directions

//Maximum amount of money to risk
double moneyToRisk = NormalizeDouble((AccountBalance()-Total_Current_Risk()) * RiskInPercent / 100, 7);

Can Total_Current_Risk() be negative?

that is, the sum of all orderers in plus profit?


double moneyToRisk = NormalizeDouble((AccountBalance() MINUS MINUS -> PLUS? Total_Current_Risk()) * RiskInPercent / 100, 7);




double Total_Current_Risk()
{



double res = 0;
for (int i = 0; i < OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderStopLoss() != 0)
{
double m_point = MarketInfo(OrderSymbol(), MODE_POINT);
double m_lotstep = MarketInfo(OrderSymbol(), MODE_LOTSTEP);
double m_TickValue = MarketInfo(OrderSymbol(), MODE_TICKVALUE);
double m_sl = 0;
if (OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT || OrderType() == OP_BUYSTOP)
{
m_sl = (OrderOpenPrice() - OrderStopLoss()) / m_point;
}
else
{
m_sl = (OrderStopLoss() - OrderOpenPrice()) / m_point;
}
res += NormalizeDouble((OrderLots() (m_sl m_TickValue)) + OrderCommission() + OrderSwap(), 2);
}
}
Print("Account Balance: ", AccountBalance(), " -- Total Current Risk (with swap and commission): ", res, " -- Net Balance: ", AccountBalance() - res);
return res;
}

double sqMMRiskFixedBalancePct(string symbol, int orderType, double price, double sl, double RiskInPercent, int decimals, double LotsIfNoMM, double MaximumLots, double multiplier, double sizeStep) {
Verbose("Computing Money Management for order - Risk fixed % of account balance");



if(UseMoneyManagement == false) {
Verbose("Use Money Management = false, MM not used");
return (mmLotsIfNoMM);
}



symbol = correctSymbol(symbol);
sl = NormalizeDouble(sl, (int) MarketInfo(symbol, MODE_DIGITS));



double openPrice = price > 0 ? price : (orderType == OP_BUY ? sqGetAsk(symbol) : sqGetBid(symbol));
double LotSize=0;



if(RiskInPercent < 0 ) {
Verbose("Computing Money Management - Incorrect RiskInPercent size, it must be above 0");
return(0);
}



double PointValue = MarketInfo(symbol, MODE_TICKVALUE) / MarketInfo(symbol, MODE_TICKSIZE);
double Smallest_Lot = MarketInfo(symbol, MODE_MINLOT);
double Largest_Lot = MarketInfo(symbol, MODE_MAXLOT);
double LotStep = MarketInfo(symbol, MODE_LOTSTEP);


//*******************************************************************************************************
//*******************************************************************************************************
//*******************************************************************************************************

//Maximum amount of money to risk
double moneyToRisk = NormalizeDouble((AccountBalance()-Total_Current_Risk()) * RiskInPercent / 100, 7);

//*******************************************************************************************************
//*******************************************************************************************************
//*******************************************************************************************************



//Maximum drawdown of this order if we buy 1 lot
double oneLotSLDrawdown = NormalizeDouble(PointValue * MathAbs(openPrice - sl), 7);



if(oneLotSLDrawdown > 0) {
LotSize = moneyToRisk / oneLotSLDrawdown;
}
else {
LotSize = 0;
}



LotSize = LotSize * multiplier;



// round computed trade size
LotSize = roundDown(LotSize, sizeStep, decimals);



//--- MAXLOT and MINLOT management



Verbose("Computing Money Management - Smallest_Lot: ", DoubleToStr(Smallest_Lot), ", Largest_Lot: ", DoubleToStr(Largest_Lot),", Computed LotSize: ", DoubleToStr(LotSize));
Verbose("Max money to risk: ", DoubleToStr(moneyToRisk), ", SL:", DoubleToStr(sl), ", One lot drawdown: ", DoubleToStr(oneLotSLDrawdown), ", Point value: ", DoubleToStr(PointValue));



if(LotSize <= 0) {
Verbose("Calculated LotSize is <= 0. Using LotsIfNoMM value: ", DoubleToStr(LotsIfNoMM), ")");
LotSize = LotsIfNoMM;
}



if(LotSize > MaximumLots) {
Verbose("LotSize is too big. LotSize set to maximal allowed value (MaximumLots): ", DoubleToStr(MaximumLots));
LotSize = MaximumLots;
}



//--------------------------------------------



if (LotSize < Smallest_Lot) {
Verbose("Calculated LotSize is too small. Minimal allowed lot size from the broker is: ", DoubleToStr(Smallest_Lot), ". Please, increase your risk or set fixed LotSize.");
LotSize = 0;
}
else if (LotSize > Largest_Lot) {
Verbose("LotSize is too big. LotSize set to maximal allowed market value: ", DoubleToStr(Largest_Lot));
LotSize = Largest_Lot;
}



return (LotSize);
}
 
FX MT4:
I would like to check with you to make sure that the net balance and risk code works in both directions

//Maximum amount of money to risk
double moneyToRisk = NormalizeDouble((AccountBalance()-Total_Current_Risk()) * RiskInPercent / 100, 7);

Can Total_Current_Risk() be negative?

that is, the sum of all orderers in plus profit?


double moneyToRisk = NormalizeDouble((AccountBalance() MINUS MINUS -> PLUS? Total_Current_Risk()) * RiskInPercent / 100, 7);



sounds like, to me that the next step is to debug the code, and then to check that it works how you think it should. We are coders of many levels of experience and skill. We are not mathmaticians! hahahahaha

 
double moneyToRisk = NormalizeDouble((AccountBalance() MINUS MINUS -> PLUS? Total_Current_Risk()) * RiskInPercent / 100, 7);
That is nonsense code. Equivalent nonsense:
double ab = AccountBalance() MINUS MINUS; // Nonsense
(Boolean? Total_Current_Risk()) // Nonsense: B? X : Y
 NormalizeDouble(aValue, 7); // Nonsense there is no money with 7 places