Exit, if at a loss
Author: topcat77
Creation Date: 5/5/2009 8:12 PM
profile picture

topcat77

#1
I am looking to find a way to install an exit that is conditional on the position being at a loss. For example, in this strategy, which positions against a bar that shows a 3x surge in volume, the position should exit after bar4, but only if it is at a loss :

CODE:
Please log in to see this code.


Help or ideas much appreciated
profile picture

Eugene

#2
1. Using average volume with the period of 2500 and starting the trading loop at bar 21 is incorrect.
CODE:
Please log in to see this code.

2. Conditioning an order to execute only after a loss is a matter of checking the Position.NetProfit property: if it's less than 0, it's time to activate the exit.
CODE:
Please log in to see this code.

3. IMO, assigning a bar to the signalBar variable makes sense if the Position has been created. For that, you might want to do the following:
CODE:
Please log in to see this code.

Otherwise if the trade didn't happen when the capital isn't enough, you risk assigning the wrong bar.

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

topcat77

#3
Brilliant. Thank You
The methodology is also widely applicable so this is most useful
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).