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

Re: On the first bar, how to access the last bar?



PureBytes Links

Trading Reference Links

There are two approaches to this problem.

You can store all the values you will need for the calculation at the
last bar on the chart in arrays and then do the calculation from the
data in the arrays.

Alternately, you can accumulate the partial results as you go through
the data and then do the final calculation at the end using the
partial results.

As a simple example, assume you wanted the average values of all the
closing prices on all bars.

   Vars: Sum(0), Count(0), Ave(0);

   Sum = Sum + Close;
   Count = Count + 1;

   if LastBarOnChart and Count <> 0 then
      Ave = Sum / Count;

Bob Fulks
---

At 7:26 AM -0700 9/17/02, Traktor Topaz wrote:

>   This is probably simple, but it's eluded me so far:
>
>   I wish to go through the bars of a given contract, performing some
>statistical calculations, looking to see how often something happens. But
>before I run through the bars I need to know one simple thing about the
>last and next-to-last bars.
>
>   As a (simplified) example, let's say that today (the last bar on the
>chart) the open is so-much higher/lower than yesterday's open, and now I
>want to run through all the bars and count up how often that is the case.
>So I'd like code like this:
>
>   If currentbar > 1 then begin
>
>	OpenPosition = Open[lastdayonchart] - Open[nexttolastdayonchart];
>
>	if open[today] blah-blah open[yesterday] then add-some-stuff-up.
>
>	if lastbaronchart then plot1( results, 'results' );
>
>   end;
>
>   The part that's eluded me so far is how, on the first (or second) bar of
>the chart to find out how many bars  exist in this chart so as to access
>the last-bar and next-to-last-bar on the chart.
>
>   Can someone point me at the answer?
>
>-- Arthur Cronos, Fairfax California
>
>PS: Does anybody else find the TS 'help' system for looking up commands to
>be inferior to a printed book which organizes similar commands together?
>Does anyone else think that for $95 a month, those folks could send a
>printed book?
>
>
>
>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>         MOBIUS MEGATAR TAPPING BASSES 
>'Making Music Easier'   http://www.megatar.com
>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/