I'm having a few troubles sometimes with positions that do not get closed at the end of the day. I try and get out at 1500, since trading goes until 1505 I want to leave a small amount of slack just in case.
My current code is fairly simple as follows:
Code: Select all
//time based exits
If Time >= Bfr then SELL ("XLTime")ALL contracts this bar at close;
If Time >= Bfr then BUYTOCOVER ("XSTime") ALL Contracts this bar at close;
The issue I have is that I am using range (point) bars and with recent quiet conditions, sometimes there is no new bar generated in the last 5mins so the strategy does not exit until the following morning.
Solutions I've tried so far without success:
I don't currently use intrabar order generation for the strategy, but tried switching it on for the end of the day only to force the position to trade out and then turning it off again
Code: Select all
inputs: aftr2(1501), bfr2(1502);
If Time > Aftr2 and Time < Bfr2 then begin
[IntrabarOrderGeneration = true];
If Time >= aftr2 then SELL ("XLTime")ALL contracts this bar at close;
If Time >= aftr2 then BUYTOCOVER ("XSTime") ALL Contracts this bar at close;
[IntrabarOrderGeneration = false];
end;
any suggestions?
I was considering writing a second signal running on the same chart just for end of day exits which would then use intra bar order generation, and MarketPosition_at_Broker to get out of any positions, but I would rather it all in one.
I have looked at other codes such as the one in this thread viewtopic.php?f=5&t=7834 but it has the same issue that it needs to exit next bar after the time condition is met.