Positionsize / Position value problem

Hi,

I'm running a backtest with a fixed positionsize for each trade. However, at some point during the backtest the positionsize goes totally wrong and the size gets significantly reduced for no reason. Below is the code, and attached is the trade report list where the sizing goes wrong. What is the problem here? I cannot see any problem in the code at least. The system makes about 12000 trades in a 12 year period if that makes sense.

SetOption("MaxOpenPositions", 1 ); 
prof_x = 0;
tn= TimeNum();
condition1 = Entrycondition
Buy = condition1;
prof_x += BarsSince(Buy) > 0 AND C >= Ref(C,-1);
Sell = prof_x >= 1;

ApplyStop( stopTypeNBar, stopModeBars, 2 );
SetPositionSize(10000,spsValue);

Settings
List
Equity

I'm not sure if that's the problem in this situation but the backtester by default will limit you to trade a maximum of 10% of the daily volume. You can change this in the backtester settings under the portfolio tab:
image

1 Like

Thanks, that solved the problem!

As you might have noticed, what is totally wrong is an assumption that you can trade more than 10% of bar volume without affecting price. AmIBroker does correct thing in limiting users unlimited appetite for absurd profits not achievable in real life due to simple things like liquidity limit. Turning this protection off is not a “solution” but “totally wrong” decision (like throwing out thermometer when you got a fever so you don’t worry about it any more)

5 Likes

Thomas,
It’s very clever of you to have implemented this kind of restriction. In this particular case, the data was FX and the volume unknown. Thanks.

My take is this should be off by default. If people don’t realize they can’t do 1 million contracts on a tick in Ethanol, lol then that’s their problem.

Far worse, IMHO, would be someone looking at a log equity chart and seeing what would appear as a “Technique’s” breakdown and lost consistency, when unbenounced to them, it was just a liquidity limiter.

I imagine all those robust and great techniques that were unknowingly thrown away. :crazy_face:
-S