Individually sized dynamic positions in multiple tickers

Hi,

I appologize if this has been answered before or is a trivial question. I have searched and could not find an answer.

I wish to enter 3 different tickers depending on lookback momentum criteria. For each lookback period a ticker has positive returns, 10% more of the portfolio is to be allocated up to a maximum of 40%. The remaining is to be allocated to IEI. I have 3 arrays with this dynamic allocation size, the sum of these is 100%.

for (i=1;i<=4;i++)
{
 SPYa = SPYa + (0<ROC(Foreign("SPY", "Close"),5*i))*10;
 TMFa = TMFa + (0<ROC(Foreign("TMF", "Close"),5*i))*10;
}
IEIa = 100 - SPYa - TMFa;

Now, how do I buy these dynamic position sizes? I have attempted the following:

Buy = (DayOfWeek()==5); // Buy on Friday open
BuyPrice = Open;
Sell = (DayOfWeek()==4); // Sell on Thursday close (simple rebalancing - to be improved)
SellPrice = Close;

Foreign("SPY", "O", 1);
SetPositionSize(SPYa,spsPercentOfEquity);
Foreign("TMF", "O", 1);
SetPositionSize(TMFa,spsPercentOfEquity);
Foreign("IEI", "O", 1);
SetPositionSize(IEIa,spsPercentOfEquity);

The above buying does not work, can it be modified to work or should this rather be solved using scale in or possibly rotational trading with position score?

Best regards

The code you have posted is wrong.
Foreign returns price of foreign symbol. It does NOT change current symbol.

Analysis is performed in multiple threads for multiple DIFFERENT symbols in parallel!
You don't change the symbol yourself.

Instead you should check current symbol Name() and set everything you want accordingly to current symbol.

To get different position size for different symbols you should simply use code like this:

switch( Name() )
{
  // the code below will set different sizes depending on symbol Name()
   case "SPY": SetPositionSize( SPYa, spsPercentOfEquity );
               break;
   case "TMF": SetPositionSize( TMFa, spsPercentOfEquity );
               break;
   case "IEI": SetPositionSize( IEIa, spsPercentOfEquity );
               break;
   default: SetPositionSize( 10, spsPercentOfEquity );
               break;
}

The code above assumes that you have created and assigned appropriate values to SPYa, TMFa and IEIa arrays.

2 Likes

Really appriciate the response. This conditional position sizing code seems to work well. I was not aware of the very useful Name() function.

Now I have to improve the rebalancing part, only sell if my currently owned allocation of X ticker is more than what X ticker should be allocated.

Is there a function to check amount/value of specific open tickers?
For example as such:
Sell = (DayOfWeek()==4) AND OpenIEIa>IEIa;
Where OpenIEIa is the current open portfolio allocation of IEI [%]
And IEIa is the array of desired allocation 0-100 [%]

1 Like
1 Like

Many thanks for pointing out which is the most proper way to do it. I appreciate it.

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.