PureBytes Links
Trading Reference Links
|
Geary,
Did you use "Cum(1)-1" for 'x' or just "Cum(1)"?
Both the LineArray function and manual line formula work fine for me
(although I only have EOD data so have to test it with months rather
than days).
One oversight with the manual line formula though is that it extends
across the whole chart. To limit it to just between the start and end
bars, mask it like this:
mask = x >= startBar && x <= endBar;
trendLine = IIf(mask, slope*(x-startBar)+startOc, Null);
Regards,
GP
--- In amibroker@xxxxxxxxxxxxxxx, "Geary" <convertah@xxx> wrote:
>
> GP,
>
> Thank you for taking the time to help me with the auto trendline code I
> greatly appreciate it.
> When I first tried your original code for the start and end bars:
>
> startbar = LastValue(ValueWhen(xx, x, 2)); // Yesterday's start bar
> -original
> endBar = LastValue(ValueWhen(xx, x, 1))-1; // Bar before today's start
> bar -original
>
> It gave me a trendline through the (o+c)/2 of yesterdays second bar and
> todays first bar and it was consistent
> with every stock I tried. I finally came up with a modified version that
> produced a trendline through the (o+c)/2
> of yesterdays first and last bar that works with every stock:
>
> startbar = LastValue(ValueWhen(xx, x, 2)-1); // Yesterday's start bar
> -modified
> endBar = LastValue(ValueWhen(xx, x, 1))-2; // Bar before today's
> start bar -modified
>
> The modified code only works with the LineArray function as when I use
> the slope formula it
> gives me a small offset from the (o+c)/2.
>
> I still need more work on this array stuff because the light has not
> gone on quite yet.
> Once again I am grateful for the help.
>
> Thank you,
> Kind regards
>
> Geary
>
> --- In amibroker@xxxxxxxxxxxxxxx, "gp_sydney" <gp.investment@> wrote:
> >
> > One issue I can see is that you choose the start and end bars by
> > comparing their 'y' values to startvalue and endvalue1. If there are
> > multiple bars with the same (O+C)/2 value, then the startbar and
> > endbar formula will find the most recent occurrences, not the ones
> > used to obtain startvalue and endvalue1.
> >
> > It seems to me you're going about this backwards. I'd find the bar
> > numbers first and then their values, not the other way around. You
> > already have the start bars marked in the "xx" array, so to get the
> > actual bar numbers (or array indices), just use something like:
> >
> > x = Cum(1)-1; // Can also use BarIndex();
> > xx = DateNum() != Ref(DateNum(),-1);
> > startbar = LastValue(ValueWhen(xx, x, 2)); // Yesterday's start bar
> > endBar = LastValue(ValueWhen(xx, x, 1))-1; // Bar before today's start
> bar
> >
> > The 'y' values are then just:
> >
> > ocAvg = (O+C)/2;
> > startOc = ocAvg[startBar];
> > endOc = ocAvg[endBar];
> >
> > although you should test both bar values for being in the valid range
> > 0 to BarCount-1 first. You can plot the line the fundamental way using
> > the formula:
> >
> > slope = (endOc-startOc)/(endBar-startBar);
> > trendLine = slope*(x-startBar) + startOc;
> >
> > or just use the LineArray function:
> >
> > trendLine = LineArray(startBar, startOc, endBar, endOc);
> >
> > Note that these plots will only look correct with linear price scale,
> > unless the price range is small. If you're using semilog, then the
> > line formula is:
> >
> > slope = log10(endOc/startOc)/(endBar-startBar);
> > trendLine = startOc*(10^(slope*(x-startBar)));
> >
> > Hope this helps, although note that I haven't actually tried any of
> > this code.
> >
> > Regards,
> > GP
> >
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "convertah" convertah@ wrote:
> > >
> > > 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
> > >
> >
>
------------------------------------
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|