Pineスクリプトv5 練習③
TradingView Pine
今回は、
Shadowing variable 'XXX' which exists in parent scope.
Did you want to use the ':=' operator instead of '=' ?
エラーについて。v5 あんまり関係ないけどー
01 //@version=5
02 indicator("My_MACD_01")
03 var fast=12
04 var slow=26
05 fastMA=ta.ema(close,fast)
06 slowMA=ta.ema(close,slow)
07 macd=fastMA-slowMA
08 signal=ta.sma(macd, 9)
09 plot(macd,color=color.blue)
10 plot(signal,color=color.orange)
11
12 var clr=color.black
13 hist=macd-signal
14 chg=ta.change(hist)
15
16 if(macd>=signal and chg>=0)
17 clr=#3DA69A
18 else if(macd>=signal and chg< 0)
19 clr:=#B6DFDB
20 else if(macd< signal and chg<=0)
21 clr:=#E6544B
22 else if(macd< signal and chg> 0)
23 clr:=#FBCDD2
24 else
25 clr:=color.white
26
27 plot(hist,style=plot.style_histogram,linewidth=4,color=clr)
MACDのサンプルですが、保存すると17行目で 「Shadowing variable 'clr' which exists in parent scope. Did you want to use the ':=' operator instead of '=' ?」 エラーになります。
17行目と19行目、同じような内容ですが、19行目はエラーになりません。
なにが違うのか、それは「=」と「:=」の違いです。Pineでは「=」は変数の定義で利用して、変数への代入は「:=」を使います。
この記事が気に入ったらサポートをしてみませんか?