I am looking to add a delay to change the type of order from a limit to a market order.
How would I add a 90 second delay (after an exit condition has been triggered) to condition2 like the pseudo code below.
Condtion1 would be the exit criterion.
Do you mean with "after an exit condition has been triggered" that the position has been closed due to this triggering, or that the code intends to close the position? In practice, there won't be a big difference in time between both, but if you scale out there can be.
PosTradeExitDateTime can be used to retrieve the DateTime value of the previous position (so the time when the position closed, not the time the script intended to do so).
With
PostTradeCount you can retrieve how many trades there were in the previous position. When `PosTradeCount` is combined with `PosTradeExitDateTime`, the DateTime value of the last trade from the last position can be retrieved.
But then 90 seconds (or 1,5 minutes) still needs to be converted to DateTime (instead of
HHmm time). That can be done with
ELTimeToDateTime_s.
When I understood you correctly, that would something similar to this:
Code: Select all
Variables:
dtExitTime(0),
dt90Seconds(ELTimeToDateTime_s(130));
dtExitTime = PosTradeExitDateTime(1, PosTradeCount(1) - 1)
+ dt90Seconds;
// Submit market order when the current time (ComputerDateTime)
// is less than the exit time of the last position + 90 seconds
if (ComputerDateTime <= dtExitTime) then
Sell ("XL MKT") 1 contract next bar at market
// If we've passed that 90 seconds time window, switch to
// submitting limit orders:
else
Sell ("XL LMT") 1 contract next bar at Close[1] limit;