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
I attach file already, Please help me.
<attached file removed : decompiled code>
Trifecta.
I attach file already, Please help me.
<attached file removed : decompiled code>
I see many, many people posting code and asking questions which can usually be answered by simply checking the return values from a few Functions and printing out any relevant errors. So I thought I would make a post specifically about this subject so that I can simply link to it in the future . . . .
What are Function Return values ?
The information in this post is mainly talks about the trading functions (<-- this is a link, please click it !) . . . but what is written will also apply to any other mql4 function that returns a value.
A Function, just like a variable, has a type, for example, int, double, string, void, bool, any type other than void returns a value, the type of the value returned depends on the type that the function is declared as . . . . so a function declared as type bool will return a bool value, true or false
An example:
bool OrderSelect ( int index, int select, int pool=MODE_TRADES )
The OrderSelect() function is declared as type bool so it returns a bool value as either true or false
An example:
int OrderSend ( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)
The OrderSend() function is declared as type int so it returns a value that is an integer, this integer is the ticket number if the OrderSend function has worked correctly, if it encountered an error the returned integer is set to -1.
How do we use these Return values ?
Where a function returns a bool, such as OrderSelect(), we can use code such as this to check if the function worked or did not work . . .
Where a function returns an int, such as OrderSend(), we can use code such as this to check that the function worked and report an error to the logs if it did not work . . .
. . . or a more concise version without using the intermediate variable TicketNumber . . .
In either version, if the OrderSend() fails for whatever reason, the error number will be printed to the log and, if running in the Strategy Tester the error will also be visible in the Journal tab, if running Demo or Live the error will be visible in the Experts tab.
When a function isn't performing as expected, for example orders are not being placed, the log or the Journal/Experts tab can be looked at and any errors will be easily seen, a quick analysis of the relevant error will then allow you to correct the issue with your code or code logic.
Link to this thread: What are Function return values ? How do I use them ?
Maybe you should include OrderDelete() and OrderModify() too, just in case. :)
Don't worry, I already know how to handle those two above. :)
Maybe you should include OrderDelete() and OrderModify() too, just in case. :)
Don't worry, I already know how to handle those two above. :)
Don't forget other functions such as ObjectCreate() . . .
Got that covered already. :)
I used to have a warning of:
returned value of 'OrderSelect' should be checked
you can do something like:
I used to have a warning of:
returned value of 'OrderSelect' should be checked
. . . do what ? what do you want to do if it's true ? more importantly what do you want to do if it failed and it's false ? don't you want to know that it failed ? don't you want to know what the error was ?and the variables being used at the time ?
RaptorUK,
In this instance I was hoping the order would simply close. I had already told my EA exactly what I want it to look for so if it doesn't close then it would be because it didn't see what I'm looking for yet. The EA itself has a stoploss of 100 pips and takeprofit of 300 pips which wont be disqualified for slippage, spread, or most other kinds of pip alteration. If for some reason the order couldn't close due to unmatched data or something then the journal would post the error. So in this case I'm just trying to close the order.
gjol,
I tried your suggestion and I got the same warning: empty controlled statement found. Then I realized I should remove the first semicolon
Everything is working good. Thank you