Closing all trades
Author: alsilva86
Creation Date: 8/28/2016 9:35 PM
profile picture

alsilva86

#1
Hello All,

Basically I want to leave all trades I have entered at same bar.

The timeframe I am using is daily, as you can see I have two limit orders and I want to close all my positions by the end of the day, I believe this is the proper code but heres the error I get.

This error doesnt happen when I try sending only one order.


CODE:
Please log in to see this code.
profile picture

Eugene

#2
Hello,

The error message "Bar number must be X or greater" suggests in this context that you cannot sell a Position before creating it e.g. on bar #19 whereas it was established on bar #20.

Check out this example, it should work. Notice how the shortcut to Position.AllPositions closes all positions at once (see QuickRef for more detail):

CODE:
Please log in to see this code.
profile picture

Eugene

#3
Thanks for saying thank you.