Here you go, with couple of additions
// This source code is subject to the terms of the Mozilla Public License 2.0 at //mozilla.org/MPL/2.0/ // © SafetyHammer //@version=4 strategy[title="Take profit [% of instrument price]", overlay=true, pyramiding=1] // STEP 1: // Make inputs that set the take profit % [optional] FastPeriod = input[title="Fast MA Period", type=input.integer, defval=20, minval=1, group="Moving Average"] SlowPeriod = input[title="Slow MA Period", type=input.integer, defval=60, minval=1, group="Moving Average"] TP1Perc = input[title="Long Take Profit [%]", type=input.float, minval=0.0, step=0.1, defval=2, group="TP & SL"] TP2Perc = input[title="Long Take Profit [%]", type=input.float, minval=0.0, step=0.1, defval=4, group="TP & SL"] SLPerc = input[title="Long Stop Loss [%]", type=input.float, minval=0.0, step=0.1, defval=2, group="TP & SL"] TP1_Ratio = input[title="Sell Postion Size % @ TP1", type=input.float, defval=50, step=1, group="TP & SL", tooltip="Example: 50 closing 50% of the position once TP1 is reached"]/100 // Calculate moving averages fastSMA = sma[close, FastPeriod] slowSMA = sma[close, SlowPeriod] // Calculate trading conditions enterLong = crossover[fastSMA, slowSMA] // Plot moving averages plot[series=fastSMA, color=color.green, title="Fase MA"] plot[series=slowSMA, color=color.red, title="Slow MA"] // STEP 2: // Figure out take profit price percentAsPoints[pcnt] => strategy.position_size != 0 ? round[pcnt / 100.0 * strategy.position_avg_price / syminfo.mintick] : float[na] percentAsPrice[pcnt] => strategy.position_size != 0 ? [[pcnt / 100.0] + 1.0] * strategy.position_avg_price : float[na] current_position_size = abs[strategy.position_size] initial_position_size = abs[valuewhen[strategy.position_size[1] == 0.0, strategy.position_size, 0]] TP1 = strategy.position_avg_price + percentAsPoints[TP1Perc] * syminfo.mintick * strategy.position_size / abs[strategy.position_size] TP2 = strategy.position_avg_price + percentAsPoints[TP2Perc] * syminfo.mintick * strategy.position_size / abs[strategy.position_size] SL = strategy.position_avg_price - percentAsPoints[SLPerc] * syminfo.mintick * strategy.position_size / abs[strategy.position_size] // Submit entry orders if [enterLong] strategy.entry[id="Long", long=true] // STEP 3: // Submit exit orders based on take profit price if strategy.position_size > 0 strategy.exit["TP1", from_entry="Long", qty = initial_position_size * TP1_Ratio, limit = TP1, stop = SL] strategy.exit["TP2", from_entry="Long", limit = TP2, stop = SL] // Plot take profit values for confirmation plot[series=[strategy.position_size > 0] ? TP1 : na, color=color.green, style=plot.style_circles, linewidth=1, title="Take Profit 1"] plot[series=[strategy.position_size > 0] ? TP2 : na, color=color.green, style=plot.style_circles, linewidth=1, title=" Take Profit 2"] plot[series=[strategy.position_size > 0] ? SL : na, color=color.red, style=plot.style_circles, linewidth=1, title="Stop Loss"]TradingView stop loss script
Bài Viết Liên Quan
Toplist mới
#2
Top 6 xem phim điều tra pháp y tái xuất 2023
7 tháng trước#3
Top 10 tìm tiếng bắt đầu bằng r d gi lớp 4 2023
7 tháng trước#4
Top 6 anime giá tộc ma cà rồng ss3 2023
7 tháng trước#5
Top 7 đề thi thử liên trường nghệ an lần 1 môn anh 2023
7 tháng trước#6
Top 8 bài tập lịch sử bài 1 lịch sử và cuộc sống 2023
7 tháng trước#7
Top 3 tổng hợp những truyện phá hoại tuổi thơ 2023
7 tháng trước#8
Top 6 thuyết minh tính toán hàng rào 2023
7 tháng trước#9
Bài mới nhất
Chủ Đề
Toplist
Địa Điểm Hay
Hỏi Đáp
Là gì
Mẹo Hay
programming
Nghĩa của từ
Học Tốt
Công Nghệ
mẹo hay
Khỏe Đẹp
bao nhiêu
Top List
Bao nhiêu
Bài Tập
Xây Đựng
Sản phẩm tốt
Ngôn ngữ
Tiếng anh
đánh giá
Bài tập
So Sánh
Ở đâu
So sánh
Hướng dẫn
Tại sao
Dịch
bao nhieu
Đại học
hướng dẫn
Thế nào
Máy tính
Vì sao
Bao lâu
Món Ngon
Khoa Học
Hà Nội