![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
A couple of comments...
Print() https://docs.mql4.com/common/Print and GetLastError() https://docs.mql4.com/check/GetLastError are your friends, make plenty of use of them.
You can use print to check that each variable is calculating the way you expect it to.
Personally, I think it is easier to read your code if you calculate your signals seperate from your trading logic, then print the variables as a check and then run your trading logic. I would calculate the two MA's as seperate variables...when you are happy everything is calculating properly, you can then delete or // the print statements.
On your two MA's, you are calculating the MA's on different timeframes. That is fine of course, but I just wanted to check that is what you mean to do. The convention imho, would be that variables called MAfast and MAslow would refer to the number of bars to be used for the average (ie period) rather than timeframe. It is perhaps just the name that is throwing me.
So on your trading criteria.... you should use GetLastError() after your ordersend. You will see then that the Sell is failing with probably error code 129-Invalid Price. You are trying to Sell at the Ask. You sell at the Bid. Also as a comment, you switch from testing with Bid in the first if's (to set posture) to using Ask. All indicators are calculated using bid and particularly with variable spread brokers you may get undesirable results by switching your analysis between Bid and Ask.
To give you the idea... buy would be like this...
follow the same approach for sell (and remeber you sell on Bid not Ask).
Lots more stuff to do, like only sending 1 order rather than an order every tick (as will happen here) ....https://docs.mql4.com/trading/OrdersTotal
and closing orders...read this https://www.mql5.com/en/forum/126647
Anyway, hope the above helps
V
Sounds great to be able to print things as I go. That is what I need to see exactly what is hape4ning. The only problem is where can I find the file that has the output of the print command?. I am unable to find it.
Or even Comment() to get it right up there on the chart
V
I thougt for sure that I would not be writing for a while be it looks like I have got to the heart of the problem. Whenever we assign a moving average to a variable and then print it the result is 0 out to about 6 decimal points. Why is that happening?
Hmm, well something is up... not sure what would cause this... are you running it on a realtime chart or back testing... if backtesting do you have enough history loaded (ie have you got 20 past bars to look at) Would probably need to see the latest code to comment further.
Anyone else any ideas?
V
Well, I just applied this script and it worked fine. I then opened an exotic symbol that I hadn't opened before and replicated the 0.000. I then changed to 1min timeframe allowed it to update history applied the script and it worked fine.