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
- Market Execution - Opening and Closing Positions - Trade - MetaTrader 5 for Android
- Request Execution - Opening and Closing Positions - Trade - MetaTrader 5 for Android
- Placing Pending Orders - Trade - MetaTrader 5 for Android
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.
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
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); }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register