为什么未激活利润目标?
我有以下代码,当我有特定价格或特定停止损失的贸易信号出售时,我正在尝试。
但是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))
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?
// 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))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的计算似乎熄灭了。
另外,
利润
strategy.exit()
函数的参数期望在tick中进行目标。如果您想将TP占4%,SL为1%,请使用以下模板。
You calculations seem off.
Also,
profit
argument of thestrategy.exit()
function expect the target in ticks.If you want to have a TP at 4% and SL at 1%, use the following template.