Hi there,
It’s all in the title; how can we single out the very useful command DEFPARAM flatafter = time for a specific day and only for long positions?
I’ve been trying all sorts of tweaking but to no avail I’m afraid…
Cheers,
Indeed DEFPARAM flatafter = time does not allow anything other than a TIME.
To be able to exit on selected days, at a given time you can use OpenDayOfWeek and OpenTime:
If OpenDayOfWeek = 3 or OpenDayOfWeek = 5 Then
If OpenTime = 190000 Then
If OnMarket Then
Sell at Market
Exitshort at Market
Endif
Endif
Endif
This will close any open trade at 190000 on Wednesday and on Friday.
Above won’t work because I forgot to mention that I work with LIMIT orders..
I can’t squeeze a SELL AT MARKET command because of it; at least, I haven’t figured this out up untill now..
With pending (Limit or Stop) if already triggered you can use the above snippet, while if not triggered they are automatically CANCELLED the next time your code is executed, so you just need to apply the above (modified) snippet not to enter at market after a given time:
If OpenDayOfWeek = 3 or OpenDayOfWeek = 5 Then
If OpenTime < 190000 Then
BUY 1 contract AT MyLongEntryPrice LIMIT //or STOP
SELLSHORT 1 contract AT MyShortEntryPrice LIMIT //or STOP
Else
Sell at Market
Exitshort at Market
Endif
Else
BUY 1 contract AT MyLongEntryPrice LIMIT //or STOP
SELLSHORT 1 contract AT MyShortEntryPrice LIMIT //or STOP
Endif
in this case you place a pending order, on Wed. or Fri., only before 190000 (while you make no check the other days). You will also close ALL open orders at 190000 on those two days.
Tested and working, many thanks!