Why is it still taking trades when equity is negative!?

Questions about MultiCharts and user contributed studies.
smhuggins
Posts: 12
Joined: 15 Mar 2015
Has thanked: 1 time

Why is it still taking trades when equity is negative!?

Postby smhuggins » 12 Aug 2015

Hi all,

I feel like I am missing something. I am running portfolio backtests using a strategy (and have not included the specific code, only the code relevant to what I am trying to solve).

My initial portfolio capital is 20k, trading ASX shares on daily bars. Only going long, with zero margin, risking 1% of equity per trade.

The problem I am facing is in portfolio backtester, it generates many trades for me, and generates more than 50 trades that send me into -$50k. It places trades when my total equity is thousands of dollars negative, even though I don't have the money to take them!

I want the strategy to STOP making any trades as soon as my equity hits $0.

Does anyone have any ideas...??

Code: Select all


input: double Capital( 20000 ) ;
Input: minEquity (5000);
Var: Equity (0) ;
Equity = Capital + NetProfit + OpenPositionProfit ;

if marketposition = 0
and Equity > minEquity
then
Buy ( "MACrossLE" ) vShares Shares next bar at market ;

My vShares calculation is based on Van Tharp's CPR model, and Equity = Capital + NetProfit + OpenPositionProfit

ANY help would be greatly appreciated!

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: Why is it still taking trades when equity is negative!?

Postby tony » 12 Aug 2015

You may want to try pulling out the conditional for entry based on equity value to the start of your script, something like:

IF Equity > MinEquity

Then Begin

rest of your code

End;

So when the script is first calculated, if equity is <= MinEquity, the rest of the script will be ignored including the section that generates trades, up to the end;

That may help resolve what's going on. I assume in posting your code, you left out more of the conditionals to generate a long or short signal.

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: Why is it still taking trades when equity is negative!?

Postby tony » 12 Aug 2015

Something else to try is print out the value of equity by putting the following at the bottom of your script

print(equity);

This way you can see if the value you think is being calculated is actually calculated the way intended.


Return to “MultiCharts”