Problem with StopLoss and Take Profit when either one is 0

 
I wrote an EA for opening market orders with predefined StopLoss and TakeProfit. The default setting is 0 on both, meaning no SL no TP. However, when placing the EA user can enter SL and TP values as inputs. When both are different than 0 (no SL no TP) the EA performs as expected. When entering a value for SL but leaving TP open (0 value) the EA doesn't place the defined SL and vice versa, when TP defined and SL open (0 value) EA doesn't place the TP. In other words if one of them is 0 EA ignores the other value. Is it by MQL definition that both must be defined in order to place them? Seems to me as if one of them is left open (0 value) mql treats both as 0. Need clarification as soon as possible. Thank you for any answer in advance. Cheers
 
cr8or:
I wrote an EA for opening market orders with predefined StopLoss and TakeProfit. The default setting is 0 on both, meaning no SL no TP. However, when placing the EA user can enter SL and TP values as inputs. When both are different than 0 (no SL no TP) the EA performs as expected. When entering a value for SL but leaving TP open (0 value) the EA doesn't place the defined SL and vice versa, when TP defined and SL open (0 value) EA doesn't place the TP. In other words if one of them is 0 EA ignores the other value. Is it by MQL definition that both must be defined in order to place them? Seems to me as if one of them is left open (0 value) mql treats both as 0. Need clarification as soon as possible. Thank you for any answer in advance. Cheers
Without code we can not say anything.
 

You need to add the if statement for the 0 value for SL or TP ... You need to do something like the following ...

double GetStopLossBuy() { if(SL==0) return(0); else return(Bid-SL*Point);} 
double GetStopLossSell() { if(SL==0) return(0); else return(Ask+SL*Point); } 
double GetTakeProfitBuy() { if(TP==0) return(0); else return(Ask+TP*Point); } 
double GetTakeProfitSell() { if(TP==0) return(0); else return(Bid-TP*Point); } 
Reason: