Multiple %% profit exits example

This example show how to make multiple take profits in percent.
Mã nguồn mở

Với tinh thần của TradingView, tác giả đã xuất bản tập lệnh theo mã nguồn mở, vì thế trader có thể dễ dàng hiểu và tùy chỉnh được. Bạn có thể sử dụng miễn phí, hoặc tùy chỉnh lại mã đã được cấp phép bởi Quy tắc Chung. Bạn có thể sử dụng nó trên biểu đồ.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?

Bình luận

Are you able to update this to have the StopLoss move to break even once the first take profit level is hit?
I can't find any example of this anywhere.

Note, I trade on the 1hr chart, so the StopLoss needs to work intra-candle, because a lot of price movement can happen in 1 hour.
+3 Phản hồi
cipher_phinx1988 citizentraderx
@citizentraderx, have you figured how to move to breakeven if the tp1 has been hit?
Phản hồi
This will be useful to many! Thx.
+2 Phản hồi
This is useful for newbie like me. It would be great if you put comments on each code so that it will understandable for beginners.
Phản hồi

I noticed that for each exit statement, the qty_percentage applies to both the profit and loss (i.e "x1" profit would be 25% but also 25% if the stop loss was hit)

strategy.exit("x1", qty_percent = 25, profit = percentAsPoints(1), loss = lossPnt)

Is there a way to apply a different qty_percent for limit and stop. More specifically, can you always fix the stop to 100% of your position while changing the take profit percentage for different TP targets?
Phản hồi
adolgov AlkiZaganiaris
@AlkiZaganiaris, yes this is possible. But we need "make" strategy.exit through `strategy.order` command.
Phản hồi
myncrypto adolgov
@adolgov, Do you happen to have a fix or some example code that resolves the stop loss issue @AlkiZaganiaris is speaking of?
Phản hồi
AlkiZaganiaris AlkiZaganiaris
I think I may have answered my own question. On your last exit you dont set qty_percent which would automatically close off any remaining position.

strategy.exit("x4", profit = percentAsPoints(4), loss = lossPnt)
Phản hồi
adolgov AlkiZaganiaris
@AlkiZaganiaris, yes it is
Phản hồi