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

Re: needing help and advice on maxbarsback



PureBytes Links

Trading Reference Links

At 8:18 AM +0200 4/4/01, Bengtsson, Mats wrote:

>I have a great number of studies that deliver data to other programs
>using fileappends. When doing this, it seems that a maxbarsback
>setting of auto makes the data a little less reliable, and also must
>cause a lot of calculation overhead. (My belief is that a maxbarsback
>of auto just means Tradestation first tries with a low number, when
>it hits a problem with that number it increases maxbarsback and then
>tries again). This is correct? Anyone know the algorithm for how it
>increases maxbarsback?

You are basically correct. Usually, for simple indicators it only has
to make one trial run to find how many bars back the study references
then sets the value and makes the final run. If you include a "Print"
statement to print on LastBarOnChart = TRUE, you will see it print
twice, once for the trial run and once for the final run.

But some times the number of bars back can depend upon the data. An
example is in the following code:

    Avg = Average(Close, 50);
    for j = 0 to 1000 begin
       n = j;
       if Close[n] > Avg then j = 1001;
    end;
    LastHigher = Close[n];

It might do a trial run and find a value, then set this value and do
another runs and find it needs a bigger value, etc. The MaxBarsBack
setting would have to be 1000 to avoid any possible problems.

>Now, when I am planning to change this setting, I am afraid of
>causing errors that I do not have today.

You probably have errors today since the results you get depend upon
a variable you are not controlling.

>The manual recommends to always set it to at least 50. Why? I can not
>see any good reason?

It is best to set the value for indicators the same as you have for
any systems trading the same data. This way the two will give the
same results. The default for systems is 50 so that is probably why
they suggest 50 for indicators.

>If using the workchart assistant for scanning a lot of stocks and
>having a maxbarsback setting that is too low, will I ever get an
>error message telling me if maxbarsback is too low? Or will I just
>have a number of indicators that did not deliver data for some
>stocks? Or was even turned off? Anyone could give me some hints on
>this?

Try to have a lot more bars than you need and start the calculations
for all stocks on the same day:

   if Date > 1/1/1995 then begin
      <put calculations here>
   end;

Then set the MaxBarsBack setting to some value, such as 50, and make
sure you have at least 50 days of data prior to 1/1/1995. If you get
error messages you know it is not enough bars back.

This will at least give consistent results.

If you are requiring far more bars back than you would like, you can
always store the values in arrays and then refer to past values as
values in the array. This can make the the required MaxBarsBack
setting a small value if you are careful. Recoding the above example
(code not tested so could have a bug...):

    Vars: Count(0);
    Array: CVal[1000](0);

    Count = iff(Count < 1000, Count + 1, 1000);  {Increment count}

    CVal[Count] = Close;                       {Save Close values}
    Avg = Average(Close, 50);

    for j = 0 to 1000 begin
       n = Count - j;                {Calculate location in array}
       if n >= 0 then                   {Check if array in bounds}
          if CVal[n] > Avg then j = 1001;
    end;
    LastHigher = CVal[n];

This works for up to 1000 bars but only requires a MaxBarsBack
setting of 50 to calculate the Average. Above 1000 bars you could use
techniques to reuse the 1000 bar array in a circular buffer (to avoid
having to move values in the array) but this gets a bit more
complicated.

Bob Fulks