繁体   English   中英

(任何人,拜托?我试着弄清楚但仍然卡住)满足多个条件时的策略进入

[英](Anybody, please? I tried figuring it out but still stuck) Strategy Entry when Multiple Conditions are met

我已经尽我所能,但无法弄清楚如何做到这一点。 我没有编码经验,但我非常精通 excel 并且在一定程度上了解 VBA,所以不知何故,我设法使用不同的编码语言来满足不同的要求。 我可以说我擅长谷歌搜索,所以我只是用谷歌搜索我真正想要的内容,并以我正在研究的任何语言获得任务的答案。 然后简单地复制粘贴解决方案以及针对我的任务进行的调整。 但无法弄清楚这一点,我在谷歌上搜索了不同的问题并在所有结果页面上搜索了解决方案。 没有像往常一样走运。 上周刚开始使用 Pine Code。

我有以下查询。

所以我有一个从 0 到 100 的指标。对于多个柱,它可以保持在 100 或 0。 我想做以下事情 -

当指标达到 100 时,我想找到柱的收盘价。 然后直到它保持在 100,这个条件应该是开放的(这是第一个条件)。 然后一旦指标值低于 98,我想找到柱的收盘价(这是第二个条件)。 如果指标低于 98 时柱线的收盘价高于指标第一次达到 100 时的收盘价,则执行 strategy.long。

如果满足以上两个条件,但条件1的收盘价高于条件2的收盘价,则执行strategy.short。

当指标达到 0 时,我想找到柱的收盘价。 然后直到它保持在0,这个条件应该是开放的(这是第一个条件)。 然后一旦指标值高于 2,我想找到柱的收盘价(这是第二个条件)。 如果指标高于 2 时柱线的收盘价高于指标第一次达到 0 时的收盘价,则执行一个 strategy.long。

如果满足以上两个条件,但条件1的收盘价高于条件2的收盘价,则执行strategy.short。

另外,我想在 startegy 做多/做空时增加 0.8% 的价格限制。

如果您阅读了所有这些内容,感谢您抽出宝贵的时间。

希望您能帮助我解决问题。

再次感谢您,干杯::)

 This is my code (it currently is an indicator but I want a strategy).- 


mom = ta.mom(close,100)
percentile = (ta.percentrank(mom, 100))

x = false
if percentile == 100
    x:=true

if percentile < 99 and percentile >98
    x:=false

    
plotshape(percentile, title = "Buy", style = shape.arrowup, location = location.belowbar, color = color.green, text = "Buy", textcolor = color.green, size = size.large)


它导致了多个买入信号。

所以两天后,我终于做到了。 结果不是我期望的那样,但这并不重要,因为我学到了一些新东西,这为我开辟了许多不同的其他想法。 另外,我自己也没有弄清楚,我在 pinescript subreddit 上发布了相同的查询,一位 redditor 的同事帮助了部分代码,我从那里拿走了它。 这是链接1

这是我的完整代码 -

//@version=5
indicator("percentile indicator", overlay = true)

mom = ta.mom(close,100)
percentile = (ta.percentrank(mom, 100))

c1 = 0.0
c1 := nz(c1[1])
c1 := (percentile == 100 and percentile[1] < 100) ? close : c1

c2 = 0.0
c2 := nz(c2[1])
c2 := (percentile[1] == 100 and percentile < 100) ? close : c2

event = 0
event := nz(event[1])
event := percentile == 100 ? 1 : event
event := event ==1 and percentile < 100 ? 2 : event

long = event == 2 and c2 > c1 ? 1 : 0
short = event == 2 and c2 < c1 ? 1 : 0

event := event == 2 ? 0 : event

plotshape(long, title = "Long", style = shape.labelup, location = location.belowbar, color = color.green, text = "Long", textcolor = color.white, size = size.tiny)
plotshape(short, title = "Short", style = shape.labelup, location = location.belowbar, color = color.red, text = "Short", textcolor = color.white, size = size.tiny)


c3 = 0.0
c3 := nz(c3[1])
c3 := (percentile == 0 and percentile[1] > 0) ? close : c3

c4 = 0.0
c4 := nz(c4[1])
c4 := (percentile[1] == 0 and percentile > 0) ? close : c4

event1 = 0
event1 := nz(event1[1])
event1 := percentile == 0 ? 1 : event1
event1 := event1 == 1 and percentile > 0 ? 2 : event1

long1 = event1 == 2 and c4 > c3 ? 1 : 0
short1 = event1 == 2 and c4 < c3 ? 1 : 0

event1 := event1 == 2 ? 0 : event1

plotshape(long1, title = "Long", style = shape.labelup, location = location.belowbar, color = color.green, text = "Long", textcolor = color.white, size = size.tiny)
plotshape(short1, title = "Short", style = shape.labelup, location = location.belowbar, color = color.red, text = "Short", textcolor = color.white, size = size.tiny)

编辑 - 上面是一个指标,下面是限制和停止的策略。

//@version=5
strategy("ABC")

mom = ta.mom(close,100)
percentile = (ta.percentrank(mom, 100))

c1 = 0.0
c1 := nz(c1[1])
c1 := (percentile == 100 and percentile[1] < 100) ? close : c1

c2 = 0.0
c2 := nz(c2[1])
c2 := (percentile[1] == 100 and percentile < 100) ? close : c2

event = 0
event := nz(event[1])
event := percentile == 100 ? 1 : event
event := event ==1 and percentile < 100 ? 2 : event

long = event == 2 and c2 > c1 ? 1 : 0
short = event == 2 and c2 < c1 ? 1 : 0

longprice = ta.valuewhen(long,close,0)
shortprice = ta.valuewhen(short,close,0)
limitlong = longprice * 1.008
stoplong = longprice * 0.992
limitshort = shortprice * 0.992
stopshort = shortprice * 1.008

event := event == 2 ? 0 : event

if long
    strategy.entry("Enter Long", strategy.long)
    strategy.exit("Long Exit","Enter Long", limit = limitlong, stop = stoplong)
if short
    strategy.entry("Enter Short", strategy.short)
    strategy.exit("Short Exit","Enter Short",limit = limitshort, stop = stopshort)

c3 = 0.0
c3 := nz(c3[1])
c3 := (percentile == 0 and percentile[1] > 0) ? close : c3

c4 = 0.0
c4 := nz(c4[1])
c4 := (percentile[1] == 0 and percentile > 0) ? close : c4

event1 = 0
event1 := nz(event1[1])
event1 := percentile == 0 ? 1 : event1
event1 := event1 == 1 and percentile > 0 ? 2 : event1

long1 = event1 == 2 and c4 > c3 ? 1 : 0
short1 = event1 == 2 and c4 < c3 ? 1 : 0

long1price = ta.valuewhen(long1,close,0)
short1price = ta.valuewhen(short1,close,0)
limit1long = long1price * 1.008
stop1long = long1price * 0.992
limit1short = short1price * 0.992
stop1short = short1price * 1.008

event1 := event1 == 2 ? 0 : event1

if long1
    strategy.entry("Enter Long", strategy.long)
    strategy.exit("Long Exit","Enter Long", limit = limit1long, stop = stop1long)
if short1
    strategy.entry("Enter Short", strategy.short)
    strategy.exit("Short Exit","Enter Short",limit = limit1short, stop = stop1short)

暂无
暂无

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

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