Search code examples
pine-scripttrading

How to close the position partillay


could you please help to making the split close position when reached to goal price?

for example ->

1000 $ -> enter price long position

1100 $ -> when 10% raise, close the 20% position in total enter volume

1200 $ -> when 20% raise, close the 20 % position in total enter volume


Solution

  • use :

    strategy.close(id, comment, qty, qty_percent, alert_message, immediately)
    

    with qty_percent = 20 for example.
    You can have more information in the manual : https://www.tradingview.com/pine-script-reference/v5/#fun_strategy{dot}close