예스스탁
예스스탁 답변
2024-09-19 13:00:21
안녕하세요
예스스탁입니다.
input : output_smoothing(20);# + 1
input : use_double(true);
input : smoothing(4);# + 1
input : atr_length(200);
input : multiplier(6);
input : range_switch("Body");#["Body", "Wick"]
input : style("MA Direction");#["MA Direction", "MA Cross", "Solid"]
input : bullish_color(rgb(33, 255, 120));
input : bearish_color(rgb(255, 33, 33));
input : neutral_color(rgb(137, 137, 137));
var : candle_top(0),candle_bottom(0);
var : smooth_top(0),smooth_bottom(0);
var : tr(0),ar(0),flag(False);
var : sr_ma(Nan),current_range(Nan),top_range(Nan),bottom_range(Nan);
var : out(0),smooth_top_range(0),smooth_bottom_range(0);
var : source(0);
source = c;
candle_top = iff(range_switch != "Body" , high , max(open, close));
candle_bottom = iff(range_switch != "Body" , low , min(open, close));
smooth_top = ma(candle_top, smoothing+1);
smooth_bottom = ma(candle_bottom, smoothing+1);
tr = candle_top - candle_bottom;
ar = ma(tr, atr_length);
flag = smooth_top > top_range or smooth_bottom < bottom_range or IsNaN(current_range);
if flag Then
{
sr_ma = source;
current_range = ar * multiplier;
top_range = sr_ma + current_range;
bottom_range = sr_ma - current_range;
}
if use_double == true Then
{
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);
}
else
{
out = WMA(sr_ma, output_smoothing);
smooth_top_range = WMA(top_range, output_smoothing);
smooth_bottom_range = WMA(bottom_range, output_smoothing);
}
var : plot_neutral(False),plot_bullish(False),plot_bearish(False);
var : ma_cross(0);
plot_neutral = high > out and low < out;
plot_bullish = low > out;
plot_bearish = high < out;
if plot_bullish Then
ma_cross = bullish_color;
if plot_bearish Then
ma_cross = bearish_color;
if plot_neutral Then
ma_cross = neutral_color;
var : ma_delta_neutral(False),ma_delta_bullish(False),ma_delta_bearish(False);
var : ma_delta(0),ma_color(0);
ma_delta_neutral = sr_ma - IFF(IsNan(out[1]),0,out[1]) == 0;
ma_delta_bullish = sr_ma - IFF(IsNan(out[1]),0,out[1]) > 0;
ma_delta_bearish = sr_ma - IFF(IsNan(out[1]),0,out[1]) < 0;
if ma_delta_bullish Then
ma_delta = bullish_color;
if ma_delta_bearish Then
ma_delta = bearish_color;
if ma_delta_neutral Then
ma_delta = neutral_color;
ma_color = iff(style == "MA Cross", ma_cross,IFf(style == "MA Direction" , ma_delta , neutral_color));
var : alpha(Red);
plot1(out, "SR MA", ma_color);
plot2(smooth_top_range, "Top Range", alpha);
plot3(smooth_bottom_range, "Bottom Range", alpha);
즐거운 하루되세요
> 다올 님이 쓴 글입니다.
> 제목 : 부탁드립니다.
> 트레이딩 뷰 수식입니다.
적용가능하도록 부탁 드립니다.
indicator("Sentiment Range MA [ChartPrime]", overlay = true, timeframe = "", timeframe_gaps = false)
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)
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]
source = input.source(close, "Source", group = "Settings")
output_smoothing = input.int(20, "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")
style = input.string("MA Direction", "Color Style", ["MA Direction", "MA Cross", "Solid"], group = "Color")
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", "This doubles as the solid color.", group = "Color")
[sr_ma, top_range, bottom_range] = sr_ma(source, output_smoothing, smoothing, atr_length, multiplier, range_switch, use_double)
var color ma_delta = na
var color ma_cross = na
plot_neutral = high > sr_ma and low < sr_ma
plot_bullish = low > sr_ma
plot_bearish = high < sr_ma
if plot_bullish
ma_cross := bullish_color
if plot_bearish
ma_cross := bearish_color
if plot_neutral
ma_cross := neutral_color
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
if ma_delta_bullish
ma_delta := bullish_color
if ma_delta_bearish
ma_delta := bearish_color
if ma_delta_neutral
ma_delta := neutral_color
ma_color = style == "MA Cross"? ma_cross : style == "MA Direction" ? ma_delta : neutral_color
alpha = color.new(color.red, 100)
ma = plot(sr_ma, "SR MA", ma_color, 3)
top = plot(top_range, "Top Range", alpha)
bottom = plot(bottom_range, "Bottom Range", alpha)
fill(ma, top, top_value = top_range, bottom_value = sr_ma, bottom_color = color.new(ma_color, 82), top_color = alpha)
fill(ma, bottom, top_value = sr_ma, bottom_value = bottom_range, top_color = color.new(ma_color, 82), bottom_color = alpha)