//=================================================================================
//Entry and Exit Signals
//=================================================================================
Cond1 = L < Ref(L,-1);
Cond2 = BullDB > ClsSt;
Cond3 = H < SMA;
Cond4 = C > SMA;
Cond5 = OptFilt AND IndexUp AND UniverseFilter AND HDBFilter; //All the optional filters
OnLastTwoBarsOfDelistedSecurity = BarIndex() >= (LastValue(BarIndex()) -1) AND !IsNull(GetFnData(“DelistingDate”));
OnSecondLastBarOfDelistedSecurity = BarIndex() == (LastValue(BarIndex()) -1) AND !IsNull(GetFnData(“DelistingDate”));
BuySetUp = Cond1 AND Cond2 AND Cond3 AND Cond5;
Buy = Ref(BuySetUp,-1);
BuyStop = H + 0.01;
SellStop = L – 0.01;
LE = Ref(BuySetUp,-1) AND H >=Ref(BuyStop,-1) AND NOT OnLastTwoBarsOfDelistedSecurity;
//————————————————————————–
//MCS code part 2
if(MCP)
LE = LE && Random()*100>=MCP;
//————————————————————————–
LEPrice = Max(Open,Ref(BuyStop,-1));
LEx = C > SMA;
LIS = SellStop;
//=================================================================================
//Looping
//=================================================================================
Buy = 0;
Sell = 0;
PriceAtBuy = 0;
LBIT = 0;
LStop = 0;
//=================================================================================
for (j = 1; j < BarCount; j++)
{
if (PriceAtBuy==0 AND LE[j])
{
Buy[j] = True;
PriceAtBuy = LEPrice[j];
BuyPrice[j] = LEPrice[j];
LStop = LIS[j-1];
if (LBIT[j]>1 AND L[j] <= LStop)
{
Sell[j] = True;
SellPrice[j] = LStop;
PriceAtBuy = 0;
}
}
else
if (PriceAtBuy > 0)
{
LBIT[j] = LBIT[j-1]+1;
if (LBIT[j]>1 AND L[j] <= LStop)
{
Sell[j] = True;
SellPrice[j] = LStop;
PriceAtBuy = 0;
}
if (LBIT[j]>1 AND LEx[j-1])
{
Sell[j] = True;
SellPrice[j] = Max(Open[j],SMA[j-1]);
PriceAtBuy = 0;
}
}
}