Australian (ASX) Stock Market Forum

To retrieve the bar's value crossing 2 MA

Joined
10 October 2008
Posts
14
Reactions
0
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 ;
}
}
 
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
 
Top