简体   繁体   English

Pinescript 在下一个蜡烛图收盘时获利

[英]Pinescript takes profit at next candle bar close

Have I have set levels for a time period and I'm trying to create strategy w/ RSI at these levels, but Pinescript takes profit at next candle bar close.我是否已经设置了一段时间的水平,并且我正在尝试在这些水平上创建带有 RSI 的策略,但是 Pinescript 在下一个蜡烛条收盘时获利。

buyzone1 = ta.crossunder(close, b1)
buyzone2 = ta.crossunder(close, b2)
buyzone3 = ta.crossunder(close, b4)
sellzone1 = ta.crossover(close, s1)
sellzone2 = ta.crossover(close, s2)
sellzone3 = ta.crossover(close, s3)

length = input( 14 )
overSold = input( 30 )
overBought = input( 70 )
price = close
vrsi = ta.rsi(price, length)

co = ta.crossover(vrsi, overSold)
cu = ta.crossunder(vrsi, overBought)

short_tp = top_valuearea
long_tp = lower_valuearea

short_stp = bottom_tail_value
long_stop = top_tail_value

if (not na(vrsi))
    if (co) and (buyzone1) or (buyzone2) or (buyzone3)
        strategy.entry("Long", strategy.long, 1 ,comment="Long")
    if (cu) and (sellzone1) or (sellzone2) or (sellzone3)
        strategy.entry("Short", strategy.short, 1, comment="Short")

if (strategy.position_size > 0)
    strategy.exit("Long TP1", from_entry="Long", limit = long_tp, stop = long_stop)
    strategy.exit("Short TP1", from_entry="Short", limit = short_tp, stop = short_stp)

// Plot take profit values for confirmation
plot(series=(strategy.position_size > 0) ? long_tp : na, color=color.green, style=plot.style_circles, linewidth=1, title="Take Profit 1")
plot(series=(strategy.position_size > 0) ? short_tp : na, color=color.green, style=plot.style_circles, linewidth=1, title="Take Profit 1")
plot(series=(strategy.position_size > 0) ? long_stop : na, color=color.red, style=plot.style_circles, linewidth=1, title="Stop Loss")
plot(series=(strategy.position_size > 0) ? short_stp : na, color=color.red, style=plot.style_circles, linewidth=1, title="Stop Loss")

But the the the TP is always on the next candle close.但 TP 总是在下一根蜡烛收盘时。 Sometimes two Long positions open, and the shorts never take profit.有时打开两个多头头寸,而空头永远不会获利。 在此处输入图像描述

I'm not sure why it doesn't follow the RSI logic or take profit at its levels.我不确定为什么它不遵循 RSI 逻辑或在其水平上获利。 The Green dots are the TP1 and the red dots are the stop losses.绿点是 TP1,红点是止损。

Remove if check for strategy.exit :删除if检查strategy.exit

...
strategy.exit("Long TP1", from_entry="Long", limit = long_tp, stop = long_stop)
strategy.exit("Short TP1", from_entry="Short", limit = short_tp, stop = short_stp)
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM