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
If you are getting, zero for "SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL)", then there is no "Stops Level" in play.
In the code above, you don't seem to be checking if the Stop Orders are actually away from current prices or not. Don't assume they are. Check, that the stop order is above current Ask price for buys, and below current Bid for sell orders.
Show as actual log entries for the errors, where all the data is properly reported.
Add "debugging" to your code. Print out details to the log, such as current bid & ask, entry, stop-loss and take profit for the order, the trade result error code, etc.
Not quite 100%, but you are getting a much better understanding of enumerations. Suffice to say that you should always use the enumerations for the "indexing" and not their value. Don't ever hard-code the "indexing" values (i.e.use "SYMBOL_TRADE_STOPS_LEVEL" and not "31").
EDIT: Please show your updated code with all the updates you have made in accordance with the requirements outlined in the article.
Hi again Fernando,
Below you will find the updated code as well as an attached log file. I have tried to take in all that you have said. Please let me know if I have still made some errors. I no longer get invalid price in the logs.
I am confused why print seems to display the data just fine but doing printformat just shows zeros for everything.
Edit: I apologize that the print statements are becoming a bit unkempt. Will address this in further updates going forward and once I figure out why Print works but not PrintFormat.
When you use the CopyRates function, you don’t check the results and any errors. You just assume that it returns the data without question.
You are not using a “magic number”, so your EA will not play “nicely” with other EAs or even itself on other timeframes. You are just assuming that your EA is the only one working on the current symbol.
You are not checking whether the entry price is valid for the pending order. I even posted an image showing the conditions required for the entry price. For a buy stop order, the entry must be above the Ask + Stops-Level, and for a sell stop order, it must be below the Bid - Stops-Level. You have not implemented it.
Remember that buy orders open at Ask and close at Bid, and sell orders open at Bid and close at Ask. Look at the image posted.
Considering the points above, you are also not checking the Stop-Loss and Take-Profit according to those rules. If the distance between the Entry and Stop-Loss (or Take-Profit) is smaller than the spread at the time it is triggered, it might be immediately closed when it is triggered.
We have not touched yet on position sizing (volume) and risk calculation, but I will assume you will address all that in the future.
There are also several other points that you have not addressed, such as filling mode, maximum deviation (slippage), etc. but I will leave that for you to research on your own.
As for PrintFormat, please read the documentation, as %d is for integer values, not floating-point values.
When you use the CopyRates function, you don’t check the results and any errors. You just assume that it returns the data without question.
You are not using a “magic number”, so your EA will not play “nicely” with other EAs or even itself on other timeframes. You are just assuming that your EA is the only one working on the current symbol.
You are not checking whether the entry price is valid for the pending order. I even posted an image showing the conditions required for the entry price. For a buy stop order, the entry must be above the Ask + Stops-Level, and for a sell stop order, it must be below the Bid - Stops-Level. You have not implemented it.
Remember that buy orders open at Ask and close at Bid, and sell orders open at Bid and close at Ask. Look at the image posted.
Considering the points above, you are also not checking the Stop-Loss and Take-Profit according to those rules. If the distance between the Entry and Stop-Loss (or Take-Profit) is smaller than the spread at the time it is triggered, it might be immediately closed when it is triggered.
We have not touched yet on position sizing (volume) and risk calculation, but I will assume you will address all that in the future.
There are also several other points that you have not addressed, such as filling mode, maximum deviation (slippage), etc. but I will leave that for you to research on your own.
As for PrintFormat, please read the documentation, as %d is for integer values, not floating-point values.
Just catching up and wanted to say thank you for all you do for the community and elevating others. Its very much appreciated.
When you use the CopyRates function, you don’t check the results and any errors. You just assume that it returns the data without question.
You are not using a “magic number”, so your EA will not play “nicely” with other EAs or even itself on other timeframes. You are just assuming that your EA is the only one working on the current symbol.
You are not checking whether the entry price is valid for the pending order. I even posted an image showing the conditions required for the entry price. For a buy stop order, the entry must be above the Ask + Stops-Level, and for a sell stop order, it must be below the Bid - Stops-Level. You have not implemented it.
Remember that buy orders open at Ask and close at Bid, and sell orders open at Bid and close at Ask. Look at the image posted.
Considering the points above, you are also not checking the Stop-Loss and Take-Profit according to those rules. If the distance between the Entry and Stop-Loss (or Take-Profit) is smaller than the spread at the time it is triggered, it might be immediately closed when it is triggered.
We have not touched yet on position sizing (volume) and risk calculation, but I will assume you will address all that in the future.
There are also several other points that you have not addressed, such as filling mode, maximum deviation (slippage), etc. but I will leave that for you to research on your own.
As for PrintFormat, please read the documentation, as %d is for integer values, not floating-point values.
Hi Fernando,
I appreciate these 8 points that you have sent me. As I mentioned this is a barebones EA to show the issue we were having without tons of clutter and hundreds of lines of code. As for #3, #5, #7, #8 I will work to address these and see where I end up. Thank you very much for your help. I do apologize for any confusion that may of occurred with some of your listed points above.
Thank you again!