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

Re: Help please, with maxsharesheld syntax



PureBytes Links

Trading Reference Links

> I want to backtest a particular strategy with $100,000 initial
> investment 100% of account balance used in each trade.   I thought
> the proper language was: 
> example... If C > O then buy maxsharesheld shares this bar at close; 
> This however, only serves to stop the entire strategy from 
> functioning.

MaxSharesHeld (assuming it's the same as MaxContractsHeld in TS4) 
tells you the largest position you've held so far.  At the start of 
your test it will be zero.  Since you're telling it to buy zero 
shares, you will never have a position, and MaxSharesHeld will always 
be zero.

You want something like this:

  Inputs:  AcctSize(100000);
  Vars:  PosSize(0);
  
  PosSize = (AcctSize + NetProfit + OpenPositionProfit) 
                / (BigPointValue * Close);
  
  if C > O then buy PosSize shares at close;

AcctSize is your starting account size.  NetProfit is the total 
*closed* profits so far, and OpenPositionProfit is your profit on any 
current trade.  So the first term is your current account size 
assuming you close the current trade on that bar.  Divide it by the 
Closing price times the BigPointValue (which should be 1 for stocks) 
and you'll have the proper position size.

Gary