I'm trying to make a rotational system that would buy 2 stocks from a watchlist of 20 of the largest stocks and short 2 stocks at the same time. For positionscore for the buys I would use the lowest RSI value and for the shorts, I would use the highest RSI value.
Positionscore looks for the highest values, shorts negative numbers and buys positive numbers. I could sort the RSI values from highest to lowest. For the lowest two values, I could just convert them to really high numbers, and positionscore would result in buys for them. For the highest two values, I could just convert them to negative numbers and positionscore would short them.
Would it be possible to have two longs and two shorts with the same rotational code? Maybe I have to split it up into two rotational codes. I started to write an AFL which won't work as it is. Does anyone have an idea how I might proceed?
//and short two of the stocks with the highest RSI so that you always have two long and two short positions _SECTION_BEGIN("Rotational to buy lowest and sell highest RSI"); SetChartOptions(1, chartShowArrows | chartShowDates); Float = 100000; // Options SetOption("CommissionAmount",0.0); SetOption("AllowPositionShrinking", True); SetOption("InitialEquity", Float); //Parameters MaxPositions =4;//Optimize("MaxPositions",2,1,20,1); RSIPeriod =10;//Optimize("RSIPeriod",2,2,25,1); RSIIndication = RSI(RSIPeriod); Number=2; SetOption("MaxOpenPositions", MaxPositions ); SetOption("WorstRankHeld", MaxPositions + Number); SetPositionSize( 100 / MaxPositions, spsPercentOfEquity ); SetBacktestMode( backtestRotational ); //SetTradeDelays( 0, 0, 0, 0 ); //use settings, set to 0 for close or 1 for open next day //BuyPrice = Close; //has no effect in rotational mode, use settings Score=100-RSIIndication;//for the two buys Score=-RSIIndication;//for the shorts....can I have two longs and two shorts in the same Rotational AFL? PositionScore = Score ; _SECTION_END(); ```