How to plot a strategy equity line against a price chart?

Questions about MultiCharts and user contributed studies.
SiliconTiger
Posts: 24
Joined: 21 Feb 2009

How to plot a strategy equity line against a price chart?

Postby SiliconTiger » 20 Aug 2009

In MultiCharts, how can I plot the equity line of a strategy I have developed against the price chart?

And a related question, how do I get the current equity position in a strategy (GrossProfit and GrossLoss give me the gross profit and loss respectively, but how do I get my equity position)?

Thanks.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: How to plot a strategy equity line against a price chart

Postby TJ » 20 Aug 2009

In MultiCharts, how can I plot the equity line of a strategy I have developed against the price chart?

use the PositionProfit keyword.
you will need a variable to store the running equity.

since you cannot use plot in a strategy, you have to use TL_NEW.


And a related question, how do I get the current equity position in a strategy (GrossProfit and GrossLoss give me the gross profit and loss respectively, but how do I get my equity position)?
Thanks.

go to your PowerEditor

View> Navigator Bar

the Studies/Dictionary will show up.

half way down the middle of the screen, you will see 2 tabs,

click on the Dictionary tab

then select Strategy Position


you will see all the relative keywords there.

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 20 Aug 2009

I just use the "Strategy Equity" indicator from TS2ki. (now supported in MC)

Plot1(I_OpenEquity, "OpenEquity");
Plot2(I_ClosedEquity, "ClosedEquity");
Plot3(0, "ZeroLine");

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Postby TJ » 20 Aug 2009

found this in my collection:

Code: Select all

[LegacyColorValue = TRUE];

{
Equity Curve Date
Version 1.02 12/9/99
Gary Fritz

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.
The indicator also plots the date associated with each bar,
in the format YYMM.DD (or YYYMM.DD for year>=2000). This allows you
to see exactly when equity peaks, drawdowns, etc happened by looking
at the "Date" value associated with a particular bar.

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.

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

(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);
Array: EQ[200](0), EQDate[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! String ops are sloooowww in EL... }

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 begin EndEq = Equity; EQDate[Countr] = Date / 100; end
else begin EndEq = Equity[1]; EQDate[Countr] = Date[1] / 100; end;
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;
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 }
end;
Plot1[Size - 1 - J](P1,"ClosedEq");
Plot2[Size - 1 - J](P2,"ClosedEq");
Plot3[Size - 1 - J](EQ[K],"ClosedEq"); { Plot white line at top of histogram }
Plot4[Size - 1 - J](EQDate[K], "Date"); { Plot date for this bar }
Last = EQ[K];
end;

SiliconTiger
Posts: 24
Joined: 21 Feb 2009

Postby SiliconTiger » 20 Aug 2009

Thanks all for your suggestions.

The problem with using "PositionProfit" is that it only provides the profit (or loss) by position, but does not include into account he initial capital. Similarly, with I_ClosedEquity & I_OpenEquity, once the first trade is taken these will track the overall equity position but they also don't take into account the initial capital.

Under "Strategy Properties" for a given signal, you can set the initial capital in the "Init Capital" field. I would like to be able to utilize this field for example to calculate how many shares to buy for the first trade. If I can access the initial capital somehow, then calculating the actual equity at any given time is simply: InitialCapital + I_ClosedEquity + I_OpenEquity. But how do I get the value for initial capital?

Thanks!

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Postby SUPER » 21 Aug 2009

Thanks all for your suggestions.

The problem with using "PositionProfit" is that it only provides the profit (or loss) by position, but does not include into account he initial capital. Similarly, with I_ClosedEquity & I_OpenEquity, once the first trade is taken these will track the overall equity position but they also don't take into account the initial capital.

Under "Strategy Properties" for a given signal, you can set the initial capital in the "Init Capital" field. I would like to be able to utilize this field for example to calculate how many shares to buy for the first trade. If I can access the initial capital somehow, then calculating the actual equity at any given time is simply: InitialCapital + I_ClosedEquity + I_OpenEquity. But how do I get the value for initial capital?

Thanks!

Try to declare InitalCapital in your code.

Input: InitialCapital (10,000);

Value1= InitialCapital + I_ClosedEquity + I_OpenEquity;

SiliconTiger
Posts: 24
Joined: 21 Feb 2009

Postby SiliconTiger » 21 Aug 2009

Try to declare InitalCapital in your code.

Input: InitialCapital (10,000);

Value1= InitialCapital + I_ClosedEquity + I_OpenEquity;
Yes, that's one way to do it. Seems the "right" (i.e. elegant) way would be to have some way to grab the value that's specified in the "init capital" field, either from the signal settings in the chart window or from the backtester. If there's no way to access the value from these fields, what's the use of the "init capital" field in the chart window and/or backtester?

Thanks.

User avatar
Andrew Kirillov
Posts: 1589
Joined: 28 Jul 2005
Has thanked: 2 times
Been thanked: 31 times
Contact:

Postby Andrew Kirillov » 10 Sep 2009

If there's no way to access the value from these fields, what's the use of the "init capital" field in the chart window and/or backtester?
It is used in many calculatons inside backtesting engine and performance report.


Return to “MultiCharts”