Plz tell me what is my mistake. All positions should be closed on the last bar (ExitAtMarket( bar + 1, p, "Exit at last bar") , but this is not happening:
CODE:
Please log in to see this code.
Size:
Color:
Welcome to the forums Dima.
The thing is, the Position will never be closed because Bars.Count is dynamic (increasing with each new bar added) and your trade is an Alert for bar+1 (that
new bar). So if you don't care about getting that alert (for you know that this Position is being closed anyway):
CODE:
Please log in to see this code.
Alternatively:
CODE:
Please log in to see this code.
As a side note, don't break the link between the IsLastPositionActive status check for the entries:
CODE:
Please log in to see this code.
Please refer to the WealthScript Programming Guide > Programming Trading Strategies > Peeking >
Trading based on Position Active Status .
Size:
Color:
Thank you for your attention! The code works correctly!
Size:
Color: