【無料】3本のSMA EMAローソク足クロスでアラートインジケーター

3MAccrossサムネイル (1) 無料インジケーター

TradingView用のインジケーターです。

 

SMAとEMAが切り替えられるMAが3本。その3本いずれかとローソク足がクロスした時点でアラートが鳴るようになっています。

3maccrossインジケーター画面

一見普通のMA(移動平均線)が表示されているインジケーターですが、MAにローソク足がクロスすることで鳴るアラートを設定できます。

 

MAはそれぞれ

  • MA1
  • MA2
  • MA3

と3本用意してあります。

MAはEMAとSMAを切り替え可能です。

 

ちなみに、全く同じような機能で4本のMAラインを設定できるインジケーターもあります。

≫【無料インジ】4本のSMA EMAローソク足クロスでアラート

 

え?そしたら4本の方がイイじゃん!という意見の方はまさにその通り。

普通に考えて4本の方が調節できて便利なのですが、なんとなくスタイリッシュな3本を作ってみただけです。

 

3MAcsrossパラメータ画面

MA1~3は、期間を調節できるので好みで設定してください。

 

3MAcsrossスタイル画面

 

 

スタイル画面はコチラ。

MA1~3の表示非表示が切り替えられ、太さや色を好みで設定できます。

 

3MAcsrossアラート画面

 

アラート画面がコチラ。

  • MA1とのクロスでアラート
  • MA2とのクロスでアラート
  • MA3とのクロスでアラート

と3種類用意してあります。

「MA1とのクロスでアラート」は、設定したMA1とローソク足がクロスするとアラートが鳴るという具合ですね。

 

ローソク足が確定してからのアラートを設定した場合、ローソク足のヒゲではなく実体がクロスしていたらアラートが鳴るようになっています。

 

ローソク足確定ではなく、クロスしたタイミングでアラートが鳴る設定をしている場合はローソク足がMAに触れたタイミングでアラートが鳴るようになっています。

 

ご自身のロジックに合わせて使い分けてください。

3MA C(candle)CROSSアラート コード

※2025/9 表示がズレていたので修正しました。

//@version=5
indicator("3MA Cross Indicator", shorttitle="3MA Cross", overlay=true)

// インプット設定
src = input.source(close, title="Source")

// MA1設定
maType1 = input.string("EMA", title="MA1 Type", options=["EMA", "SMA", "WMA", "RMA"])
length1 = input.int(5, title="MA1 Length", minval=1, maxval=500)
color1 = input.color(color.blue, title="MA1 Color")

// MA2設定
maType2 = input.string("EMA", title="MA2 Type", options=["EMA", "SMA", "WMA", "RMA"])
length2 = input.int(10, title="MA2 Length", minval=1, maxval=500)
color2 = input.color(color.red, title="MA2 Color")

// MA3設定
maType3 = input.string("EMA", title="MA3 Type", options=["EMA", "SMA", "WMA", "RMA"])
length3 = input.int(20, title="MA3 Length", minval=1, maxval=500)
color3 = input.color(color.green, title="MA3 Color")

// 表示設定
showMA1 = input.bool(true, title="Show MA1")
showMA2 = input.bool(true, title="Show MA2")
showMA3 = input.bool(true, title="Show MA3")

// 線の太さ設定
lineWidth = input.int(2, title="Line Width", minval=1, maxval=4)

// クロスシグナル設定
showCrossUp = input.bool(true, title="Show Cross Up Signals")
showCrossDown = input.bool(true, title="Show Cross Down Signals")
showMAAlignment = input.bool(true, title="Show MA Alignment Signals")

// MA計算関数
calcMA(source, length, maType) =>
    switch maType
        "EMA" => ta.ema(source, length)
        "SMA" => ta.sma(source, length)
        "WMA" => ta.wma(source, length)
        "RMA" => ta.rma(source, length)
        => ta.ema(source, length) // デフォルト

// MAの計算
ma1 = calcMA(src, length1, maType1)
ma2 = calcMA(src, length2, maType2)
ma3 = calcMA(src, length3, maType3)

// MAのプロット
plot(showMA1 ? ma1 : na, title="MA1", color=color1, linewidth=lineWidth)
plot(showMA2 ? ma2 : na, title="MA2", color=color2, linewidth=lineWidth)
plot(showMA3 ? ma3 : na, title="MA3", color=color3, linewidth=lineWidth)

