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

Re: EasyButNotDocumentedLanguage DLL Questions ;^)



PureBytes Links

Trading Reference Links

At 8:49 PM -0500 12/12/98, David Wieringa wrote:

>1) In several places there is reference to "circular buffer". Can someone
>give me a context to put this in? I understand the concept of a circular
>buffer, but what is it being used for? I don't see it documented anywhere.


Below is some code I recently posted to "The Code" list. (ELA and GIF files
omitted) It uses a "circular buffer" (which I called a "ring buffer"). The
idea is to save the most recent 200 trades.

The straightforward approach would be to store the data in an array and,
when a new trade occurs, move the previous values and store the most recent
value at the top of the array. This requires moving 199 values for every
new value, a very slow process.

The ring-buffer approach just puts the new value in the next location in
the array, wrapping back around when you get to the end (hence the name
"ring"). Then, when you need to access the values, you need to start at the
most recent entry, which is somewhere in the middle of the array. The trick
is to keep track of the location in the array.

This technique is commonly used in programming.

Bob Fulks

---------------------

Mime-Version: 1.0
Date: Fri, 20 Nov 1998 18:01:14 -0500
To: "Code List" <code-list@xxxxxxxxxxxxx>
From: Bob Fulks <bfulks@xxxxxxxxxxxx>
Subject: CL_Equity Profile Indicator

In the spirit of sharing code, below is one indicator I use all the time.

It plots bars of closed equity after each trade of a system at the right
hand side of the screen. You can use it get an idea of how a trading system
works on a variety of different markets by simply paging through a sequence
of markets in TradeStation or SuperCharts. Since the plot is at the right
side of the screen, you don't have to move back in time to see old trades.
There are no inputs.

See the attached GIF file as an example of its use. The lower plot shows
the equity of each trade as a bar.

It is very fast as it keeps values in a ring buffer to avoid having to move
data around.

I find it very useful. Hope you will.

The code is below. The next message will contain the ELA file.

(Nice to have a list where you can include pictures!)

Bob Fulks


{ *******************************************************************

  Indicator    : Equity Profile

  Last Edit    : 9/22/97

  Provided By  : Bob Fulks

  Description  : This indicator plots bars of closed equity for each
     trade of a system on the last 200 bars of a chart. If more than
     200 trades, it only plots the last 200 trades. The first bar is
     cyan to note the beginning of the plot.

     The number of trades plotted is the variable "Size" which may
     be changed. If changed, set the size of the array "ACE" and the
     "MaxBarsBack" equal to the value of "Size".

     In the unlikely event that the change in equity of a trade is
     exactly zero, the trade will not be recorded. To avoid this, set
     commissions to some odd value such as $95 or $0.0001 for zero.

     The indicator is a recoding, for greater speed, of the indicator
     shown in the TS Express Newsletter of Jul/Aug 1996. It uses a
     ring buffer instead of shifting the array on each new point.

     © 1997 Robert G. Fulks. All rights reserved.

********************************************************************}
Vars:  Countr(0), J(0), K(0), CE(0), Size(200), Last(0);
Array: ACE[200](0);

CE = I_ClosedEquity;
if CE <> CE[1] then begin             {If equity changes           }
   ACE[Countr] = CE;                  {Save new value              }
   Countr = Mod(Countr + 1, Size);    {Move pointer in buffer      }
end;

if LastBarOnChart then begin
   for J = 0 to Size - 1 begin        {Loop to plot bars           }
      K = Mod(Countr + J, Size);      {Calc pointer                }

      if ACE[K] < Last then           {Plot losers in red          }
         Plot1[Size - 1 - J](ACE[K],"ClosEquity");

      if ACE[K] > Last then           {Plot winners in green       }
         Plot2[Size - 1 - J](ACE[K],"ClosEquity");

      Last = ACE[K];
      Plot4[Size - 1 - J](0, "Zero"); {Plot baseline               }
   end;
   Plot3[Size - 1](ACE[Countr],"End");{Plot leftmost bar           }
end;