Is this Good practices for if else statement

 

Hello,


Instead of using classic if-else or nested if-else i am using like this for small conditions

double TakeProfit_BuyEntry = (TP != 0) ? (Ask + TP * Pips) : 0;

double BuyLimitOrderDifference = LastOrderPrice(OP_BUY, BuyLimitMagic) - LastOrderPrice(OP_BUYLIMIT, BuyLimitMagic);

double LotChecking1 = (Increase_Type == Multiplication) ? NormalizeDouble(LastOrderLot(OP_BUY, BuyLimitMagic) * DiMarti, LotDigit) : NormalizeDouble(LastOrderLot(OP_BUY, BuyLimitMagic) + DiMarti, LotDigit);

string t_style = (Trading_Strategy == Custom) ? "Custom" : (Trading_Strategy == MartingaleHedging_TrailingTP) ? "Martingale + Hedging + Trailing TakeProfit" : (Trading_Strategy == MartingaleHedging_TrailingSL) ? "Martingale + Hedging + Trailing StopLoss" : (Trading_Strategy == Scalping_TP) ? "Scalping + Take Profit" : (Trading_Strategy == Scalping_TrailingSL) ? "Scalping + Trailing StopLoss" : (Trading_Strategy == News_Trading) ? "News Trading + Trailing StopLoss" : "Unknown";

This working fine without any issue in MQL4 EA. can i continue to use like this or should i change all this to classic if-else.

 
You are free to choose.
 

Personally, I think it's better to avoid multiple ternary operators (linked to each other).

Instead of multiple "if-elseif-elseif-..." I can suggest you use a switch (if we are talking about integer types). The switch operator is much faster than multiple "if-elseif-elseif-..."

Reason: