return value of 'OrderModify' should be checked
bool OrderModify functionality, is to check on successfulness of your OrderModify.
But will it be ok if the code is written as:
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
?
Coz if I turn it into
bool res;
res = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
The warning goes away.
What is the difference between the 2?
Thank you. Your response is deeply appreciated.
But will it be ok if the code is written as:
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
?
Coz if I turn it into
bool res;
res = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
The warning goes away.
What is the difference between the 2?
Thank you. Your response is deeply appreciated.
You can use function that returns a value (in this case bool) like a function that doesn't return a value (void) without possibility checking returned value. But in your case you should check what the OrderModify() returns.
1. Does that mean that both aforementioned examples will modify the order? The difference is that putting the "bool res" line gives the added use of being able to check whether the order modification had been successful or not.
Please correct me if I am accurate in my understanding.
2. Just a clarification. Is VOID the only data type that does not not return a value? All other types seem to.
Thanks!
1. Does that mean that both aforementioned examples will modify the order? The difference is that putting the "bool res" line gives the added use of being able to check whether the order modification had been successful or not.
Please correct me if I am accurate in my understanding.
2. Just a clarification. Is VOID the only data type that does not not return a value? All other types seem to.
Thanks!
- Yes, you got it. Except: Both aforementioned examples will try to modify the order and if you use the returned parameter (res) you can see the result.
- Yes
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
When @whroeder1 wakes up, he will post here warning about using NormalizeDouble() in setting SL and TP. You should use Tick Size adjustment instead of NormalizeDouble().
Is that so? Then I shall wait until @whroeder1 wakes. I am still in the process of understanding the codes generated by online EA generators. Manners on how to streamline the processes and reduce the runtime will be very much appreciated.
Thanks Petr!
When @whroeder1 wakes up, he will post here warning about using NormalizeDouble() in setting SL and TP. You should use Tick Size adjustment instead of NormalizeDouble().
res = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
The warning goes away.
What is the difference between the 2?
- None, all you did was hide the warning.
Check your return codes for errors, and report them.
Don't just silence the compiler, it is trying to help you.
What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after. - When you post code please use the CODE button (Alt-S)!
(For large amounts of code, attach it.) Please edit your post.
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor -
Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't
use it. It's use is usually wrong
- Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 and MetaTrader 4 - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 and MetaTrader 4 - MQL4 programming forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 and MetaTrader 4 - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 and MetaTrader 4 - MQL4 programming forum
- Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
loool. You are doing WHRoeder job now.
Is that so? Then I shall wait until @whroeder1 wakes. I am still in the process of understanding the codes generated by online EA generators. Manners on how to streamline the processes and reduce the runtime will be very much appreciated.
Thanks Petr!
The adjusting Price, SL and TP could be like this:
double NormalizePrice(const double price,string symbol=NULL) { if(price<0.0) return(0.0); if(symbol==NULL || symbol=="") symbol=_Symbol; double tickSize=SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE); return(round(price/tickSize)*tickSize); }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi.
I would just like to inquire regarding boolean functions, particularly the OrderModify.
I understand that OrderModify is a boolean function, returning TRUE/FALSE, upon execution. I was thinking that this is a test whether the Order has been successfully Modified or not.
However, I was surprised to see it as follows:
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
upon using a Code Generator online. Does this mean that other than being a function that checks something, booleans can be made to actually DO something?
I saw the error message:
return value of 'OrderModify' should be checked
though the code runs perfectly otherwise.
I tried looking up at boards, guides, and other literature but to no avail. They might be too deep for my understanding, or I may have missed out a programming basic.
Thank you in advance for your clarifications!
P.S. I am not a programmer. Yet. I have tried, and still am trying hard. Really :)