簡體   English   中英

Pine Script:當兩個條件一個接一個滿足時繪制標簽

[英]Pine Script: Paint label when two conditions are met one after the other

一旦在多個條上一個接一個滿足兩個條件,我就會嘗試繪制標簽。

首先,4K-sma 與5K-sma 交叉,然后在下一次oneK-sma 與oneD-sma 交叉時,它會繪制一個標簽。

ATM 腳本保存得很好,但沒有繪制標簽,而且我已經沒有關於如何解決這個問題的想法。

oneK=sma(stoch(close, high, low, 11), 10)
oneD=sma(oneK, 4)
fourK=sma(stoch(close, high, low, 176), 160)
fiveK=sma(stoch(close, high, low, 352), 320)

test=bool(na)
fir=bool(na)
if (crossover(fourK,fiveK))
    test:=true
if (test==true) and crossover(oneK,oneD)
    fir:=true
    test:=false

plotshape(fir, style = shape.arrowup, location = location.belowbar, color=#ff4545, size=size.small)

問題是:

  • 您在沒有var關鍵字的情況下聲明變量,因此它們在每個條形上都被初始化。
  • 一旦fir設置為 true,您就再也不會將其重置為 false。

這將起作用:

//@version=4
study("SO 64706821", overlay=true, shorttitle="SO")

oneK  = sma(stoch(close, high, low, 11), 10)
oneD  = sma(oneK, 4)
fourK = sma(stoch(close, high, low, 176), 160)
fiveK = sma(stoch(close, high, low, 352), 320)

var bool test = na // Initializion occurs once, on first bar
bool fir = false   // Initializion occurs on every bar

if crossover(fourK,fiveK)
    test := true
    
if test and crossover(oneK,oneD)
    fir  := true
    test := false

plotshape(fir, style = shape.arrowup, location = location.belowbar, color=color.red, size=size.small)

// Background color to make it more clear where the signals occur, because there are so few.
bgcolor(fir ? color.yellow : na, transp=80) 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM