spsPercentOfEquity query

Hi

I would be grateful for some help with spsPercentOfEquity.

My scenario is...

  1. I set a buy limit some distance below the LOW of the signal bar.
  2. I enter a trade on the following bar if price is less or equal to my buy limit.
  3. I want position size calculated against my original buy limit.

The problem I have is...

If price gaps down and opens below my buy limit, I want to enter the trade at this OPEN price but still have position size calculated on the original buy limit.

I find that CBT will use the HIGH of the trade bar in this scenario and will also calculate position size based on the HIGH price.

I can supply my code but thought I'd start with the concept first...

Thanks in advance.
Tim.

@timhopson, there are several issues to contend with here. First, you need to use the correct entry price. Let's assume that you want to place a limit order 1% below the prior bar's low. You need something like this:

LimitPrice = Ref(L,-1) * 0.99;
BuyPrice = min(LimitPrice, Open);

Next, if you want the position size to be calculated from the limit price rather than the actual entry price, then you need to modify your SetPositionSize call a bit. For example, to size your position at 5% of equity:

SetPositionSize(5 * BuyPrice/LimitPrice, spsPercentOfEquity);

Also make sure that you have used

SetOption("UsePrevBarEquityForPosSizing", True);

if you're trying to simulate live trading where you place orders before the market opens.

Finally, depending on your strategy, your backtest may be producing unrealistic results if it's possible for your strategy to generate more orders than you have capacity to accommodate. Please read through this entire thread carefully to see if it applies to you: PositionScore / Ranking for trades taken “next day at limit”

1 Like

Hi Matt, thank you for this. The bit that really helped was including...

* BuyPrice/LimitPrice

in the position size calculation. It solved my problem, thanks.

1 Like