Print your value and check why.
I tried that already and both moving averages have a value.
This is a example of what it printed:
EURUSD,H1: Sell Conditions
EURUSD,H1: Sell 1true
EURUSD,H1: Sell 2false
I tried that already and both moving averages have a value.
This is a example of what it printed:
EURUSD,H1: Sell Conditions
EURUSD,H1: Sell 1true
EURUSD,H1: Sell 2false
sell_condition_2 = (1.088302857142855 < 1.088302380952381) : false
It's correct.
Though you have only difference on 7th decimal.
sell_condition_2 = (1.088302857142855 < 1.088302380952381) : false
It's correct.
Though you have only difference on 7th decimal.
I don't understand then where I could be wrong. It shows that 7 period MA is always higher than the 21 period MA. How can this be? It is averaged out so it should definitly be possible for the 21 to be higher than the 7 at some point.
I just want it to sell when 7 MA < 21 MA and buy when 7 MA > 21 MA
I don't understand then where I could be wrong. It shows that 7 period MA is always higher than the 21 period MA. How can this be? It is averaged out so it should definitly be possible for the 21 to be higher than the 7 at some point.
I just want it to sell when 7 MA < 21 MA and buy when 7 MA > 21 MA
If you want to sell when fast is less than slow and buy when fast is greater than slow, with your conditions you are always going to be either selling or buying on each and every bar regardless of the previous state. You should consider using only crosses instead.
PS: it is not showing that 7 period MA is always higher than 21 period MA (at least at my terminal it does not). It works as expected. Check the rest of your code for some accidental assignment
If you want to sell when fast is less than slow and buy when fast is greater than slow, with your conditions you are always going to be either selling or buying on each and every bar regardless of the previous state. You should consider using only crosses instead.
PS: it is not showing that 7 period MA is always higher than 21 period MA (at least at my terminal it does not). It works as expected. Check the rest of your code for some accidental assignment
Thank you for your response Mladen! I managed to figure out the problem.. really simple actually, I had the IMA declarations before my OnTick() loop so the two MA values were stuck as the same numbers for the whole loop everytime.
I actually have another buy and sell condition that is the main focus of my EA. I just added the MA condition so that I protect against losses incase of a heavy upward or downward trend.
Thanks for the help and advice!
- 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'm having trouble with one of my sell signals.
The buy signal works perfect but when I turn it around for a sell signal it gives me a False statement the whole time.
double MA2L15 = iMA(NULL,15,21,0,MODE_SMA,PRICE_CLOSE,0);
bool buy_condition_2 = (MA1L15 > MA2L15);
bool sell_condition_2 = (MA1L15 < MA2L15);
Has anyone encountered this before?
Thanks in advance!
Anton