Confusion with buy and sell orders
Posted: Dec 22 2009
I'm confused on some of the aspects of submitting buy and sell orders. When I submit a buy order as follows:
buy ("Gone long") nbuy contracts next bar at market; where nbuy = 3
It works as expected. Then my study at some time in the future may want to close 1 contract out of the 3 thus:
sell ("Covered long") nsell contracts total next bar at market; where nsell = 1
It works as expected. Then the study may do it again to close another one using the same command. It fails. I believe it's because you can't have multiple orders applied to open contracts using the same exit label. If I use use a different label it works fine. However, I can't use different labels since the number of times my study may close open contracts varies. It's a pity the labels can't be string variables so I could get around it by updating a number in the string. So, what else can I do? It does not help to leave out the exit label.
According to the documentation, if EntryLabel is not specified, all of the open long entries will be closed. Well this does not actually happen since I know that after closing one position, 2 remain according to the currentcontracts strategy position keyword. Anyway, I don't want to tie the order to a previous order as there could be more than one entry order.
Maybe I'm missing something - all I need is a simple and straightforward order to close some of the open positions, which can be used more than once. Any ideas? Also, I'm still using version 5.0. Will 5.5 help?
buy ("Gone long") nbuy contracts next bar at market; where nbuy = 3
It works as expected. Then my study at some time in the future may want to close 1 contract out of the 3 thus:
sell ("Covered long") nsell contracts total next bar at market; where nsell = 1
It works as expected. Then the study may do it again to close another one using the same command. It fails. I believe it's because you can't have multiple orders applied to open contracts using the same exit label. If I use use a different label it works fine. However, I can't use different labels since the number of times my study may close open contracts varies. It's a pity the labels can't be string variables so I could get around it by updating a number in the string. So, what else can I do? It does not help to leave out the exit label.
According to the documentation, if EntryLabel is not specified, all of the open long entries will be closed. Well this does not actually happen since I know that after closing one position, 2 remain according to the currentcontracts strategy position keyword. Anyway, I don't want to tie the order to a previous order as there could be more than one entry order.
Maybe I'm missing something - all I need is a simple and straightforward order to close some of the open positions, which can be used more than once. Any ideas? Also, I'm still using version 5.0. Will 5.5 help?