Hi guys,
I've made a simple code to buy when the price is above the moving average and sell is the price is below the moving average everytime that there is no position open. I checked the backtest and saw that the code is not performing as I wanted and only performs buy trades. I printed the moving average value to make sure that the buy signal is really triggered only if the price is above the MA value. The moving average value printed in the journal tab is very different from the one that is displayed in the chart:
Here's my short code:
Appreciate if anyone could help me solve this issue, probably I'm not using the iMA() function correctly?
Thanks in advance!:D
The problem might be in your 'main' function here
long dir; dir=ORDER_TYPE_BUY; OpenPosition(dir); ClosePosition(dir); TrailingPosition(dir,m_ts); dir=ORDER_TYPE_SELL; OpenPosition(dir); ClosePosition(dir); TrailingPosition(dir,m_ts);
Assuming this is your source, or you acquired it legally, try this
dir=CheckSignal(true);
OpenPosition(dir); ClosePosition(dir); TrailingPosition(dir,m_ts);
The problem might be in your 'main' function here
Assuming this is your source, or you acquired it legally, try this
Hi ssn,
I think this will solve the problem for the order types, but do you know how I can fix the wrong MA value being displayed?
Thank you very much!
- www.mql5.com
Hi ssn,
I think this will solve the problem for the order types, but do you know how I can fix the wrong MA value being displayed?
Thank you very much!
Hi Polymath,
For the incorrect MA value I may not be of much help because I actually use the standard library class CiMA and I have now forgotten (or am out of touch) with the first principles initialization of an indicator. However you could try tweaking the MA setting of Set as Series... beyond that I cannot help much besides encouraging you to also use CiMA... :-)
Hi Polymath,
For the incorrect MA value I may not be of much help because I actually use the standard library class CiMA and I have now forgotten (or am out of touch) with the first principles initialization of an indicator. However you could try tweaking the MA setting of Set as Series... beyond that I cannot help much besides encouraging you to also use CiMA... :-)
Hi Polymath,
I wonder if you managed to find a solution to your problem. As I understand it, you're getting a difference to what's displayed on the graph & what's being
returned to you in the program. I have a similar problem in that my returned values for high,low,open & close values (MqlRates mrate[];) & entirely different from from the
ones displayed on the graph. Consequently, I find that the EA behaves randomly & erracticly producing erronous results. Thus I'm searching this forum
to see if anybody else has experienced similar problems.
If anybody else has found this type of bug, please feel free to comment. I want to be able to make progress & this issue has completely stopped me in
my tracks.
Thanks in advance.
- www.mql5.com

- 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 guys,
I've made a simple code to buy when the price is above the moving average and sell is the price is below the moving average everytime that there is no position open. I checked the backtest and saw that the code is not performing as I wanted and only performs buy trades. I printed the moving average value to make sure that the buy signal is really triggered only if the price is above the MA value. The moving average value printed in the journal tab is very different from the one that is displayed in the chart:
Here's my short code:
Appreciate if anyone could help me solve this issue, probably I'm not using the iMA() function correctly?
Thanks in advance!:D