It should print Buy Order => Error Code : and Sell Order => Error Code : but it printing invalid takeprofit for OrderSend function and invalid stoploss for OrderSend function
you have not shown what the sl or tp variables are, or your code for gRandomSymbols, or your gRandomLots, however, I think that both the calculations you have above need to be normalised or trancated to number of the symbols digits. Any number that goes beyond the symbols digits will cause those errors.
OrderSend_TakeProfit = (TakeProfit > 0) ? MarketInfo(gRandomSymbol, MODE_BID) - MathMax(TakeProfit, gStopLevel) * Point : 0
assigning varialbes inside like this will not work. this could be reason for the errors also. instead remove the OrderSend_TakeProfit =.
Same goes for OrderSendStopLoss =... remove this and just leave the boolean statement.
you have not shown what the sl or tp variables are, or your code for gRandomSymbols, or your gRandomLots, however, I think that both the calculations you have above need to be normalised or trancated to number of the symbols digits. Any number that goes beyond the symbols digits will cause those errors.
assigning varialbes inside like this will not work. this could be reason for the errors also. instead remove the OrderSend_TakeProfit =.
Same goes for OrderSendStopLoss =... remove this and just leave the boolean statement.
ternary operator working fine inside Orderfunction. Can you answer my second question, why it not printing error message defined by me if Orderfunction return false/error?
anuj71:
if(!OrderSend(/*...*/)) Print("Sell Order => Error Code : " + GetLastError());
It should print Buy Order => Error Code : and Sell Order => Error Code : but it printing invalid takeprofit for OrderSend function and invalid stoploss for OrderSend function
-1 is true or false, what do you think?
https://docs.mql4.com/trading/ordersend
Returned value
Returns number of the ticket assigned to the order by the trade server or -1 if it fails.
Reading documentation always help. https://docs.mql4.com/trading/ordersend
OrderSend do not return true or false. You are using bool operator for an integer returned value.

- docs.mql4.com
-1 is true or false, what do you think?
I got it. I was not aware of. I thought it will give true or false.
OrderSend do not return true or false. You are using bool operator for an integer returned value.
Is this correct?
if(OrderSend(gRandomSymbol, OP_BUY, gRandomLotSize, MarketInfo(gRandomSymbol, MODE_ASK), Slippage, OrderSend_StopLoss = (StopLoss > 0) ? MarketInfo(gRandomSymbol, MODE_ASK) - MathMax(StopLoss, gStopLevel) * Point : 0, OrderSend_TakeProfit = (TakeProfit > 0) ? MarketInfo(gRandomSymbol, MODE_ASK) + MathMax(TakeProfit, gStopLevel) * Point : 0, gTradeComment, gBuyMagic, 0, clrNONE) < 0)
Print(Buy Order => Error Code : " + GetLastError());
Is this correct?
if(OrderSend(/*...*/) < 0) Print("Buy Order => Error Code : " + GetLastError());
This should work. Although, I, for example, strictly compare with -1. I don't know which option is better, they are probably the same.
https://docs.mql4.com/trading/ordersend
Returned value
Returns number of the ticket assigned to the order by the trade server or -1 if it fails.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am frequently getting two error invalid takeprofit for OrderSend function and invalid stoploss for OrderSend function.
Question 1 :
I am getting these error in Expert tab not in Journal tab. If order-send is failed, then it should show in Journal tab right?
Question 2 :
I am checking error with OrderSend function but instead of printing error from my code rules it printing invalid takeprofit for OrderSend function & invalid stoploss for OrderSend function
It should print Buy Order => Error Code : and Sell Order => Error Code : but it printing invalid takeprofit for OrderSend function and invalid stoploss for OrderSend function