////////////////////////////////////////// jbmarwood.com // 20. Linear Reg & ATR // ////////////////////////////////////////// SetOption( "InitialEquity", 10000); // Start with USD 10000// SetOption( "MinShares", 0.01 ); SetOption( "MarginRequirement", 100); SetOption( "UsePrevBarEquityForPosSizing", True ); // Use prev bar for equity sizing// SetTradeDelays( 0, 0, 0, 0 ); // Trade delays applied with REF function// SetOption( "MaxOpenpositions", 12); SetOption("SeparateLongShortRank", True ); MOL = 12; MOS = 6; SetOption ("Maxopenlong",MOL); SetOption ("Maxopenshort",MOS); SetOption( "AllowSameBarExit", True ); numberpositions = 12; SetOption("Maxopenpositions",numberpositions); SetPositionSize( 1, spsShares ); PositionSize= -100/12;//numberpositions; ////////////////////////////////////////// Index = Foreign ("SPY","C",True); Indexfastma = MA (Index, 13); Indexslowma = MA (Index, 39); ATR1 = Ref(ATR(20),-1); PositionScore = ATR1-100; ////////////////////////////////////////// Lopt1 = Optimize("lopt1",5,1,10,1); Lopt2 = 15 ; Lopt3 = 60 ; Lin1 = MA(LinearReg(O,Lopt1),Lopt2); Lin2 = MA(LinearReg(O,Lopt1),Lopt3); Lin3= Cross(Lin1,Lin2); Lin4= Cross(Lin2,Lin1); ////////////////////////////////////////// Buy = Lin3 AND O>1;// AND Indexfastma > Indexslowma;// AND Volume > 100000; Sell = Lin4; Short = Lin4 AND O>1; Cover = Lin3; ////////////////////////////////////////// BuyPrice = (C + H) / 2; SellPrice = (C + L) /2; ShortPrice = SellPrice;//C; CoverPrice = BuyPrice;//C; Buy = ExRem( Buy, Sell ); Sell = ExRem( Sell, Buy ); Short = ExRem( Short, Cover); Cover = ExRem( Cover, Short); ///////////////////////////////////////////////////////// ///////////////////////// end ///////////////////////////