Cannot get first in first out strategy to work with hedging

 

I am running a long-only strategy that opens multiple long trades, and then sells them off one by one. The first position it sells should correspond with the ticket of the first position it had opened.


I have been browsing the forums for literally hours on end, as well as documentation, but have been unable to get it to work (Tried mostly with CTrade functions).


Can anyone point me in the right direction? 

 
Check out this code: Close All FIFO
 
Vladimir Karputov #:
Check out this code: Close All FIFO

So basically, they store the tickets in an array, and sort via time?

So every position I open, i should append the corresponding ticket to an array?

So I should just close the ticket corresponding with the first index in the array? And then once closed, remove it from the array?

Reason: