Why different number of trades when there is no error in info tab

Hello guys :slight_smile:

Could you please help me clarify why the following code produce different number of trades (depending on PositionSize).
The thing is I don't see the following error if the positionsize is the problem:
Notice 802: Trade size limit of 10% of entry bar volume has been hit N times. Check your Settings 'Portfolio' tab, position sizing

Thank you in advance!

SetOption("MaxOpenPositions", 100);
SetOption("AllowSameBarExit", False);
SetTradeDelays(1,1,1,1);

// Set the risk per share and position risk as before
RiskPerShare = 2 * ATR(20);
PositionRisk = 0.1;

// Calculate the position size for long and short trades separately
PctSizeLong = PositionRisk * BuyPrice / RiskPerShare;
PctSizeShort = PositionRisk * ShortPrice / RiskPerShare;

// Set different position sizes for long and short trades using conditional statements
// If it's a long trade, use PctSizeLong; otherwise, use PctSizeShort

BuyPrice = Open;
SellPrice = Open;
ShortPrice = Open;
CoverPrice = Open;

value_optimize = Optimize("std_refDays", 360, 5, 365, 10);
priceReturn = abs(C - Ref(C, -1));
hisSTD = abs(ln(StDev(priceReturn,365,True))); //standard deviation for the past 365 days
std = ln(StDev(priceReturn,value_optimize,True));

Buy = C >= HHV(C, 10) AND std <= 1.01*hisSTD and C >= MA(C,200);
Sell = C <= LLV(C, 10);

Short = C <= LLV(C,10) AND std >= 1.02*hisSTD;
Cover = C >= HHV(C, 5);

//Here if we test wuth dufferebt PositionSizes we produce different number of trades
//SetPositionSize( IIf(Buy, PctSizeLong, IIf(Short, PctSizeShort, 0)), spsPercentOfEquity );
//SetPositionSize(1, spsPercentOfEquity );

@manovgeorgi, in general, the best approach to understand the cause is to use the
the Detaileg Log, from the Report tab of the Analysis settings dialog:

image

It will tell you precisely what signals are generated each and every bar, what are the position scores and when / why some signals are ignored (due to constraints such as insufficient funds), equity, cash, etc.

2 Likes

In addition to the sage advice from @beppe on how to track down the issue, I will note that it's likely that one of your position sizing methods is causing you to run out of capital more frequently than the other method. This is particularly common with risk-based position sizing, where a non-volatile instrument (small ATR) can result in very large position values.

As a side note, since pctPosSizeLong and pctPosSizeShort are based on BuyPrice and ShortPrice, respectively, the pctPosSize* assignments should logically come after the BuyPrice and ShortPrice assignments, not before.

2 Likes

Thank you guys.
It was really helpful from your side.
I understand now where to check all signals / errors and what causing them!