iMA() problem

 

I want to compare yesterday’s MA value with today’s MA value. I have set the MAs as follows:

Today’s MA

SMAnow = iMA(NULL, 0, SlowerSMA, 0, MODE_SMA, PRICE_CLOSE, 1);

Yesterday’s MA

SMAprevious = iMA(NULL, 0, SlowerSMA, 0, MODE_SMA, PRICE_CLOSE, 1+1);

I have coded – if(SMAprevious < SMAnow, xx,xx);

Have I correctly set up the two SMAs? The results make me doubtful.

I would appreciate someone to help me with this.

Regards,

KeithN

 

I have coded – if(SMAprevious < SMAnow, xx,xx);

What's this supposed to do?

 

I'm pretty new to this, but I'm guessing you're looping through the bars and if so you'll want i (or whatever you used to increment your loops) as opposed to hard coding 1 and 1+1.... So, I think you probably want more like : iMA(NULL, 0, SlowerSMA, 0, MODE_SMA, PRICE_CLOSE, i);

iMA(NULL, 0, SlowerSMA, 0, MODE_SMA, PRICE_CLOSE, i+1);


And, as phy pointed out, not sure what that if line is trying to do, don't think mql supports what you have there.

 

Thank you for your responses. My replies to you both are somewhat delayed as my time zone is 16 hours ahead of the USA.

I am attempting to compare this bar’s MA value with the previous bar’s value of the same MA to determine whether the MA is going up or down. A setup will depend upon this.

I realise I have made a couple of typos. 1+1 should be i+1. Like wise 1 should be i in the SMAnow text.

The coding should be if

(SMAprevious<SMAnow)

Setup == 1;

My further researches tell me the last fully formed bar should be i+1 and the previous bar should be i+2. Is my understanding correct?

Many thanks for your help.

KeithN.

Reason: