답변완료
지표로 전환 부탁드려요
건강하세요
var : aa(0),bb(0),a(0),b(0),av(0),bv(0),d(0),e(0),f(0),g(0);
var : bf(0),sf(0),pbf(0),psf(0),bfh(0),SFH(0);
aa=C-(H+L)/2;
bb=(O+C+H+L+Iff(0<=aa,(C+H)/2,(C+L)/2))/5;
A=Accum(Iff(0<=aa,bb*V,0));
B=Accum(Iff(aa<0,bb*V,0));
AV=Accum(Iff(0<=aa,V,0));
BV=Accum(Iff(aa<0,V,0));
if sDate != sDate[1] Then
{
D=A[1];
E=B[1];
F=AV[1];
G=BV[1];
}
BF=(A-D)/(AV-F);
SF=(B-E)/(BV-G);
PBF=Iff(0<BF,BF,bb);
PSF=Iff(0<SF,SF,bb);
IF PBF>PSF && CROSSUP(C, PBF) && C>O TheN
Find(1);
2025-06-20
235
글번호 191964
지표
답변완료
수식 부탁드립니다
지표식 부탁 드립니다.
//@version=5
indicator(title='Machine Learning Momentum Index (MLMI)', shorttitle='Machine Learning Momentum Index (MLMI)', overlay=false, precision=1)
// ~~ ToolTips {
t1 ="This parameter controls the number of neighbors to consider while making a prediction using the k-Nearest Neighbors (k-NN) algorithm. By modifying the value of k, you can change how sensitive the prediction is to local fluctuations in the data. ₩n₩nA smaller value of k will make the prediction more sensitive to local variations and can lead to a more erratic prediction line. ₩n₩nA larger value of k will consider more neighbors, thus making the prediction more stable but potentially less responsive to sudden changes."
t2 ="The parameter controls the length of the trend used in computing the momentum. This length refers to the number of periods over which the momentum is calculated, affecting how quickly the indicator reacts to changes in the underlying price movements. ₩n₩nA shorter trend length (smaller momentumWindow) will make the indicator more responsive to short-term price changes, potentially generating more signals but at the risk of more false alarms. ₩n₩nA longer trend length (larger momentumWindow) will make the indicator smoother and less responsive to short-term noise, but it may lag in reacting to significant price changes."
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Input Parameters {
numNeighbors = input(200, title='Prediction Data (k)', tooltip=t1)
momentumWindow = input.int(20, step=2, minval=10, maxval=200, title='Trend Length', tooltip=t2)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Moving Averages & RSI {
MA_quick = ta.wma(close, 5)
MA_slow = ta.wma(close, 20)
rsi_quick = ta.wma(ta.rsi(close, 5),momentumWindow)
rsi_slow = ta.wma(ta.rsi(close, 20),momentumWindow)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Crossover Conditions {
pos = ta.crossover(MA_quick, MA_slow)
neg = ta.crossunder(MA_quick, MA_slow)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Type Definition {
type Data
array<float> parameter1
array<float> parameter2
array<float> priceArray
array<float> resultArray
// Create a Data object
var data = Data.new(array.new_float(1, 0), array.new_float(1, 0), array.new_float(1, 0), array.new_float(1, 0))
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Method that saves the last trade and temporarily holds the current one. {
method storePreviousTrade(Data d, p1, p2) =>
d.parameter1.push(d.parameter1.get(d.parameter1.size() - 1))
d.parameter2.push(d.parameter2.get(d.parameter2.size() - 1))
d.priceArray.push(d.priceArray.get(d.priceArray.size() - 1))
d.resultArray.push(close >= d.priceArray.get(d.priceArray.size() - 1) ? 1 : -1)
d.parameter1.set(d.parameter1.size() - 1, p1)
d.parameter2.set(d.parameter2.size() - 1, p2)
d.priceArray.set(d.priceArray.size() - 1, close)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Method to Make Prediction {
method knnPredict(Data d, p1, p2, k) =>
// Create a Distance Array
distances = array.new_float(0)
n = d.parameter1.size() - 1
for i = 0 to n
distance = math.sqrt(math.pow(p1 - d.parameter1.get(i), 2) + math.pow(p2 - d.parameter2.get(i), 2))
distances.push(distance)
// Get Neighbors
sortedDistances = distances.copy()
sortedDistances.sort()
셀렉티드Distances = sortedDistances.slice( 0, math.min(k, sortedDistances.size()))
maxDist = 셀렉티드Distances.max()
neighbors = array.new_float(0)
for i = 0 to distances.size() - 1
if distances.get(i) <= maxDist
neighbors.push(d.resultArray.get(i))
// Return Prediction
prediction = neighbors.sum()
prediction
if pos or neg
data.storePreviousTrade(rsi_slow, rsi_quick)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Plots {
prediction = data.knnPredict(rsi_slow, rsi_quick, numNeighbors)
prediction_ = plot(prediction, color=color.new(#426eff, 0), title="MLMI Prediction")
prediction_ma = ta.wma(prediction, 20)
plot(prediction_ma, color=color.new(#31ffc8, 0), title="WMA of MLMI Prediction")
hline(0, title="Mid Level")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Gradient Fill {
upper = ta.highest(prediction,2000)
lower = ta.lowest(prediction,2000)
upper_ = upper - ta.ema(ta.stdev(prediction,20),20)
lower_ = lower + ta.ema(ta.stdev(prediction,20),20)
channel_upper = plot(upper, color = na, editable = false, display = display.none)
channel_lower = plot(lower, color = na, editable = false, display = display.none)
channel_mid = plot(0, color = na, editable = false, display = display.none)
// ~~ Channel Gradient Fill {
fill(channel_mid, channel_upper, top_value = upper, bottom_value = 0, bottom_color = na, top_color = color.new(color.lime,75),title = "Channel Gradient Fill")
fill(channel_mid, channel_lower, top_value = 0, bottom_value = lower, bottom_color = color.new(color.red,75) , top_color = na,title = "Channel Gradient Fill")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Overbought/Oversold Gradient Fill {
fill(prediction_, channel_mid, upper, upper_, top_color = color.new(color.lime, 0), bottom_color = color.new(color.green, 100),title = "Overbought Gradient Fill")
fill(prediction_, channel_mid, lower_, lower, top_color = color.new(color.red, 100), bottom_color = color.new(color.red, 0),title = "Oversold Gradient Fill")
2025-06-20
270
글번호 191959
지표
답변완료
부틱드립니다
수고하십니다
매번 부탁드려서 죄송합니다
예스로 변경드립니다
// This Pine S cript™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ChartPrime
//@version=5
indicator('Linear Regression Channel', overlay = true, max_lines_count = 3)
// ---------------------------------------------------------------------------------------------------------------------}
// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
// ---------------------------------------------------------------------------------------------------------------------{
bool bands = input.bool(true, "Plot Linear Regression Bands", group = "Settings Bands")
int window = input.int(150, "Length", group = "Settings Bands")
float devlen_b = input.float(3., "Deviation Linear Regression Bands",step=0.1, group = "Settings Bands")
bool channel = input.bool(false, "Plot Linear Regression Channel", group = "Settings Channel")
int window1 = input.int(150, "Channel Length", group = "Settings Channel")
float devlen1 = input.float(1., "Deviation Linear Regression Channel",step=0.1, group = "Settings Channel")
bool channel1 = input.bool(false, "Plot Future Projection of linear regression", group = "Future Projection Channel")
bool arr_dirc = input.bool(false, "Plot Arrow Direction", group = "Future Projection Channel")
int window2 = input.int(50, "Length", group = "Future Projection Channel")
float devlen2 = input.float(1., "Deviation Future Projection Regression Channel",step=0.1, group = "Future Projection Channel")
// Define colors for up, down, and mid lines
color col_dn = #f01313
color col_up = color.aqua
color col_mid = color.yellow
color gray = color.gray
color fg_col = chart.fg_color
// Regression Channel Arrays Line
var reglines = array.new_line(3)
var reglines_ = array.new_line(3)
// ---------------------------------------------------------------------------------------------------------------------}
// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
// ---------------------------------------------------------------------------------------------------------------------{
//@function linear_regression
//@des cription Calculates linear regression coefficients for a given source and window.
//@param src (series float) The data series on which linear regression is calculated.
//@param window (int) The number of bars to use in the calculation.
//@returns the intercept slope, Deviation, end of the channel.
linear_regression(src, window) =>
sum_x = 0.0
sum_y = 0.0
sum_xy = 0.0
sum_x_sq = 0.0
// Calculate sums
for i = 0 to window - 1 by 1
sum_x += i + 1
sum_y += src[i]
sum_xy += (i + 1) * src[i]
sum_x_sq += math.pow(i + 1, 2)
// Calculate linear regression coefficients
slope = (window * sum_xy - sum_x * sum_y) / (window * sum_x_sq - math.pow(sum_x, 2))
intercept = (sum_y - slope * sum_x) / window
y1 = intercept + slope * (window - 1)
dev = 0.0
for i = 0 to window - 1
dev := dev + math.pow(src[i] - (slope * (window - i) + intercept), 2)
dev := math.sqrt(dev/window)
[intercept, y1, dev, slope]
[y2, y1, dev, slope] = linear_regression(close, window)
[y2_, y1_, dev_, slope_] = linear_regression(close, window1)
[y2__, y1__, dev__, slope__] = linear_regression(close, window2)
// Linear Regression Channel Lines
series float mid = y2 + slope
series float upper = mid + ta.rma(high - low, window) * devlen_b
series float lower = mid - ta.rma(high - low, window) * devlen_b
// Returns True for window length period
isAllowed = (last_bar_index - bar_index < window1)
// ---------------------------------------------------------------------------------------------------------------------}
// 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
// ---------------------------------------------------------------------------------------------------------------------{
// Plot upper, lower, and mid lines if channel is not enabled
p_u = plot(upper, color = bands and channel ? na : bands ? gray : na, linewidth = 2)
p_l = plot(lower, color = bands and channel ? na : bands ? gray : na, linewidth = 2)
p_m = plot(mid, color = bands and channel ? na : bands ? gray : na)
// Fill areas between upper/mid and lower/mid lines
fill(p_u, p_m, mid, upper, na, bands and channel ? na : bands ? color.new(col_up, 80) : na)
fill(p_m, p_l, lower, mid, bands and channel ? na : bands ? color.new(col_dn, 80) : na, na)
if barstate.islast and channel
for i = 0 to 2
array.set(reglines, i,
line.new(x1 = bar_index - (window1 - 1),
y1 = y1_ + dev_ * devlen1 * (i - 1),
x2 = bar_index,
y2 = y2_ + dev_ * devlen1 * (i - 1),
color = color.gray,
style = i % 2 == 1 ? line.style_dashed : line.style_solid,
width = 2,
extend = extend.none)
)
linefill.new(array.get(reglines, 1), array.get(reglines, 2), color = color.new(col_up, 90))
linefill.new(array.get(reglines, 1), array.get(reglines, 0), color = color.new(col_dn, 90))
if barstate.islast and channel1
for i = 0 to 2
array.set(reglines_, i,
line.new(x1 = bar_index - (window2 - 1),
y1 = y1__ + dev__ * devlen2 * (i - 1),
x2 = bar_index,
y2 = y2__ + dev__ * devlen2 * (i - 1),
color = color.gray,
style = i % 2 == 1 ? line.style_dotted : line.style_dashed,
width = 1,
extend = extend.right)
)
linefill.new(array.get(reglines_, 1), array.get(reglines_, 2), color = color.new(col_up, 95))
linefill.new(array.get(reglines_, 1), array.get(reglines_, 0), color = color.new(col_dn, 95))
if arr_dirc
l1 = label.new(chart.point.from_index(bar_index, hl2 > y2__ ? high : low),
text = hl2 > y2__ ? "⇗" : hl2 < y2__ ? "⇘" : "⇒",
textcolor = hl2 > y2__ ? col_up : hl2 < y2__ ? col_dn : gray,
color = color(na),
size = size.huge,
style = label.style_label_left
)
label.delete(l1[1])
// Bar Heat Map
b_c = (close - lower) / (upper - lower)
b_c := b_c > 1 ? 1 : b_c < 0 ? 0 : b_c
bar_color = channel ?
(isAllowed ?
(b_c <= 0.5 ? color.from_gradient(b_c, 0, 0.5, col_up, col_mid) : color.from_gradient(b_c, 0.5, 1, col_mid, col_dn))
: na)
: (b_c >= 0.5 ? color.from_gradient(b_c, 0.5, 1, col_mid, col_up) : color.from_gradient(b_c, 0, 0.5, col_dn, col_mid))
plotcandle(open, high, low, close,
title = "Bar HeatMap",
color = bar_color,
wickcolor = bar_color,
bordercolor = bar_color
)
barcolor(bar_color)
// Conditions for crossovers
condition1 = bands and channel ? na : bands ? ta.pivotlow(3, 3) and close < lower : na
condition2 = bands and channel ? na : bands ? ta.pivothigh(3, 3) and close > upper: na
// Plot markers for channel break outs
plotchar(condition1, "", "◆", size=size.tiny, location=location.belowbar, color = col_up)
plotchar(condition2, "", "◆", size=size.tiny, location=location.abovebar, color = col_dn)
// ------------------------------------------------------------------------------------
2025-06-20
273
글번호 191951
지표
답변완료
트레이딩뷰 지표 변환 요청
트레이딩뷰 지표소스로 종목 검색식을 만들고 싶은데
가능할까요?
지표상 Buy 신호 종목 검색을 하고 싶습니다.
//@version=4
study("Hull Trend", shorttitle="HMA Trend",overlay=true)
length = input(24)
src = input(hl2)
showcross = input(true, "Show cross over/under")
hma(_src, _length)=>
wma((2 * wma(_src, _length / 2)) - wma(_src, _length), round(sqrt(_length)))
hma3(_src, _length)=>
p = length/2
wma(wma(close,p/3)*3 - wma(close,p/2) - wma(close,p),p)
a = hma(src, length)
b = hma3(src, length)
c = b > a ? color.lime : color.red
p1 = plot(a,color=c,linewidth=1,transp=75)
p2 = plot(b,color=c,linewidth=1,transp=75)
fill(p1,p2,color=c,transp=55)
crossdn = a > b and a[1] < b[1]
crossup = b > a and b[1] < a[1]
plotshape(showcross and crossdn ? a : na, location=location.absolute, style=shape.labeldown, color=color.red, size=size.tiny, text="Sell", textcolor=color.white, transp=0, offset=-1)
plotshape(showcross and crossup ? a : na, location=location.absolute, style=shape.labelup, color=color.green, size=size.tiny, text="Buy", textcolor=color.white, transp=0, offset=-1)
2025-06-20
300
글번호 191949
종목검색
답변완료
부틱드립니다
수고하십니다
예스로 부탁드립니다
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=5
indicator("Order Block Detector [LuxAlgo]"
, overlay = true
, max_boxes_count = 500
, max_labels_count = 500
, max_lines_count = 500)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length = input.int(5, 'Volume Pivot Length'
, minval = 1)
bull_ext_last = input.int(3, 'Bullish OB '
, minval = 1
, inline = 'bull')
bg_bull_css = input.color(color.new(#169400, 80), ''
, inline = 'bull')
bull_css = input.color(#169400, ''
, inline = 'bull')
bull_avg_css = input.color(color.new(#9598a1, 37), ''
, inline = 'bull')
bear_ext_last = input.int(3, 'Bearish OB'
, minval = 1
, inline = 'bear')
bg_bear_css = input.color(color.new(#ff1100, 80), ''
, inline = 'bear')
bear_css = input.color(#ff1100, ''
, inline = 'bear')
bear_avg_css = input.color(color.new(#9598a1, 37), ''
, inline = 'bear')
line_style = input.string('⎯⎯⎯', 'Average Line Style'
, options = ['⎯⎯⎯', '----', '····'])
line_width = input.int(1, 'Average Line Width'
, minval = 1)
mitigation = input.string('Wick', 'Mitigation Methods'
, options = ['Wick', 'Close'])
//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
//Line Style function
get_line_style(style) =>
out = switch style
'⎯⎯⎯' => line.style_solid
'----' => line.style_dashed
'····' => line.style_dotted
//Function to get order block coordinates
get_coordinates(condition, top, btm, ob_val)=>
var ob_top = array.new_float(0)
var ob_btm = array.new_float(0)
var ob_avg = array.new_float(0)
var ob_left = array.new_int(0)
float ob = na
//Append coordinates to arrays
if condition
avg = math.avg(top, btm)
array.unshift(ob_top, top)
array.unshift(ob_btm, btm)
array.unshift(ob_avg, avg)
array.unshift(ob_left, time[length])
ob := ob_val
[ob_top, ob_btm, ob_avg, ob_left, ob]
//Function to remove mitigated order blocks from coordinate arrays
remove_mitigated(ob_top, ob_btm, ob_left, ob_avg, target, bull)=>
mitigated = false
target_array = bull ? ob_btm : ob_top
for element in target_array
idx = array.indexof(target_array, element)
if (bull ? target < element : target > element)
mitigated := true
array.remove(ob_top, idx)
array.remove(ob_btm, idx)
array.remove(ob_avg, idx)
array.remove(ob_left, idx)
mitigated
//Function to set order blocks
set_order_blocks(ob_top, ob_btm, ob_left, ob_avg, ext_last, bg_css, border_css, lvl_css)=>
var ob_box = array.new_box(0)
var ob_lvl = array.new_line(0)
//Fill arrays with boxes/lines
if barstate.isfirst
for i = 0 to ext_last-1
array.unshift(ob_box, box.new(na,na,na,na
, xloc = xloc.bar_time
, extend= extend.right
, bgcolor = bg_css
, border_color = color.new(border_css, 70)))
array.unshift(ob_lvl, line.new(na,na,na,na
, xloc = xloc.bar_time
, extend = extend.right
, color = lvl_css
, style = get_line_style(line_style)
, width = line_width))
//Set order blocks
if barstate.islast
if array.size(ob_top) > 0
for i = 0 to math.min(ext_last-1, array.size(ob_top)-1)
get_box = array.get(ob_box, i)
get_lvl = array.get(ob_lvl, i)
box.set_lefttop(get_box, array.get(ob_left, i), array.get(ob_top, i))
box.set_rightbottom(get_box, array.get(ob_left, i), array.get(ob_btm, i))
line.set_xy1(get_lvl, array.get(ob_left, i), array.get(ob_avg, i))
line.set_xy2(get_lvl, array.get(ob_left, i)+1, array.get(ob_avg, i))
//-----------------------------------------------------------------------------}
//Global elements
//-----------------------------------------------------------------------------{
var os = 0
var target_bull = 0.
var target_bear = 0.
n = bar_index
upper = ta.highest(length)
lower = ta.lowest(length)
if mitigation == 'Close'
target_bull := ta.lowest(close, length)
target_bear := ta.highest(close, length)
else
target_bull := lower
target_bear := upper
os := high[length] > upper ? 0 : low[length] < lower ? 1 : os[1]
phv = ta.pivothigh(volume, length, length)
//-----------------------------------------------------------------------------}
//Get bullish/bearish order blocks coordinates
//-----------------------------------------------------------------------------{
[bull_top
, bull_btm
, bull_avg
, bull_left
, bull_ob] = get_coordinates(phv and os == 1, hl2[length], low[length], low[length])
[bear_top
, bear_btm
, bear_avg
, bear_left
, bear_ob] = get_coordinates(phv and os == 0, high[length], hl2[length], high[length])
//-----------------------------------------------------------------------------}
//Remove mitigated order blocks
//-----------------------------------------------------------------------------{
mitigated_bull = remove_mitigated(bull_top
, bull_btm
, bull_left
, bull_avg
, target_bull
, true)
mitigated_bear = remove_mitigated(bear_top
, bear_btm
, bear_left
, bear_avg
, target_bear
, false)
//-----------------------------------------------------------------------------}
//Display order blocks
//-----------------------------------------------------------------------------{
//Set bullish order blocks
set_order_blocks(bull_top
, bull_btm
, bull_left
, bull_avg
, bull_ext_last
, bg_bull_css
, bull_css
, bull_avg_css)
//Set bearish order blocks
set_order_blocks(bear_top
, bear_btm
, bear_left
, bear_avg
, bear_ext_last
, bg_bear_css
, bear_css
, bear_avg_css)
//Show detected order blocks
plot(bull_ob, 'Bull OB', bull_css, 2, plot.style_linebr
, offset = -length
, display = display.none)
plot(bear_ob, 'Bear OB', bear_css, 2, plot.style_linebr
, offset = -length
, display = display.none)
//-----------------------------------------------------------------------------}
//Alerts
//-----------------------------------------------------------------------------{
alertcondition(bull_ob, 'Bullish OB Formed', 'Bullish order block detected')
alertcondition(bear_ob, 'Bearish OB Formed', 'bearish order block detected')
alertcondition(mitigated_bull, 'Bullish OB Mitigated', 'Bullish order block mitigated')
alertcondition(mitigated_bear, 'Bearish OB Mitigated', 'bearish order block mitigated')
//-----------------------------------------------------------------------------}
2025-06-20
301
글번호 191947
지표