Exit condition with multiple positions
Author: maninjapan
Creation Date: 12/21/2009 1:31 PM
profile picture

maninjapan

#1
The follow code obviously works fine with a single position, what if, though, Id like to apply the same kind of exit to a 'long' Spread Position?
CODE:
Please log in to see this code.


profile picture

Cone

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

maninjapan

#3
right, but if I am long one and short the other, how do I specify long and short...

This is the exit I would like to use to exit a short position, but the way it is currently set it doesnt specify a long or short position in the spread right?


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

Eugene

#4
QUOTE:
right, but if I am long one and short the other, how do I specify long and short...

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

maninjapan

#5
Ok, I understand tha part, but I am more worried about the exit rule,
CODE:
Please log in to see this code.


this will exit short positions that have crossed back under the middle oving average as I would like, however 'long spread' positions need to exit after they close above the ma. The current rule would exit every trade where the Close was under the moving average, which I dont wantto happen with 'long Spread ' positions. So I guess I need to somehow differentiate between a long spread and a short spread position. Hope that makes sense
profile picture

maninjapan

#6
Ive been playing around with some exits and would like to add a time based exit to my pairs strategy. I found the following example, but not sure how I could adjust it to a pairs strategy.

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

Eugene

#7
In theory, you can refer to the penultimate position of a pair as Positions[Positions.Count-2] and, respectively, the last created Position object is Positions[Positions.Count-1]. Maybe Robert have a different idea?
profile picture

maninjapan

#8
Tried the following so that it should hold for 5 bars, but it still closes the very next bar.... I would like it to hold for 5 bars before exiting.

CODE:
Please log in to see this code.

profile picture

Cone

#9
It's because the statements following "if (bar+1 - p.EntryBar >= 5)" are not delimited with { }, therefore the only statement that executes for that condition being true is "SetContext( shortSymbol, true );", and, that statement isn't even necessary!
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).