
トレビューインジ【MA_Trend_BackgroundColor_2.5】
えー、バージョンアップになります。
今までの「ver.2」では各時間足のMA期間が変更できなかったですが、
変更可能にしました。

//@version=5
indicator(title="MA_Trend_Background_Color ver.2.5 by YMP", shorttitle="MA_Trend_Background_Color ver.2.5 by YMP", overlay=true)
// Function to calculate moving average based on selected type
ma_function(src, len, type) =>
if type == "SMA"
ta.sma(src, len)
else if type == "EMA"
ta.ema(src, len)
else if type == "WMA"
ta.wma(src, len)
else
na
// Inputs for MA periods (parameters to change based on timeframe)
ma_period_5min = input.int(60, title="5-Minute Time Frame MA Period", minval=1)
ma_period_15min = input.int(80, title="15-Minute Time Frame MA Period", minval=1)
ma_period_1hour = input.int(80, title="1-Hour Time Frame MA Period", minval=1)
ma_period_4hour = input.int(100, title="4-Hour Time Frame MA Period", minval=1)
ma_period_daily = input.int(100, title="Daily Time Frame MA Period", minval=1)
// Inputs for MA
src1 = input.source(close, title="MA Source")
type1 = input.string("WMA", title="MA Type", options=["SMA", "EMA", "WMA"])
// Colors for background
bg_color_up = input.color(#f77c80, title="Uptrend Background Color")
bg_color_down = input.color(#4dd0e1, title="Downtrend Background Color")
bg_opacity = input.int(20, minval=0, maxval=100, title="Background Opacity (%)")
// Determine MA length based on the current time frame and user inputs
get_ma_length_for_timeframe() =>
if timeframe.isintraday and timeframe.multiplier == 5
ma_period_5min // 5分足: MA期間60
else if timeframe.isintraday and timeframe.multiplier == 15
ma_period_15min // 15分足: MA期間80
else if timeframe.isintraday and timeframe.multiplier == 60
ma_period_1hour // 1時間足: MA期間80
else if timeframe.multiplier == 240
ma_period_4hour // 4時間足: MA期間100
else if timeframe.isdaily
ma_period_daily // 日足: MA期間100
else
ma_period_daily // デフォルト期間
// Get dynamic MA length based on the timeframe
len1 = get_ma_length_for_timeframe()
// Calculations for the MA
ma1 = ma_function(src1, len1, type1)
ma1_up = ma1 > ma1[1]
ma1_down = ma1 < ma1[1]
// Adjust the background colors based on opacity parameter
adjusted_bg_up = color.new(bg_color_up, 100 - bg_opacity)
adjusted_bg_down = color.new(bg_color_down, 100 - bg_opacity)
// Set the background color based on the MA trend
bgcolor(ma1_up ? adjusted_bg_up : ma1_down ? adjusted_bg_down : na, title="Background Color")
今回の記事が良かったと思ったら、
お気持ち購入¥500。
ここから先は
¥ 500
この記事が気に入ったらチップで応援してみませんか?