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

Equity Curve indicator



PureBytes Links

Trading Reference Links

I've always been annoyed by TradeStation 4.0's lack of a decent 
equity curve display.  The "System Equity" indicator does a good job 
of giving you a micro-level look at your equity, but only for as many 
bars as will fit on a chart.  You can't see the equity history of 
your entire system test.

A while ago Bob Fulks posted an "Equity Profile" indicator that 
plotted a nice equity curve in the last 200 bars of a chart.  Bob's 
indicator plots equity on a per-trade basis.

I like to see equity on a calendar-time basis, so I expanded Bob's 
indicator.  Depending on the value of the input "Period," you can 
plot an equity curve on a per-trade, yearly, monthly, weekly, or 
daily basis.  The indicator also prints (to the Print Log) the 
current closed equity and the change in equity during the past 
period, suitable for importing into a spreadsheet.  This new 
indicator is called "Equity Curve".

Here is the source.  ELA is attached.  You can also get it from my 
FTP site, ftp://ftp.frii.com/pub/fritz, under "eqcurve.ela" or 
"eqcurve.txt".

Enjoy,
Gary



{
   Equity Curve:  
     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 trades plotted is determined by the variable "Size," 
     which may be changed. If you increase it, set the size of the array 
     "CE" 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 Print Log.

   Inputs:
     Period:  Sampling period 
              (0=per trade, 1=yearly, 2=quarterly, 3=monthly, 4=weekly, 5=daily)

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

Inputs: Period(4);

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

if (BarNumber = 1) then begin
  Per[0] = "Per-Trade"; Per[1]  = "Yearly"; Per[2] = "Quarterly";
  Per[3] = "Monthly";   Per[4] = "Weekly";  Per[5] = "Daily";
  print;
  print(Per[Period] + " profit:");
  end;

Mo = Month(Date);
Equity = I_ClosedEquity;

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

if  ((Period = 0) and (Equity <> Equity[1]))
 or ((Period = 1) and (Year(Date) <> Year(Date[1])))
 or ((Period = 2) and (Mo <> Mo[1]) and (Mo=1 or Mo=4 or Mo=7 or Mo=10))
 or ((Period = 3) and (Mo <> Mo[1]))
 or ((Period = 4) and (DayOfWeek(Date) < DayOfWeek(Date[1])))
 or ((Period = 5) and (Date <> Date[1]))
then begin
  if (LastBarOnChart = False) then
    print(Date[1]:6:0,",",Equity:7:2,",",Equity-LastEq:7:2);
  LastEq = Equity;
  EQ[Countr] = Equity;
  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;


Attachment Converted: "c:\eudora\attach\EqCurve.ela"