BOLLINGER Bands with MA_EMA/SMA_日本語
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © FukuiFinance

//@version=5
indicator("BOLLINGER Bands with MA_EMA/SMA", overlay = true)

//MAの種類
MethodMA = input.string(defval = "SMA", title = "MAの種類", options = ["EMA", "SMA"])

//EMA5
length_MA5 = input(title='短期MAの期間', defval=5)
MA5 = MethodMA == "EMA"? ta.ema(close, length_MA5): ta.sma(close, length_MA5)
PlotEMA5 = plot(MA5, title = "MA5", color = color.rgb(198, 68, 68), linewidth = 2)

//EMA20
length_MA20 = input(title='中期MAの期間', defval=20)
MA20 = MethodMA == "EMA"? ta.ema(close, length_MA20): ta.sma(close, length_MA20)
PlotEMA20 = plot(MA20, title = "MA20", color = color.rgb(59, 122, 54), linewidth = 2)

//EMA200
length_MA200 = input(title='長期MAの期間', defval=200)
MA200 = MethodMA == "EMA"? ta.ema(close, length_MA200): ta.sma(close, length_MA200)
PlotEMA200 = plot(MA200, title = "MA200", color = color.rgb(95, 31, 130), linewidth = 2)

//BOLLINGER Bands

lengthBB = input(20, title='BBの算出する期間')
EMABB = MethodMA == "EMA"? ta.ema(close, lengthBB): ta.sma(close, lengthBB)
dev = ta.stdev(close, lengthBB)

line1 = plot(EMABB + dev, color=color.rgb(60, 60, 60, 100), linewidth=1)
line2 = plot(EMABB + dev * 2, color=color.rgb(60, 60, 60, 100), linewidth=1)
line3 = plot(EMABB - dev, color=color.rgb(60, 60, 60, 100), linewidth=1)
line4 = plot(EMABB - dev * 2, color=color.rgb(60, 60, 60, 100), linewidth=1)

//帯の背景色変更
fill(line1, line2, color=color.rgb(76, 149, 47, 70), title = "BBの背景_上")
fill(line3, line4, color=color.rgb(76, 149, 47, 70), title = "BBの背景_下")
