Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pinescript question, sell 50% at profit and let 50% run

I am trying to have 2 sell orders but I want to have a profit and stop as well based on pips not price. If I use strategy.exit it would look like this for my stop and profit but I cant figure out how to split the sells.

strategy.exit("exit", "long", stop = 100, profit = 100)


Is this possible? I know my coding isnt very good any help is greatly appreciated.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

shortCondition = close < lowerBand and close[1] > lowerBand

if (shortCondition)

strategy.entry("short", strategy.short, qty=pos_size)

strategy.order("short1", strategy.long, qty=size_trim, comment="closefirst50%")

strategy.order("short2", strategy.long, qty=size_trim, comment="closesecond50%")


longCondition = close > upperBand and close[1] < upperBand

if (longCondition)

strategy.entry("long", strategy.long, qty=pos_size)

strategy.order("long1", strategy.short, qty=size_trim, comment="closefirst50%")

strategy.order("long2", strategy.short, qty=size_trim, comment="closesecond50%")

>Solution :

The solution is to use 2 strategy.exit indeed

if (shortCondition)
    
    strategy.entry("short", strategy.short, qty=pos_size)
    
if strategy.position_size < 0

    strategy.exit("exit short TP", qty=size_trim, profit = 100, comment="closefirst50%")
    
    strategy.exit("exit short SL", loss = 100, comment="close the remaining 50%")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading