# Exploration for MA crossover

#### amitrandive

##### Well-Known Member
Dear All

I need an exploration for Moving averages 10,20 and 89 to be within 1% of the security price.Please help.

Thanks
Amit

#### manojborle

##### Learner
m1 = MA(C, 10);
m2 = MA(C, 20);
m3 = MA(C, 89);
d = 0.01*C;
Cond1 = C - d;
Cond2 = C + d;

Filter = m1 > Cond1 AND m1 < Cond2
AND
Filter = m2 > Cond1 AND m1 < Cond2
AND
Filter = m3 > Cond1 AND m1 < Cond2;

AddColumn(C,"Close within 10, 20 & 89 SMA", colorBlue);

Check this afl if it is okay....
Do reply I am also learning afl programming

#### manojborle

##### Learner
Looks like it is not working...
I will try to find out where I am making mistake

#### manojborle

##### Learner
m1 = MA(C, 10);
m2 = MA(C, 20);
m3 = MA(C, 89);
d = 0.01*C;
Cond1 = C - d;
Cond2 = C + d;

Filter = m1 > Cond1 AND m1 < Cond2
AND
Filter = m2 > Cond1 AND m1 < Cond2
AND
Filter = m3 > Cond1 AND m1 < Cond2;

AddColumn(C,"Close within 10, 20 & 89 SMA", colorBlue);

Check this afl if it is okay....
Do reply I am also learning afl programming

m1 = MA(C, 10);
m2 = MA(C, 20);
m3 = MA(C, 89);
d = 0.01*C;
Cond1 = C - d;
Cond2 = C + d;

Filter = m1 > Cond1 AND m1 < Cond2
AND
Filter = m2 > Cond1 AND m2 < Cond2
AND
Filter = m3 > Cond1 AND m3 < Cond2;

AddColumn(C,"Close within 10, 20 & 89 SMA", colorBlue);

found the mistake I just copy pasted filter and forgot to change variables m1 to m2 and m3.
Problem solved now and now it is working

#### amitrandive

##### Well-Known Member
Manoj

Thanks , Works very well .

Thanks
Amit
:clapping:

#### amitrandive

##### Well-Known Member
Manoj

Can we plot this condition on the Chart also?

Also can we get a buy condition when the price crosses above the 89 period EMA and a sell when the price crosses below the 89 period EMA?

Thanks
Amit

#### manojborle

##### Learner
Manoj

Can we plot this condition on the Chart also?

Also can we get a buy condition when the price crosses above the 89 period EMA and a sell when the price crosses below the 89 period EMA?

Thanks
Amit
Plot this condition means ?
Do you want to plot moving averages on chart ?
we can get buy and sell condition
I will put the code

#### amitrandive

##### Well-Known Member
Manoj

Yes , I want a plot of this and an arrow for buy and sell with the current exploration.

Thanks
Amit