見出し画像

TradingView:インジケータ

簡単なインジケータです。PineScriptを学びながら作ってます。


移動平均線4本とその順番を表示

  • 移動平均線4本、初期値5, 20, 60, 100

  • SMA, EMAの選択可能

  • 移動平均線の順番を数字で表示(S, M, L, X)

移動平均線4本とその順番を表示
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © takaharafamilia
// 【概要】移動平均線を4本表示 短期(5)中期(20)中長期(60)長期(100)


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

// my func
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 or EMA")
s_len = input.int(5, "S MA", minval=1)
m_len = input.int(20, "M MA", minval=1)
l_len = input.int(60, "L MA", minval=1)
x_len= input.int(100, "XL MA", minval=1)

maclose = sw_ma ? ta.sma(close,1) : ta.ema(close,1)
ma_short = sw_ma ? ta.sma(close, s_len) : ta.ema(close, s_len)
ma_mid = sw_ma ? ta.sma(close, m_len) : ta.ema(close, m_len)
ma_long = sw_ma ? ta.sma(close, l_len) : ta.ema(close, l_len)
ma_xlong = sw_ma ? ta.sma(close, x_len) : ta.ema(close, x_len)

//plot ma
p_s = plot(ma_short,"short ma",color=color.red) 
plot(ma_mid,"mid ma",color=color.blue) 
plot(ma_long,"lomg ma",color=color.yellow) 
plot(ma_xlong,"xlong ma",color=color.green) 

// 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 = 1,rows = 2, border_width = -7) //,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 = "SMLX", text_color = _textcolor, text_size = size.large)
    table.cell(table_id = pppTable, column = 0, row = 1, text = _str, text_color = _textcolor, text_size = size.large)

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