답변완료
지표전환 요청
study("Divergence Histogram for many indicator", overlay=false, max_bars_back = 4000)
lrb = input(5, title="Pivot Point Period", minval = 1)
mindiv = input(1, title="Minimum #Num of Divergence for Alert", minval = 1)
chcut = input(false, title = "Check Cut-Through in indicators")
// RSI
rsi = rsi(close, 14)
// MACD
[macd, signal, deltamacd] = macd(close, 12, 26, 9)
// Momentum
moment = mom(close, 10)
// CCI
cci = cci(close, 10)
// OBV
Obv = obv // cum(change(close) > 0 ? volume : change(close) < 0 ? -volume : 0 * volume)
// Stoch
stk = sma(stoch(close, high, low, 14), 3)
// DIOSC
DI = change(high) - (-change(low))
trur = rma(tr, 14)
diosc = fixnan(100 * rma(DI, 14) / trur)
// volume weighted macd
maFast = vwma(close, 12)
maSlow = vwma(close, 26)
vwmacd = maFast - maSlow
// Chaikin money flow
Cmfm = ((close-low) - (high-close)) / (high - low)
Cmfv = Cmfm * volume
cmf = sma(Cmfv, 21) / sma(volume,21)
// Moneyt Flow Index
Mfi = mfi(close, 14)
float top = na
float bot = na
top := pivothigh(lrb, lrb)
bot := pivotlow(lrb, lrb)
topc = 0, botc = 0
topc := top ? lrb : nz(topc[1]) + 1
botc := bot ? lrb : nz(botc[1]) + 1
// Negative Divergence (checking possible higher highs(lb=0))
newtop = pivothigh(lrb, 0) // check only left side
emptyh = true
if not na(newtop) and newtop > high[topc] // there must not close price higher than the line between last PH and current high
diff = (newtop - high[topc]) / topc
hline = newtop - diff // virtual line to check there is no close price higher than it
for x = 1 to topc -1
if close[x] > hline
emptyh := false
break
hline := hline - diff
else
emptyh := false
// check cut-through in indicators
nocut1(indi, len)=>
_ret = true
diff = (indi - nz(indi[len])) / len
ln = indi - diff
for x = 1 to len -1
if nz(indi[x]) > ln
_ret := false
break
ln := ln - diff
_ret
rsiokn = nocut1(rsi, topc)
macdokn = nocut1(macd, topc)
deltamacdokn = nocut1(deltamacd, topc)
momentokn = nocut1(moment, topc)
cciokn = nocut1(cci, topc)
obvokn = nocut1(obv, topc)
stkokn = nocut1(stk, topc)
dioscokn = nocut1(diosc, topc)
vwmacdokn = nocut1(vwmacd, topc)
cmfokn = nocut1(cmf, topc)
mfiokn = nocut1(Mfi, topc)
negadiv(indi, isok)=>
_ret = (emptyh and not na(newtop) and indi[topc] > indi and (not chcut or isok))
// Positive Divergence (checking possible Lower lows(lb=0))
newbot = pivotlow(lrb, 0) // check only left side
emptyl = true
if not na(newbot) and newbot < low[botc] // there must not close price lower than the line between last PL and current low
diff = (newbot - low[botc]) / botc
lline = newbot - diff // virtual line to check there is no close price lower than it
for x = 1 to botc -1
if close[x] < lline
emptyl := false
break
lline := lline - diff
else
emptyl := false
// check cut-through in indicators
nocut2(indi, len)=>
_ret = true
diff = (indi - nz(indi[len])) / len
ln = indi - diff
for x = 1 to len -1
if nz(indi[x]) < ln
_ret := false
break
ln := ln - diff
_ret
rsiokp = nocut2(rsi, botc)
macdokp = nocut2(macd, botc)
deltamacdokp = nocut2(deltamacd, botc)
momentokp = nocut2(moment, botc)
cciokp = nocut2(cci, botc)
obvokp = nocut2(obv, botc)
stkokp = nocut2(stk, botc)
dioscokp = nocut2(diosc, botc)
vwmacdokp = nocut2(vwmacd, botc)
cmfokp = nocut2(cmf, botc)
mfiokp = nocut2(Mfi, botc)
posidiv(indi, isok)=>
_ret = (emptyl and not na(newbot) and indi[botc] < indi and (not chcut or isok))
indi1 = iff(posidiv(rsi, rsiokp), 1, iff(negadiv(rsi, rsiokn), -1, 0))
indi2 = iff(posidiv(macd, macdokp), 1, iff(negadiv(macd, macdokn), -1, 0))
indi3 = iff(posidiv(deltamacd, deltamacdokp), 1, iff(negadiv(deltamacd, deltamacdokn), -1, 0))
indi4 = iff(posidiv(moment, momentokp), 1, iff(negadiv(moment, momentokn), -1, 0))
indi5 = iff(posidiv(cci, cciokp), 1, iff(negadiv(cci, cciokn), -1, 0))
indi6 = iff(posidiv(Obv, obvokp), 1, iff(negadiv(Obv, obvokn), -1, 0))
indi7 = iff(posidiv(stk, stkokp), 1, iff(negadiv(stk, stkokn), -1, 0))
indi8 = iff(posidiv(diosc, dioscokp), 1, iff(negadiv(diosc, dioscokn), -1, 0))
indi9 = iff(posidiv(vwmacd, vwmacdokp), 1, iff(negadiv(vwmacd, vwmacdokn), -1, 0))
indi10 = iff(posidiv(cmf, cmfokp), 1, iff(negadiv(cmf, cmfokn), -1, 0))
indi11 = iff(posidiv(Mfi, mfiokp), 1, iff(negadiv(Mfi, mfiokn), -1, 0))
totaldiv = indi1 + indi2 + indi3 + indi4 + indi5 + indi6 + indi7 + indi8 + indi9 + indi10 + indi11
hline(0, color = color.gray, linestyle = hline.style_dotted)
plot(abs(totaldiv), color = totaldiv > 0 ? color.new(color.lime, 0) :totaldiv < 0 ? color.new(color.red, 0) : na, style = plot.style_columns, linewidth = 6)
if totaldiv != 0
label.new(x = bar_index, y = abs(totaldiv), text = tostring(abs(totaldiv)), color = color.new(color.white, 100), textcolor = totaldiv < 0 ? color.red : color.lime)
alertcondition(totaldiv >= mindiv, title='Positive Divergence', message='Positive Divergence')
alertcondition(totaldiv <= -mindiv, title='Negative Divergence', message='Negative Divergence')
파인스크립트지표입니다 실력이 부족해서 예스랭귀지로 전환요청 부탁드립니다
-다른 모델에서 타주기참조로 전환이 어렵다 답변받았는데 가능하다면 5분봉에서라도 가능하다면 돌아가게 가능할지요 부탁드려봅니다
2025-05-10
389
글번호 190706
지표
답변완료
문의드립니다.
이전 문의드린 수식중 아래의 수식을 적용했더니 선의 색상이 파란색으로만 나오고
green과 red는 구현되지 않습니다. 또한 선이 직선처럼 나와야 하는데 휩소처럼 나옵니다.
다시한번부탁드립니다.
==========================
study(title="Average True Range Trailing Stops Strategy, by Sylvain Vervoort", overlay = true)
nATRPeriod = input(5)
nATRMultip = input(3.5)
xATR = atr(nATRPeriod)
nLoss = nATRMultip * xATR
xATRTrailingStop = iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss),
iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss),
iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))
pos = iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1,
iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0)))
color = pos == -1 ? red: pos == 1 ? green : blue
plot(xATRTrailingStop, color=color, title="ATR Trailing Stop")
===============================================
작성해주신 수식
input : nATRPeriod(5);
input : nATRMultip(3.5);
var : xATR(0),nLoss(0),xATRTrailingStop(0),ps(0),nz(0),color(0);
xATR = atr(nATRPeriod);
nLoss = nATRMultip * xATR;
nz = iff(xATRTrailingStop[1] == true,0,xATRTrailingStop[1]);
xATRTrailingStop = iff(close > nz and close[1] > nz, max(nz, close - nLoss),
iff(close < nz and close[1] < nz, min(nz, close + nLoss),
iff(close > nz, close - nLoss, close + nLoss)));
ps = iff(close[1] < nz and close > nz, 1,
iff(close[1] > nz and close < nz, -1, iff(isnan(ps[1]) ==true, 0,ps[1]))) ;
color = iff(ps == -1 , red, iff(ps == 1 , green , blue));
plot1(xATRTrailingStop, "ATR Trailing Stop",color);
==================
항상 감사드립니다. 수고하세요!!!
2025-05-09
444
글번호 190682
지표
답변완료
지표 변환 부탁드립니다.
항상 감사합니다.
아래는 트레이딩뷰 스크립트입니다.
시간이 오래 걸리면 이평선 만이라도 차트에 적용할 수 있게 변환 부탁드립니다.
//@version=5
indicator("Market Structure Trend Targets [ChartPrime]", "Market Structure TT [ChartPrime]",
overlay = true, max_lines_count = 500, max_labels_count = 500)
// --------------------------------------------------------------------------------------------------------------------}
// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
// --------------------------------------------------------------------------------------------------------------------{
int length = input.int(10, "Length", maxval = 30, minval = 2)
bool display_per = input.bool(false, "Display %")
bool display_stop = input.bool(true, "Display Trailing Stop")
color col_up = input.color(#54b6d4, "+", inline = "col")
color col_dn = input.color(#cf3737, "-", inline = "col")
// --------------------------------------------------------------------------------------------------------------------}
// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
// --------------------------------------------------------------------------------------------------------------------{
series float ph = ta.pivothigh(length, length)
series float pl = ta.pivotlow(length, length)
market_structure()=>
var upper = float(na)
var lower = float(na)
var upper_count = 0
var lower_count = 0
var upper_index = 0
var lower_index = 0
var trend = bool(na)
float source = ta.sma(high - low, 50)*2
float source1 = ta.sma(ta.median(close, 40), 10)
float volatility = math.avg(ta.highest(source, 200), ta.lowest(source, 200))
float trend_line = float(na)
var line_h = line(na)
var line_l = line(na)
if not na(ph)
upper_index := bar_index[length]
upper := high[length]
line_h := line.new(upper_index, upper, upper_index, upper, color = col_up)
if not na(pl)
lower_index := bar_index[length]
lower := low[length]
line_l := line.new(lower_index, lower, lower_index, lower, color = col_dn)
if ta.crossover(high, upper)
upper_count += 1
var price_enter = 0.
int index = bar_index - (bar_index - upper_index)/2
if upper_count == 1
price_enter := line_h.get_y1()
float percent = (line_h.get_y1() - price_enter) / price_enter * 100
string txt = upper_count == 1
? str.tostring(price_enter, "#.# △")
: (display_per ? str.tostring(percent, format.percent) : str.tostring(upper_count-1))
label.new(index, line_h.get_y1(), txt, textcolor = chart.fg_color, color = color(na))
line_h.set_x2(bar_index)
line_h := na
upper := na
lower_count := 0
trend := true
if ta.crossunder(low, lower)
lower_count += 1
var price_enter = 0.
int index = bar_index - (bar_index - lower_index)/2
if lower_count == 1
price_enter := line_l.get_y1()
float percent = (line_l.get_y1() - price_enter) / price_enter * 100
string txt = lower_count == 1
? str.tostring(price_enter, "#.# ▽")
: (display_per ? str.tostring(percent, format.percent) : str.tostring(lower_count-1))
label.new(index, line_l.get_y1(), txt, textcolor = chart.fg_color, color = color(na), style = label.style_label_up)
line_l.set_x2(bar_index)
line_l := na
lower := na
upper_count := 0
trend := false
if trend
trend_line := source1 - volatility
else
trend_line := source1 + volatility
color color = trend ? col_up : col_dn
if trend and ta.crossover(low, trend_line) and display_stop and not (trend and not trend[1])
label.new(bar_index[1], low[1], text = "◈", style = label.style_label_up, textcolor = color, color = color(na))
if not trend and ta.crossunder(high, trend_line) and display_stop and not (trend[1] and not trend)
label.new(bar_index[1], high[1], text = "◈", style = label.style_label_down, textcolor = color, color = color(na))
if trend and not trend[1]
label.new(bar_index, trend_line, text = "△", textcolor = color, style = label.style_label_center, color = color(na), size = size.large)
if not trend and trend[1]
label.new(bar_index, trend_line, text = "▽", textcolor = color, style = label.style_label_center, color = color(na), size = size.large)
[color, trend_line, trend]
[color, trend_line, trend] = market_structure()
float stop_loss = trend_line,
stop_loss := ta.change(trend)
? na
:
high > stop_loss and not trend
? na
: low < stop_loss and trend
? na
: stop_loss
// --------------------------------------------------------------------------------------------------------------------}
// 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
// --------------------------------------------------------------------------------------------------------------------{
display = display_stop ? display.all : display.none
color1 = display_stop ? 90 : 100
sl = plot(stop_loss, style = plot.style_linebr, color = color, display = display),
plot(stop_loss, style = plot.style_linebr, color = color.new(color, 80), linewidth = 5, display = display)
pp = plot(hl2, color = color(na))
fill(sl, pp, stop_loss, hl2, color.new(color, color1), na)
candle_col = color.new(color, 50)
plotcandle(open, high, low, close, title='Candles Trend', color = candle_col, wickcolor=candle_col, bordercolor = candle_col)
// --------------------------------------------------------------------------------------------------------------------}
2025-05-09
401
글번호 190676
지표