I'm try to detect when a stoploss has been hit and to prevent reentry in the same direction as the stopout. Once that reentry occurs I'd like trading to resume as normal, unless that position is stopped out. I write signal orders to a printlog. The code I've come up with prevents same entry from stop out but doesn't return the signal to regular trading. it gets stuck, doesn't take profit or reverse and seems to just wait for another stopout and reverse. I've tried adding a "break;" in the code and get "illegal break" on compile.
Code: Select all
{If short hit prevent same entry trade only allow long and vice versa}
If PositionProfit(1)<-500 and MP=0 then begin // seems like a crude way to detect a stopout but I couldn't think of another way in a function
Switch MP1 begin
Case >0:
EntryOK = true;
BuyLimitOK = false;
SellLimitOK = true;
Case <0:
EntryOK = true;
BuyLimitOK = true;
SellLimitOK = false;
//Case =0:
//EntryOK = true;
//BuyLimitOK = true;
//SellLimitOK = true;
end;
end;