For example, let's assume that the strategy is running on hourly bars. It purchases one contract at 1:00, a second contract at 2:00 and a third contract at 3:00. I'd like to close each position after that position has been open for five hours -- i.e., it would sell one contract at 6:00, a second contract at 7:00 and a third contract at 8:00.
I currently have the following code for my entry and exit. The exit is based on the "TimeExit (Bars) LE" signal:
This doesn't have the desired effect. Instead of pyramiding out of the position gradually, it sells all of the contracts at the same time, X number of bars after the first position was entered. In the example above, it will sell all three contracts at 6:00, rather than closing them sequentially over time. (Despite the "sell 1 contract" limitation.)
Code: Select all
If Time >= EnterStart AND Time < EnterEnd then begin
Buy 1 contract next bar at Close Limit;
If BarsSinceEntry = BarToExitOn then begin
Sell 1 contract next bar at market;
Is there any way to achieve this? Thanks in advance for any pointers.