커뮤니티

수식 부탁드립니다

프로필 이미지
사노소이
2025-06-11 12:00:09
294
글번호 191593
답변완료
지표식 부탁드립니다. //@version=5 indicator("SR MA", overlay = true, timeframe = "", timeframe_gaps = false) // Simple filter function simple_filter(float source, int length, bool duel_filter) => switch duel_filter false => ta.wma(source, length) true => ta.wma(ta.sma(source, length), length) // Main SR MA function sr_ma(float source = close, int output_smoothing = 3, int trigger_smoothing = 1, int atr_length = 50, float multiplier = 1, string range_switch = "Body", bool duel_filter = false) => candle_top = range_switch != "Body" ? high : math.max(open, close) candle_bottom = range_switch != "Body" ? low : math.min(open, close) smooth_top = ta.sma(candle_top, trigger_smoothing) smooth_bottom = ta.sma(candle_bottom, trigger_smoothing) tr = candle_top - candle_bottom atr = ta.sma(tr, atr_length) var float sr_ma = na var float current_range = na var float top_range = na var float bottom_range = na flag = smooth_top > top_range or smooth_bottom < bottom_range or na(current_range) if flag sr_ma := source current_range := atr * multiplier top_range := sr_ma + current_range bottom_range := sr_ma - current_range out = simple_filter(sr_ma, output_smoothing, duel_filter) smooth_top_range = simple_filter(top_range, output_smoothing, duel_filter) smooth_bottom_range = simple_filter(bottom_range, output_smoothing, duel_filter) [out, smooth_top_range, smooth_bottom_range] // === Inputs === source = input.source(close, "Source", group = "Settings") output_smoothing = input.int(100, "Length", minval = 0, group = "Settings") + 1 use_double = input.bool(true, "Double Filter", group = "Settings") smoothing = input.int(4, "Trigger Smoothing", minval = 0, group = "Settings") + 1 atr_length = input.int(200, "ATR Length", minval = 1, group = "Settings") multiplier = input.float(6, "Range Multiplier", minval = 0, step = 0.125, group = "Settings") range_switch = input.string("Body", "Range Style", ["Body", "Wick"], group = "Settings") // === Color Inputs === bullish_color = input.color(color.rgb(33, 255, 120), "Bullish Color", group = "Color") bearish_color = input.color(color.rgb(255, 33, 33), "Bearish Color", group = "Color") neutral_color = input.color(color.rgb(137, 137, 137), "Neutral Color", tooltip = "This doubles as the solid color.", group = "Color") // === Calculate SR MA & Ranges === [sr_ma, top_range, bottom_range] = sr_ma(source, output_smoothing, smoothing, atr_length, multiplier, range_switch, use_double) // === MA Color Logic === ma_delta_neutral = sr_ma - nz(sr_ma[1]) == 0 ma_delta_bullish = sr_ma - nz(sr_ma[1]) > 0 ma_delta_bearish = sr_ma - nz(sr_ma[1]) < 0 ma_color = ma_delta_neutral ? neutral_color : ma_delta_bullish ? bullish_color : bearish_color // === Plot SR MA and Ranges === alpha = color.new(color.red, 100) ma = plot(sr_ma, "SR MA", ma_color, 4) top = plot(top_range, "Top Range", ma_color, 2) bottom = plot(bottom_range, "Bottom Range", ma_color, 2) fill(ma, top, top_value = top_range, bottom_value = sr_ma, bottom_color = color.new(ma_color, 80), top_color = alpha) fill(ma, bottom, top_value = sr_ma, bottom_value = bottom_range, top_color = color.new(ma_color, 80), bottom_color = alpha) // === Detect Color Change === var color prev_color = na color_change = ma_color != prev_color and not na(prev_color) prev_color := ma_color color_change_to_bullish = color_change and ma_color == bullish_color color_change_to_bearish = color_change and ma_color == bearish_color // === Visual Markers === plotshape(color_change_to_bullish, title="MA Color Change to Bullish", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small, text="Bullish") plotshape(color_change_to_bearish, title="MA Color Change to Bearish", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small, text="Bearish") // === Alerts for Color Changes === alertcondition(color_change_to_bullish, title="SR MA Color Changed to Bullish", message="SR MA color changed to Bullish (Uptrend)") alertcondition(color_change_to_bearish, title="SR MA Color Changed to Bearish", message="SR MA color changed to Bearish (Downtrend)")
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-06-11 16:29:49

