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

Equity Curve indicator, v1.01



PureBytes Links

Trading Reference Links

A while back I posted an Equity Curve indicator for TS4, based on 
another indicator Bob Fulks provided.  I've made a few minor changes 
and improvements to it:

* The indicator plots & prints the equity for every day, week, month, 
trade, whatever you specify.  The old indicator used a numeric input 
to determine the period.  I could never remember what number meant 
what, so I changed it to accept "D", "W", "M", "T", etc.

* Often I find myself looking at the equity curve and wondering "When 
did that drawdown happen?"  I wanted a simple way to find out.  So I 
added a "commentary" feature.  Click on the Expert Commentary icon in 
TS4, click on the bar in question, and it will display the date and 
the equity for that bar.

* I fixed a small bug.  The indicator was supposed to plot & print 
the ending equity at the end of a period.  Instead, it reported the 
equity at the START of the next period.  That caused slightly wrong 
results e.g. if you got stopped out by a gap-open at the start of a 
new period.  

Source is appended below.  Source and ELA are available at my FTP 
site, ftp://ftp.frii.com/pub/fritz -- look for the files eqcurve.txt 
and eqcurve.ela.

Gary


{
   Equity Curve
   Version 1.01  11/9/99

     This indicator plots bars of closed equity on a periodic basis
     on the last 200 bars of a chart. If your system test contains more
     than 200 trades or periods, it only plots the last 200.

     Winning periods plot green bars, losing periods plot red bars,
     and flat periods plot dark gray bars.

     The number of periods plotted is determined by the variable "Size," 
     which may be changed. If you increase it, set the size of the array 
     "EQ" and the "MaxBarsBack" value larger than or equal to the value 
     of "Size". 

     Also prints each period's ending equity, and change in equity, 
     to the Print Log.

     To find the date at a particular equity spike or dip, select the
     "Expert Commentary" icon in TS4, and click on the desired bar.

   Inputs:
     Period:  Sampling period 
              ("T"=per trade, "Y"=yearly, "Q"=quarterly, "M"=monthly, 
               "W"=weekly, "D"=daily)

   Gary Fritz
   (Thanks to Bob Fulks for the idea I "borrowed" :-)
}

Inputs: Period("W");

Vars:  Equity(0), EndEq(0), LastEq(0);
Vars:  Mo(0), Countr(0), J(0), K(0), CE(0), Size(200), Last(0);
Vars:  Per(0), P1(0), P2(0), P3(0), P4(0);
Array: EQ[200](0);

{ Determine the desired period, print the proper header, and
  set Per to the appropriate value.  Why use Per?  Because if I
  compare Period to "T", "Y", etc on every bar, the indicator runs
  TWICE as slowly! }

if (BarNumber = 1) then begin
  if Period = "T" then begin print("Per-trade profit:"); Per = 0; end;
  if Period = "Y" then begin print("Yearly profit:"); Per = 1; end;
  if Period = "Q" then begin print("Quarterly profit:"); Per = 2; end;
  if Period = "M" then begin print("Monthly profit:"); Per = 3; end;
  if Period = "W" then begin print("Weekly profit:"); Per = 4; end;
  if Period = "D" then begin print("Daily profit:"); Per = 5; end;
  end;

Mo = Month(Date);
Equity = I_ClosedEquity;

{ If our chosen period has expired, record the end-of-period equity }

if  ((Per = 0) and (Equity <> Equity[1]))
 or ((Per = 1) and (Year(Date) <> Year(Date[1])))
 or ((Per = 2) and (Mo <> Mo[1]) and (Mo=1 or Mo=4 or Mo=7 or Mo=10))
 or ((Per = 3) and (Mo <> Mo[1]))
 or ((Per = 4) and (DayOfWeek(Date) < DayOfWeek(Date[1])))
 or ((Per = 5) and (Date <> Date[1]))
then begin
  if Per = 0 then EndEq = Equity
             else EndEq = Equity[1];
  if (LastBarOnChart = False) then
    print(Date[1]:6:0,",",EndEq:7:2,",",EndEq-LastEq:7:2);
  LastEq = EndEq;
  EQ[Countr] = EndEq;
  Countr = Mod(Countr + 1, Size);       { Move pointer in buffer         }
  end;

{ On last bar, plot the last Size periods of equity }

if LastBarOnChart then 
  for J = 0 to Size - 1 begin           { Loop to plot bars              }
    K = Mod(Countr + J, Size);          { Calc pointer into buffer       }
    P1 = 0; P2 = 0; P3 = 0; P4 = 0;
    if (J > 0) then begin               { Set J=0 bar to 0 to "erase" it }
      if EQ[K] < Last then P1 = EQ[K];  { Plot losing periods in red     }
      if EQ[K] > Last then P2 = EQ[K];  { Plot winning periods in green  }
      if EQ[K] = Last then P3 = EQ[K];  { Plot flat periods in dark gray }
      P4 = EQ[K];
      end;
    Plot1[Size - 1 - J](P1,"ClosedEq");
    Plot2[Size - 1 - J](P2,"ClosedEq");
    Plot3[Size - 1 - J](P3,"ClosedEq");
    Plot4[Size - 1 - J](P4, "");        { Plot white line at top of histogram }
    Last = EQ[K];
    end;

#BeginCmtryOrAlert
if AtCommentaryBar then begin
   Commentary(newline + "Date:   " + NumToStr(Date,0) + newline + "Equity: " + NumToStr(Equity,2));
end;
#end