[英]Why Profit Target is not activated?
我有以下代碼,當我收到以特定價格或特定止損賣出的交易信號時,我正在嘗試。
但是 Trandingview 總是漲 1.3% 而不是 4%,你知道為什么會這樣嗎?
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mpempi
//@version=5
strategy("Strategy HOLD", overlay = true)
rsi = ta.rsi(close, 14)
inTrade = strategy.position_size > 0
notInTrade = strategy.position_size <= 0
timeperiod = time >= timestamp(syminfo.timezone, 2021, 01, 01)
active = rsi > 70
active_close = close < ma200
buy_price = ta.valuewhen(notInTrade, close[1] + close[1] * 4 / 100, 1)
stop_price = ta.valuewhen(notInTrade, close[1] - close[1] * 1 / 100, 1)
if timeperiod and active
strategy.entry('long', strategy.long)
strategy.exit('long', profit = buy_price, stop = stop_price)
bgcolor(activate_long ? color.new(color.green, 50): na)
bgcolor(activate_buy ? color.new(color.purple, 50): na)
plot(buy_price, color = color.new(color.green, 0))
plot(stop_price, color = color.new(color.yellow, 0))
你的計算似乎不對。
此外, strategy.exit()
function 的profit
論點期望以滴答為單位的目標。
如果您希望 TP 為 4%,SL 為 1%,請使用以下模板。
tp_per = input.float(4.0, "TP %", minval=0.0, step=0.1) * 0.01
sl_per = input.float(1.0, "TP %", minval=0.0, step=0.1) * 0.01
tp_price = strategy.position_avg_price * (1 + tp_per)
sl_price = strategy.position_avg_price * (1 - sl_per)
if timeperiod and active
strategy.entry('long', strategy.long)
if (strategy.position_size > 0)
strategy.exit('long', limit=tp_price, stop=sl_price)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.