To retrieve the bar's value crossing 2 MA - Aussie Stock Forums

# Thread: To retrieve the bar's value crossing 2 MA

1. ## To retrieve the bar's value crossing 2 MA

Lol !!

I tried to retrieve a bar's value wich is crossing above my MA10 ...

Without success the "cross" function gives only the value 1, true or 0.

What is the good way?

Here is what I have done.

First attempt

Code:
```Curve1= 0 ;
Curve2 = 0;
Curve1 = Cross(MA(C,10),MA(C,30)); // gives only 1 , true or false?!
Curve2= Ref(Cross(WMA(C,10),MA(C,30)),80);```
2nd attempt

Code:
```a= 0;
b= 0 ;

for(i=0;i<BarCount;i++)
{
if (MA(C,10) = MA(C,30))  //the formula to see a cross but there is a bug
{
a = MA(C,30);
b = Ref(MA(C,30,80);// I need to retrieve the value 80 days ago .
}
else
{
a = 0;
b =0 ;
}
}```

2. ## Re: To retrieve the bar's value crossing 2 MA

Assuming this is AmiBroker, use the ValueWhen function:

ma30 = MA(C,30);
curve1 = Cross(MA(C,10),ma30);
a = ValueWhen(curve1, ma30);
b = ValueWhen(curve1,Ref(ma30,-80));

GP

3. ## Re: To retrieve the bar's value crossing 2 MA

Thanks exactly what I need !

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Aussie Stock Forums