見出し画像

TradingView:相場師朗さんの5本の移動平均線


5本の移動平均線


チャートがよく見えないので下に貼り付けます

背景の色

上昇、下降トレンドで背景に色

GC,DC


パーフェクトオーダーを数値表示


PineScriptソース

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Arahabakan
// 【概要】移動平均線を5本表示 短期(赤5)中期(緑20)中長期(青60)長期(紫100) 超長期(橙300)

//@version=5
indicator("ind_相場師朗MA", overlay = true)

// func Perfect Order
retOrder(ma_val, s_ma, m_ma, l_ma, x_ma) => 
    ma4_array = array.from(s_ma,m_ma,l_ma,x_ma)
    if ma_val==array.max(ma4_array,0)
        1
    else if ma_val==array.max(ma4_array,1)
        2
    else if ma_val==array.max(ma4_array,2)
        3
    else
        4

// ma
sw_ma = input.bool(false, "表示する移動平均(チェック:SMA, 空白:EMA")
// ma本数
// s_len = input.bool(true,"S MA") ? input.int(5, "S MA", minval=1) : na
s_len = input.int(5,  "本数変更:  5日MA", minval=0)
m_len = input.int(20, "本数変更: 20日MA", minval=0)
l_len = input.int(60, "本数変更: 60日MA", minval=0)
x_len= input.int(100, "本数変更:100日MA", minval=0)
z_len= input.int(300, "本数変更:300日MA", minval=0)

// bg_per
bg_green = input.int(88,"緑背景通過%",minval=0,maxval=100,step=1)
bg_red = input.int(88,"赤背景通過%",minval=0,maxval=100,step=1)

// maclose = sw_ma ? ta.sma(close,1) : ta.ema(close,1)
ma_short = if s_len > 0 
    sw_ma ? ta.sma(close, s_len) : ta.ema(close, s_len)
else
    na

ma_mid = if m_len > 0
    sw_ma ? ta.sma(close, m_len) : ta.ema(close, m_len)
else
    na

ma_long = if l_len > 0
    sw_ma ? ta.sma(close, l_len) : ta.ema(close, l_len)
else
    na

ma_xlong = if x_len > 0
    sw_ma ? ta.sma(close, x_len) : ta.ema(close, x_len)
else
    na

ma_zlong = if z_len > 0
    sw_ma ? ta.sma(close, z_len) : ta.ema(close, z_len)
else
    na
//plot ma
plot(ma_short,"short ma",color=color.red) 
plot(ma_mid,"mid ma",color=color.green) 
plot(ma_long,"lomg ma",color=color.blue) 
plot(ma_xlong,"xlong ma",color=color.purple) 
plot(ma_zlong,"zlong ma",color=color.orange) 

// ma order

order_s = retOrder(ma_short,ma_short,ma_mid, ma_long, ma_xlong)
order_m = retOrder(ma_mid,ma_short,ma_mid, ma_long, ma_xlong)
order_l = retOrder(ma_long,ma_short,ma_mid, ma_long, ma_xlong)
order_x = retOrder(ma_xlong,ma_short,ma_mid, ma_long, ma_xlong)

// table (PPP表示)
var pppTable = table.new(position = position.bottom_right,columns = 2,rows = 2) //,bgcolor=color.rgb(0, 0, 0)
if barstate.islast
    _str = str.format("{0}{1}{2}{3}",order_s,order_m,order_l,order_x)
    _textcolor = switch _str
        "1234" => color.rgb(0, 255, 8)
        "4321" => color.rgb(255, 0, 0)
        => color.white
    table.cell(table_id = pppTable, column = 0, row = 0, text = _str, text_color = _textcolor, text_size = size.large)

// cross short, middle
_updown = if ma_mid[0] > ma_short[0]
    1
else
    2
plot(ta.cross(ma_short, ma_mid) and _updown==1 ? ma_short : na, color=#ff72e8d1, style = plot.style_cross, linewidth = 4, title="dw")
plot(ta.cross(ma_short, ma_mid) and _updown==2 ? ma_mid : na, color=#3be910, style = plot.style_cross, linewidth = 4, title="up")

// bgcolor
bgcolor((ma_mid > ma_mid[1]) and (ma_short > ma_short[1]) ? color.new(color.green,bg_green) : na)
bgcolor((ma_mid < ma_mid[1]) and (ma_short < ma_short[1]) ? color.new(color.red, bg_red) : na)

この記事が気に入ったらサポートをしてみませんか?