[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re[2]: Trend line syntax



PureBytes Links

Trading Reference Links

Jon,

>AM> ..if you calculate your own trendlines, make sure you do it on
>AM> log(price) instead of price.  Usually tradestation displays
>AM> price charts in log scale (as it should), which means that
>AM> the trendlines, slopes, and extensions are actually being
>AM> calculated on log prices.  Any new price read off the trendline
>AM> is actually the ExpValue of the internal trendline value.
>
>    Find this confusing Alex. If "you calculate your own
>    trendlines" (with values stored in arrays ?) then why use log ?

Because if your chart is a log scale, and you don't do your trenline
calculations with log prices, then the points along the trendline in
between the starting and ending points won't conform to a straight
line, they will curve.  The only way to calculate a true straight
line on a log scale chart is to use log prices in all calculations,
and convert them back to normal prices when displaying them.  This
is what tradestation does internally, which I'll demonstrate.

>    Raw price (which presumably the array values have been produced
>    from) is in itself not log. ie when charting the plots will
>    be appropriate to scaling. The TL_new 's descrided above plot
>    appropriate to scaling.  Can you explain anymore? I've lost the
>    picture somewhere.

If all you care about are the start and end points of the TL, and
nothing in between, and nothing extended to the right, then log
prices don't matter.  If you want to read values of arbitrary
locations on the trendline, then it matters a lot!

Let me demonstrate with a real example.  Soybeans, monthly chart,
log price scale, from 1980 until now.

There is an order of magnitude difference between the highest
and lowest price on this chart (high=2400, low=350), which is
why I chose it to illustrate this example.  The greater the
difference between the top and bottom of the vertical scale, the
more pronounced will be the effect of not using log prices in
calculations.

Okay, now I'll draw a trendline from the 360 price level in January
1993 to the 2300 price level in January 2003.  Can you guess what
price I will read off the middle of the trendline in January 1998?

On a linear price scale, you would think (360+2300)/2, or 1330.
This is indeed what the data window (see View / Data Window)
displays when I put the cursor there.  AND IT'S WRONG!  The midpoint
of the trendline is nowhere near there, on the price scale.  The
cursor (which rounds to the nearest pixel) shows about 908.

If the data window is wrong, what about TL_GetValue?  Does it return
the correct price for the midpoint of the trendline?  Let's see.  I
create the following indicator:

if LastBarOnChart then begin
    value1 = TL_New(930129, 1415, 360, 1030131, 1415, 2300);
    value2 = TL_GetValue(value1, 980130, 1415);
    print(value2);
end;

What gets printed?  910.11.  This is the midpoint of the trendline
on a log price chart.

This is close agreement with the cursor value of 908 (in that region
the pixels on the vertical scale are about 3.3 points apart, so the
cursor can't be more accurate).

The ONLY way tradestation could have come up with that value is
by using log prices to calculate the trendline.

When you call TL_GetValue, the internal calculation that occurs is
based on log prices, that is (log(360)+log(2300))/2, and the final
value is the antilog, or ExpValue, of the result.  I get 909.94,
which is very close.  The 0.17 difference is likely because the bar
midway between the start and end point doesn't correspond exactly to
the date midway between the start and end dates.  These are monthly
bars that occur on the last trading day of each month, so the bars
won't be exactly equally spaced in time.

Conclusions:  (1) The data window displays incorrect values for
trendlines except for the endpoints, when the trendline is drawn on
a log price scale.  (2) Internally, TS uses log prices to calculate
trendline values.  Therefore, if you create functions to manage your
own trendlines, then you should use log prices too, if your chart is
displayed that way.

When using trendlines, the chart scale matters.  Swing points that
line up on a log scale won't line up on a linear scale, and vice
versa.  Generally things tend to change in uniform percentages of
the price, so a log scale seems more appropriate for price displays.
If that's the case, then log prices should be used in calculations
where the relative positions of prices and times matter.

-- 
  ,|___    Alex Matulich -- alex@xxxxxxxxxxxxxx
 // +__>   Director of Research and Development
 //  \ 
 // __)    Unicorn Research Corporation -- http://unicorn.us.com