[英]Why Profit Target is not activated?
I have the following code, and I am trying when I have a trade signal to sell at a specific price or a specific stop loss.我有以下代码,当我收到以特定价格或特定止损卖出的交易信号时,我正在尝试。
But Trandingview always sells at 1.3% up and not at 4%, do you have any idea why this is happening?但是 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))
You calculations seem off.你的计算似乎不对。
Also, profit
argument of the strategy.exit()
function expect the target in ticks.此外, strategy.exit()
function 的profit
论点期望以滴答为单位的目标。
If you want to have a TP at 4% and SL at 1%, use the following template.如果您希望 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.