// クロス条件
crossUpMA1 = ta.crossover(src, ma1)
crossDownMA1 = ta.crossunder(src, ma1)
crossUpMA2 = ta.crossover(src, ma2)
crossDownMA2 = ta.crossunder(src, ma2)
crossUpMA3 = ta.crossover(src, ma3)
crossDownMA3 = ta.crossunder(src, ma3)

// MA間のクロス条件
ma1_cross_ma2_up = ta.crossover(ma1, ma2)
ma1_cross_ma2_down = ta.crossunder(ma1, ma2)
ma1_cross_ma3_up = ta.crossover(ma1, ma3)
ma1_cross_ma3_down = ta.crossunder(ma1, ma3)
ma2_cross_ma3_up = ta.crossover(ma2, ma3)
ma2_cross_ma3_down = ta.crossunder(ma2, ma3)

// MAアライメント条件
bullishAlignment = ma1 > ma2 and ma2 > ma3  // 上昇トレンド
bearishAlignment = ma1 < ma2 and ma2 < ma3  // 下降トレンド
alignmentChanged = (bullishAlignment and not bullishAlignment[1]) or (bearishAlignment and not bearishAlignment[1])

// 価格とMAのクロスシグナル表示
plotshape(showCrossUp and crossUpMA1, title="MA1 Cross Up", location=location.belowbar, 
          style=shape.triangleup, size=size.small, color=color.lime, text="1↑")
plotshape(showCrossDown and crossDownMA1, title="MA1 Cross Down", location=location.abovebar, 
          style=shape.triangledown, size=size.small, color=color.red, text="1↓")

plotshape(showCrossUp and crossUpMA2, title="MA2 Cross Up", location=location.belowbar, 
          style=shape.triangleup, size=size.small, color=color.lime, text="2↑")
plotshape(showCrossDown and crossDownMA2, title="MA2 Cross Down", location=location.abovebar, 
          style=shape.triangledown, size=size.small, color=color.red, text="2↓")

plotshape(showCrossUp and crossUpMA3, title="MA3 Cross Up", location=location.belowbar, 
          style=shape.triangleup, size=size.small, color=color.lime, text="3↑")
plotshape(showCrossDown and crossDownMA3, title="MA3 Cross Down", location=location.abovebar, 
          style=shape.triangledown, size=size.small, color=color.red, text="3↓")

// MAアライメントシグナル表示
plotshape(showMAAlignment and bullishAlignment and not bullishAlignment[1], title="Bullish Alignment", 
          location=location.belowbar, style=shape.diamond, size=size.normal, color=color.lime, text="🔥")
plotshape(showMAAlignment and bearishAlignment and not bearishAlignment[1], title="Bearish Alignment", 
          location=location.abovebar, style=shape.diamond, size=size.normal, color=color.red, text="❄️")

// 背景色でトレンド表示
bgcolor(bullishAlignment ? color.new(color.lime, 95) : bearishAlignment ? color.new(color.red, 95) : na, title="Trend Background")

// 価格とMAのクロスアラート
alertcondition(crossUpMA1, title="MA1 Cross Up", message="Price crossed above MA1 ({{maType1}} {{length1}})!")
alertcondition(crossDownMA1, title="MA1 Cross Down", message="Price crossed below MA1 ({{maType1}} {{length1}})!")
alertcondition(crossUpMA2, title="MA2 Cross Up", message="Price crossed above MA2 ({{maType2}} {{length2}})!")
alertcondition(crossDownMA2, title="MA2 Cross Down", message="Price crossed below MA2 ({{maType2}} {{length2}})!")
alertcondition(crossUpMA3, title="MA3 Cross Up", message="Price crossed above MA3 ({{maType3}} {{length3}})!")
alertcondition(crossDownMA3, title="MA3 Cross Down", message="Price crossed below MA3 ({{maType3}} {{length3}})!")

// MA間のクロスアラート
alertcondition(ma1_cross_ma2_up, title="MA1 crosses above MA2", message="MA1 crossed above MA2 - Bullish signal!")
alertcondition(ma1_cross_ma2_down, title="MA1 crosses below MA2", message="MA1 crossed below MA2 - Bearish signal!")
alertcondition(ma1_cross_ma3_up, title="MA1 crosses above MA3", message="MA1 crossed above MA3 - Strong bullish signal!")
alertcondition(ma1_cross_ma3_down, title="MA1 crosses below MA3", message="MA1 crossed below MA3 - Strong bearish signal!")
alertcondition(ma2_cross_ma3_up, title="MA2 crosses above MA3", message="MA2 crossed above MA3 - Trend change!")
alertcondition(ma2_cross_ma3_down, title="MA2 crosses below MA3", message="MA2 crossed below MA3 - Trend change!")

