Hello everyone and thank you in advance for any help you can provide. I have a rotational system that maintains 4 positions on a monthly basis. Right now they are balanced 25% each. I would like to balance by equalizing their ATR. For example if Stock 1 has ATR(10) = 10 and stock 2 has ATR(10) of 5, I would like the rotation to buy 2 share of stock 2 for every one share of stock 1. This equalizes my exposure in terms of price movement. I would need the code to use position score to identify the four stocks for this rotation, then read each of those 4 stock's ATR(10) and then allocate the portfolio to balance this to as close as 100% exposure as possible. Where I am stuck is referencing the 4 selected stocks in the code to pull the atr so I can balance it.
Here is the base code:
SetOption("InitialEquity", 100000); totalPositions =4; SetOption("MaxOpenPositions", totalPositions); SetOption("AllowPositionShrinking", True ); SetPositionSize(100/ totalPositions, spsPercentOfEquity); SetOption("AllowSameBarExit", True ); SetOption("HoldMinBars", 1); lastDayOfMonth = Month() != Ref(Month(), 1); score = ((ROC(Close, 84) + ROC(Close, 105)) + ROC(Close, 252))/ 3 ; PositionScore = 1000 + score; Sell = lastDayOfMonth ; Buy = lastDayOfMonth ;