Hello and good day,
I have been trying to write a formula that will draw an automatic
trendline through the, (O+C)/2, of the first and last five minute
candles of yesterday. I'm new to AFL and had fun trying to get this far,
which was only accomplished by searching mail archives,the users guide,
knowledge bases and, even the "new" googlesearch.

The trendline works perfectly on some stocks but other stocks will have
the line through one but not both of the candles; while other stocks
show no connection with the trendline at all.

Thoughts on how to make this really work would be greatly appreciated.

This is the code:

x = Cum(1);

xx =  DateNum() !=Ref (DateNum(),-1);

startvalue = LastValue(ValueWhen( Ref (xx,79), (O+C)/2,1 ));     /*
(O+C)/2   of first bar of yesterday */
endvalue1 = LastValue(ValueWhen( Ref (xx,1), (O+C)/2,1 ));        /*
(O+C)/2   of last bar of yesterday */

startbar = LastValue( ValueWhen( (O+C)/2 == startvalue, x, 1 ) );
endbar = LastValue( ValueWhen( (O+C)/2 == endvalue1, x, 1 ) );

Aa = (endvalue1-startvalue)/(endbar-startbar);
b = startvalue;

trendline = Aa * ( x  - startbar ) + b;

Plot( Close, "Price", colorBlue, styleCandle );
Plot( trendline, "Trendline", colorRed );

Thank you,
Kind regards

Geary



Reply via email to