Elementary Inquiry on Codes

To add comments, please log in or register
Ibex Thales
99
Ibex Thales  

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 :)

Mohamad Zulhairi Baba
16412
Mohamad Zulhairi Baba  
Ibex Thales:

return value of 'OrderModify' should be checked

bool OrderModify functionality, is to check on successfulness of your OrderModify.
True - successfully modify.
False - unsuccessfully.
Later, can be use for error checking.

Hope it helps.
Ibex Thales
99
Ibex Thales  
Mohamad Zulhairi Baba:
bool OrderModify functionality, is to check on successfulness of your OrderModify.
True - successfully modify.
False - unsuccessfully.
Later, can be use for error checking.

Hope it helps.

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.

Petr Nosek
3023
Petr Nosek  
Ibex Thales:

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.
Ibex Thales
99
Ibex Thales  
Petr Nosek:
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!

Petr Nosek
3023
Petr Nosek  
Ibex Thales:

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. 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.
  2. Yes
Petr Nosek
3023
Petr Nosek  
Ibex Thales:


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().
Ibex Thales
99
Ibex Thales  
Petr Nosek:
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!

Alain Verleyen
38674
Alain Verleyen  
Petr Nosek:
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().
loool. You are doing WHRoeder job now.
William Roeder
20210
William Roeder  
Ibex Thales:

res = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);

The warning goes away.

What is the difference between the 2?

  1. 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.

  2. 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

  3. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is usually wrong

Petr Nosek
3023
Petr Nosek  
Alain Verleyen:
loool. You are doing WHRoeder job now.
No way! I know how this topic is important to him.


Ibex Thales:

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);
  }
12
To add comments, please log in or register