안녕하세요 예스스탁입니다. input : source(close); input : output_smoothing(100); input : use_double(true); input : smoothing(4); input : atr_length(200); input : multiplier(6); input : range_switch(0); #0:Body 1:Wick" input : bullish_color(Lime); input : bearish_color(Red); input : neutral_color(Gray); var : candle_top(0),candle_bottom(0),smooth_top(0),smooth_bottom(0),TR(0),ATR(0); var : sr_ma(Nan),current_range(Nan),top_range(Nan),bottom_range(Nan); var : flag(False); var : out(0),smooth_top_range(0),smooth_bottom_range(0); var : ma_delta_neutral(False),ma_delta_bullish(False),ma_delta_bearish(False); var : ma_color(Nan),alpha(0); candle_top = iff(range_switch != 0 , high , max(open, close)); candle_bottom = iff(range_switch != 0 , low , min(open, close)); smooth_top = ma(candle_top, smoothing+1); smooth_bottom = ma(candle_bottom, smoothing+1); tr = candle_top - candle_bottom; atr = ma(TR, atr_length); flag = smooth_top > top_range or smooth_bottom < bottom_range or IsNan(current_range) == true; if flag == true Then { sr_ma = source; current_range = atr * multiplier; top_range = sr_ma + current_range; bottom_range = sr_ma - current_range; } if use_double == False Then { out = WMA(sr_ma, output_smoothing+1); smooth_top_range = WMA(top_range, output_smoothing+1); smooth_bottom_range = WMA(bottom_range, output_smoothing+1); } Else { out = WMA(MA(sr_ma, output_smoothing+1), output_smoothing+1); smooth_top_range = WMA(MA(top_range, output_smoothing+1), output_smoothing+1); smooth_bottom_range = WMA(MA(bottom_range, output_smoothing+1), output_smoothing+1); } ma_delta_neutral = out - iff(isnan(out[1]),0,out[1]) == 0; ma_delta_bullish = out - iff(isnan(out[1]),0,out[1]) > 0; ma_delta_bearish = out - iff(isnan(out[1]),0,out[1]) < 0; ma_color = iff(ma_delta_neutral , neutral_color , iff(ma_delta_bullish , bullish_color , bearish_color)); plot1(out, "SR MA", ma_color,Def, 4); plot2(smooth_top_range, "Top Range", ma_color,Def, 2); plot3(smooth_bottom_range, "Bottom Range", ma_color,Def, 2); 즐거운 하루되세요 > 사노소이 님이 쓴 글입니다. > 제목 : 수식 부탁드립니다 > 지표식 부탁드립니다. //@version=5 indicator("SR MA", overlay = true, timeframe = "", timeframe_gaps = false) // Simple filter function simple_filter(float source, int length, bool duel_filter) => switch duel_filter false => ta.wma(source, length) true => ta.wma(ta.sma(source, length), length) // Main SR MA function sr_ma(float source = close, int output_smoothing = 3, int trigger_smoothing = 1, int atr_length = 50, float multiplier = 1, string range_switch = "Body", bool duel_filter = false) => candle_top = range_switch != "Body" ? high : math.max(open, close) candle_bottom = range_switch != "Body" ? low : math.min(open, close) smooth_top = ta.sma(candle_top, trigger_smoothing) smooth_bottom = ta.sma(candle_bottom, trigger_smoothing) tr = candle_top - candle_bottom atr = ta.sma(tr, atr_length) var float sr_ma = na var float current_range = na var float top_range = na var float bottom_range = na flag = smooth_top > top_range or smooth_bottom < bottom_range or na(current_range) if flag sr_ma := source current_range := atr * multiplier top_range := sr_ma + current_range bottom_range := sr_ma - current_range out = simple_filter(sr_ma, output_smoothing, duel_filter) smooth_top_range = simple_filter(top_range, output_smoothing, duel_filter) smooth_bottom_range = simple_filter(bottom_range, output_smoothing, duel_filter) [out, smooth_top_range, smooth_bottom_range] // === Inputs === source = input.source(close, "Source", group = "Settings") output_smoothing = input.int(100, "Length", minval = 0, group = "Settings") + 1 use_double = input.bool(true, "Double Filter", group = "Settings") smoothing = input.int(4, "Trigger Smoothing", minval = 0, group = "Settings") + 1 atr_length = input.int(200, "ATR Length", minval = 1, group = "Settings") multiplier = input.float(6, "Range Multiplier", minval = 0, step = 0.125, group = "Settings") range_switch = input.string("Body", "Range Style", ["Body", "Wick"], group = "Settings") // === Color Inputs === bullish_color = input.color(color.rgb(33, 255, 120), "Bullish Color", group = "Color") bearish_color = input.color(color.rgb(255, 33, 33), "Bearish Color", group = "Color") neutral_color = input.color(color.rgb(137, 137, 137), "Neutral Color", tooltip = "This doubles as the solid color.", group = "Color") // === Calculate SR MA & Ranges === [sr_ma, top_range, bottom_range] = sr_ma(source, output_smoothing, smoothing, atr_length, multiplier, range_switch, use_double) // === MA Color Logic === ma_delta_neutral = sr_ma - nz(sr_ma[1]) == 0 ma_delta_bullish = sr_ma - nz(sr_ma[1]) > 0 ma_delta_bearish = sr_ma - nz(sr_ma[1]) < 0 ma_color = ma_delta_neutral ? neutral_color : ma_delta_bullish ? bullish_color : bearish_color // === Plot SR MA and Ranges === alpha = color.new(color.red, 100) ma = plot(sr_ma, "SR MA", ma_color, 4) top = plot(top_range, "Top Range", ma_color, 2) bottom = plot(bottom_range, "Bottom Range", ma_color, 2) fill(ma, top, top_value = top_range, bottom_value = sr_ma, bottom_color = color.new(ma_color, 80), top_color = alpha) fill(ma, bottom, top_value = sr_ma, bottom_value = bottom_range, top_color = color.new(ma_color, 80), bottom_color = alpha) // === Detect Color Change === var color prev_color = na color_change = ma_color != prev_color and not na(prev_color) prev_color := ma_color color_change_to_bullish = color_change and ma_color == bullish_color color_change_to_bearish = color_change and ma_color == bearish_color // === Visual Markers === plotshape(color_change_to_bullish, title="MA Color Change to Bullish", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small, text="Bullish") plotshape(color_change_to_bearish, title="MA Color Change to Bearish", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small, text="Bearish") // === Alerts for Color Changes === alertcondition(color_change_to_bullish, title="SR MA Color Changed to Bullish", message="SR MA color changed to Bullish (Uptrend)") alertcondition(color_change_to_bearish, title="SR MA Color Changed to Bearish", message="SR MA color changed to Bearish (Downtrend)")