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
Size:
Color:
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.
Size:
Color:
Brilliant. Thank You
The methodology is also widely applicable so this is most useful
Size:
Color: