//================================================================================= //Entry and Exit Signals //================================================================================= LESetup = OptFilt AND IndexUp AND UniverseFilter AND HDBFilter AND NOT OnSecondLastBarOfDelistedSecurity AND H > Ref(HHV(H,20),-1) AND ROC(C,20) > 30 ; LE = Ref(LESetup,-1); LEPrice = O; LExSetup = 0; LEx = Ref(LExSetup,-1) OR OnLastTwoBarsOfDelistedSecurity; up = 40; down = 10; LTS = IIf(IndexFilterUp,H*(1-(up/100)),H*(1-(down/100))); //================================================================================= //Looping //================================================================================= Buy = 0; Sell = 0; PriceAtBuy = 0; LBIT = 0; LStop = Null; //================================================================================= for (j = 1; j < BarCount; j++) { if (PriceAtBuy==0 AND LE[j]) { Buy[j] = True; PriceAtBuy = LEPrice[j]; BuyPrice[j] = LEPrice[j]; LStop[j-1] = LTS[j-1]; LStop[j] = Max(LTS[j-1],LTS[j]); LBIT[j] = 1; if (LBIT[j]>1 AND LEx[j]) { Sell[j] = True; SellPrice[j] = Open[j]; PriceAtBuy = 0; } if (LBIT[j]>1 AND Close[j-1] < LStop[j-1]) { Sell[j] = True; SellPrice[j] = Open[j]; PriceAtBuy = 0; } } else if (PriceAtBuy > 0) { LBIT[j] = LBIT[j-1]+1; if (LBIT[j]>1) { LStop[j] = Max(LStop[j-1],LTS[j]); } if (LBIT[j]>1 AND LEx[j]) { Sell[j] = True; SellPrice[j] = Open[j]; PriceAtBuy = 0; } if (LBIT[j]>1 AND Close[j-1] < LStop[j-1]) { Sell[j] = True; SellPrice[j] = Open[j]; PriceAtBuy = 0; } } } //Rank = 1000 + ROC(C,20); //PositionScore = Ref(Rank,-1);