// MAアライメントアラート
alertcondition(bullishAlignment and not bullishAlignment[1], title="Bullish MA Alignment", message="All MAs aligned bullish - Strong uptrend!")
alertcondition(bearishAlignment and not bearishAlignment[1], title="Bearish MA Alignment", message="All MAs aligned bearish - Strong downtrend!")

// 統合アラート条件
anyCrossUp = crossUpMA1 or crossUpMA2 or crossUpMA3
anyCrossDown = crossDownMA1 or crossDownMA2 or crossDownMA3
anyCross = anyCrossUp or anyCrossDown

alertcondition(anyCrossUp, title="Any MA Cross Up", message="Price crossed above any MA!")
alertcondition(anyCrossDown, title="Any MA Cross Down", message="Price crossed below any MA!")
alertcondition(anyCross, title="Any MA Cross", message="Price crossed any MA!")

// 情報テーブル(現在の状態)
if barstate.islast
    var table infoTable = table.new(position.top_right, 3, 5, bgcolor=color.white, border_width=1)
    table.cell(infoTable, 0, 0, "MA", text_color=color.black, bgcolor=color.gray)
    table.cell(infoTable, 1, 0, "Value", text_color=color.black, bgcolor=color.gray)
    table.cell(infoTable, 2, 0, "vs Price", text_color=color.black, bgcolor=color.gray)
    
    // MA1情報
    ma1Status = src > ma1 ? "Above" : src < ma1 ? "Below" : "Equal"
    ma1StatusColor = src > ma1 ? color.lime : src < ma1 ? color.red : color.gray
    table.cell(infoTable, 0, 1, "MA1(" + str.tostring(length1) + ")", text_color=color1)
    table.cell(infoTable, 1, 1, str.tostring(ma1, "#.####"), text_color=color.black)
    table.cell(infoTable, 2, 1, ma1Status, text_color=ma1StatusColor)
    
    // MA2情報
    ma2Status = src > ma2 ? "Above" : src < ma2 ? "Below" : "Equal"
    ma2StatusColor = src > ma2 ? color.lime : src < ma2 ? color.red : color.gray
    table.cell(infoTable, 0, 2, "MA2(" + str.tostring(length2) + ")", text_color=color2)
    table.cell(infoTable, 1, 2, str.tostring(ma2, "#.####"), text_color=color.black)
    table.cell(infoTable, 2, 2, ma2Status, text_color=ma2StatusColor)
    
    // MA3情報
    ma3Status = src > ma3 ? "Above" : src < ma3 ? "Below" : "Equal"
    ma3StatusColor = src > ma3 ? color.lime : src < ma3 ? color.red : color.gray
    table.cell(infoTable, 0, 3, "MA3(" + str.tostring(length3) + ")", text_color=color3)
    table.cell(infoTable, 1, 3, str.tostring(ma3, "#.####"), text_color=color.black)
    table.cell(infoTable, 2, 3, ma3Status, text_color=ma3StatusColor)
    
    // トレンド情報
    trendStatus = bullishAlignment ? "Bullish" : bearishAlignment ? "Bearish" : "Neutral"
    trendColor = bullishAlignment ? color.lime : bearishAlignment ? color.red : color.gray
    table.cell(infoTable, 0, 4, "Trend", text_color=color.black)
    table.cell(infoTable, 1, 4, trendStatus, text_color=trendColor)
    table.cell(infoTable, 2, 4, "", text_color=color.black)

 

 

他にもマルチタイムフレームでEMA SMA表示できるインジも作りました。

マルチタイム表示できるEMAとSMA6本インジケーター作った件
チャートを見ていると「うわ 5分見てるけどこれ1時間足だとEMAどの辺にあるんだろ」 って時ありませんかね?自分だけですかね 例えばみんな大好き200EMAとかだと、短い時間足で確認して、長い時間足で~とかっていちいち切り替えるのがかなり面...

コメント

タイトルとURLをコピーしました