Reputation: 615
After certain number of bars - say 100 bars, if my trade hasn't exited with the original stop or take profit, I would like to exit out 50% of the trade at market value and modify the original exit order with new profit and stop loss values. Is that possible? How could I do it in Pinescript?
Upvotes: 1
Views: 918
Reputation: 3818
You can use barssince
function to count the bars, strategy.position_size
to detect the long entry and qty_percent
argument of the strategy.exit
function:
wasLongEntry = strategy.position_size > 0 and strategy.position_size != strategy.position_size[1]
barsFromLong = barssince(wasLongEntry)
if barsFromLong >= 100
*check for stop and take profit*
...
strategy.exit( ..., qty_percent = 50, ... )
//then overwrite SL/TP
sl := ...
tp := ...
Upvotes: 2