簡體   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