I'm trying to create, either via rules or code, a way to close out positions at the end of every day. I figured out how to do it via code by using the total minute bars for a given day:
if (LastActivePosition != null && LastActivePosition.Active)
if (bar - LastActivePosition.EntryBar >= 387 - LastActivePosition.EntryBar)
CoverAtMarket(bar + 1, p, "Group1")
But this will only work for one day at a time. I'm wondering if there is an easier way that I'm missing, or a way to reset the count at the end of each day or something? Thank you.
Size:
Color:
Size:
Color:
Eugene, thank you for the tip.
Size:
Color:
I'm trying to close open multiple positions at the end of the day. The code below seems to work for some symbols, but for some I get a bar number error. (Runtime Error - Bar number must be 390 or greater). Any help or ideas would be greatly appreciated. Thanks.
CODE:
Please log in to see this code.
Size:
Color:
QUOTE:
(Runtime Error - Bar number must be 390 or greater).
It happens when a
CrossUnder occurs at the last bar of day. Try this code:
CODE:
Please log in to see this code.
Size:
Color:
Thank you for this - it works well. I noticed you changed the loop to 421. Is this to cycle through an entire day up front? Also, if I were to ever start auto trading, if I understand correctly you should not use AtClose functions? In this case, could you use CoverAtMarket instead of CoverAtClose?
Size:
Color:
That's a remnant (just fixed), feel free to use "21" as it was.
Size:
Color: