Convert Tradingview indicator

T

Trigun1127

New member
Hey guys I'm looking for an ATR trailing stop band. We all know how ATR trailing stops work but I basically want a band plotted above for taking profit. Here is an exact video of what I'm looking for.

I would prefer it as well if I can customize length of the ATR along with its multiplier, colors for long short switches, and whether or not I want to use a line or dots or whatever. That all might just be included but I have never programmed before.
 
S

shreyb

New member
Hi,

can anyone help me convert this free RVOL indicator I found on trading view to TOS (thinkScript). The goal is to find the RVOL oof a stock compared to the last 20 days. Ex compare the current vol up till 10 EST to the avg vol up till 10 EST for the last 20 days.

Any help would be appreciated,

Thanks.

Code Below:

Code:
//@version=4
// Created by Matthew J. Slabosz
// www.zenandtheartoftrading.com
study(title="Volume (RVOL By Time of Day)", shorttitle="Volume+")
// Get user input
type = input(title="Market", defval='Stocks', type=input.string, options=['Forex', 'Crypto', 'Futures', 'Stocks', 'TSX Stocks'])
lookback = input(title="Lookback Period", type=input.integer, defval=15)
alertPercent = input(title="Alert At RVOL %", type=input.float, defval=0.0)
barColorOption = input(title="Color Scheme", defval='Price', type=input.string, options=['Heatmap', 'Traffic', 'Trigger', 'Price'])
// Get order/tick volume data
totalVolume = volume - volume
for i = 1 to lookback by 1
    if type == "Forex"
        totalVolume := totalVolume + (timeframe.period == "1" ? 0 :
           timeframe.period == "3" ? 0 : timeframe.period == "5" ? volume[i * 288] :
           timeframe.period == "10" ? volume[i * 144] :
           timeframe.period == "15" ? volume[i * 96] :
           timeframe.period == "30" ? volume[i * 48] :
           timeframe.period == "45" ? volume[i * 32] :
           timeframe.period == "60" ? volume[i * 24] :
           timeframe.period == "120" ? volume[i * 12] :
           timeframe.period == "180" ? volume[i * 8] :
           timeframe.period == "240" ? volume[i * 6] :
           timeframe.period == "D" ? volume[i * 5] :
           timeframe.period == "W" ? volume[i * 4] : 0)
    if type == "Crypto"
        totalVolume := totalVolume + (timeframe.period == "1" ? 0 :
           timeframe.period == "3" ? 0 : timeframe.period == "5" ? volume[i * 288] :
           timeframe.period == "10" ? volume[i * 144] :
           timeframe.period == "15" ? volume[i * 96] :
           timeframe.period == "30" ? volume[i * 48] :
           timeframe.period == "45" ? volume[i * 32] :
           timeframe.period == "60" ? volume[i * 24] :
           timeframe.period == "120" ? volume[i * 12] :
           timeframe.period == "180" ? volume[i * 8] :
           timeframe.period == "240" ? volume[i * 6] :
           timeframe.period == "D" ? volume[i * 7] :
           timeframe.period == "W" ? volume[i * 4] : 0)
    if type == "Stocks"
        totalVolume := totalVolume + (timeframe.period == "1" ? 0 :
           timeframe.period == "3" ? 0 : timeframe.period == "5" ? volume[i * 78] :
           timeframe.period == "10" ? volume[i * 39] :
           timeframe.period == "15" ? volume[i * 26] :
           timeframe.period == "30" ? volume[i * 13] :
           timeframe.period == "45" ? volume[i * 9] :
           timeframe.period == "60" ? volume[i * 7] :
           timeframe.period == "120" ? volume[i * 4] :
           timeframe.period == "180" ? volume[i * 3] :
           timeframe.period == "240" ? volume[i * 2] :
           timeframe.period == "D" ? volume[i * 5] :
           timeframe.period == "W" ? volume[i * 4] : 0)
    if type == "TSX Stocks"
        totalVolume := totalVolume + (timeframe.period == "1" ? 0 :
           timeframe.period == "3" ? 0 : timeframe.period == "5" ? volume[i * 79] :
           timeframe.period == "10" ? volume[i * 40] :
           timeframe.period == "15" ? volume[i * 27] :
           timeframe.period == "30" ? volume[i * 14] :
           timeframe.period == "45" ? volume[i * 9] :
           timeframe.period == "60" ? volume[i * 7] :
           timeframe.period == "120" ? volume[i * 4] :
           timeframe.period == "180" ? volume[i * 3] :
           timeframe.period == "240" ? volume[i * 2] :
           timeframe.period == "D" ? volume[i * 5] :
           timeframe.period == "W" ? volume[i * 4] : 0)
    if type == "Futures"
        totalVolume := totalVolume + (timeframe.period == "1" ? 0 :
           timeframe.period == "3" ? 0 : timeframe.period == "5" ? volume[i * 273] :
           timeframe.period == "15" ? volume[i * 138] :
           timeframe.period == "15" ? volume[i * 92] :
           timeframe.period == "30" ? volume[i * 46] :
           timeframe.period == "45" ? volume[i * 31] :
           timeframe.period == "60" ? volume[i * 23] :
           timeframe.period == "120" ? volume[i * 12] :
           timeframe.period == "180" ? volume[i * 8] :
           timeframe.period == "240" ? volume[i * 6] :
           timeframe.period == "D" ? volume[i * 4] :
           timeframe.period == "W" ? volume[i * 4] : 0)
       
// Calculate average volume for this bar
avgVolume = totalVolume / lookback
// Calculate relative volume percentage for this bar
volumePercent = volume / avgVolume
// Determine if this candle exceeds the average
alert = alertPercent == 0.0 and volume > avgVolume and timeframe.period != "1" and
   timeframe.period != "3" or alertPercent != 0.0 and volumePercent >= alertPercent
  
// Determine volume bar color
barColor = color.gray
// Heatmap Color Scheme
if barColorOption == "Heatmap" and volumePercent >= 0.25
    barColor := #005000
if barColorOption == "Heatmap" and volumePercent >= 0.50
    barColor := #007000
if barColorOption == "Heatmap" and volumePercent >= 0.75
    barColor := #009900
if barColorOption == "Heatmap" and volumePercent >= 1
    barColor := #00dd00
if barColorOption == "Heatmap" and volumePercent >= 2
    barColor := #00ff00
   
// Traffic Light Color Scheme
if barColorOption == "Traffic" and volumePercent >= 1.00
    barColor := #ff1d00
if barColorOption == "Traffic" and volumePercent >= 1.50
    barColor := color.orange
if barColorOption == "Traffic" and volumePercent >= 2.0
    barColor := color.green
if barColorOption == "Traffic" and volumePercent >= 3.0
    barColor := #00ff00
// Trigger Color Scheme
if barColorOption == "Trigger"
    barColor := alert ? color.teal : color.gray
// Colored Scheme
if barColorOption == "Price" and close >= open
    barColor := #5cbcb3
if barColorOption == "Price" and close < open
    barColor := #f37e7c
if alertPercent != 0.0 and volumePercent >= alertPercent
    barColor := color.teal
   
// Draw average volume column
plot(avgVolume, style=plot.style_columns, color=color.gray, title="Average Bars", transp=66)
// Draw current volume column
plot(volume, style=plot.style_columns, color=barColor, title="Volume Bars", transp=0)
// Draw data
plot(avgVolume, style=plot.style_line, color=color.purple, title="Average Line", transp=0)
plot(volumePercent, style=plot.style_line, color=color.blue, title="Percentage", transp=100)
// Send out an alert if this candle meets our conditions
alertcondition(alert, title="Volume Alert!", message="Volume signal for {{ticker}}")
 
A

alokranjan3

New member
I am looking for LBR RSI indicator (three-period RSI of this one period change), but so far no luck. Here is the description from LBR and Connor's "Street Smart" book.

This Pattern uses a one-period rate of change or "momentum" function. This is simply, the difference between today's close and yesterday's close. (i.e., if today;,, closing price was 592 and yesterday's closing price was 596, the difference is -4.)
A three-period RSI of this one period change is calculated. (Most software charting packages allow the user to do studies on studies in just this way.)

Thank you in advance!

Code:
I found TradingView Code:
//@version=3
////////////////////////////////////////////////////////////////////////////////////////////////
//// Momentum Pinball, when you get a buy/sell signal, wait for the next day
//// enter on the high or low of the first hour and place a stop in the low/high
//// of the first hour. If the day you get filled closes profitable you can decide to close
//// the trade buy the end of the day or hold overnight and exit the following morning
////////////////////////////////////////////////////////////////////////////////////////////
study("Momentum Pinball")

rocPeriod = input(title="ROC Period", type=integer, defval=1)
rsiPeriod = input (title="RSI Period", type=integer, defval=3)
oversoldLevel = 30
overboughtLevel = 70

lbrrsi = rsi(roc(close, rocPeriod), rsiPeriod)

buySetup = lbrrsi < oversoldLevel
sellSetup = lbrrsi > overboughtLevel

plotshape(buySetup, color=green, style=shape.triangleup, location=location.bottom)
plotshape(sellSetup, color=red, style=shape.triangledown, location=location.top)
hline(overboughtLevel, title='Overbought', color=#5E606B, linestyle=dashed, linewidth=2)
hline(oversoldLevel, title='Oversold', color=#5E606B, linestyle=dashed, linewidth=2)
plot(lbrrsi, color=#5E606B)
 
Last edited:
H

hanimusa

New member
@BenTen Hi BenTen
can you please help me for coding this indicator to thinkorswim

Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at [URL]https://mozilla.org/MPL/2.0/[/URL]
// © blackcat1402
//@version=4

study("[blackcat] L2 KDJ Trading System", overlay=false)

//functions
xrf(values, length) =>
    r_val = float(na)
    if length >= 1
        for i = 0 to length by 1
            if na(r_val) or not na(values[i])
                r_val  :=  values[i]
                r_val
    r_val
xsa(src,len,wei) =>
    sumf = 0.0
    ma = 0.0
    out = 0.0
    sumf  :=  nz(sumf[1]) - nz(src[len]) + src
    ma  :=  na(src[len]) ? na : sumf/len
    out  :=  na(out[1]) ? ma : (src*wei+out[1]*(len-wei))/len
    out

xfl(cond, lbk) =>
    out = 0.0
    itemp = 0
    for i = lbk to 0 by 1
        if itemp > 0
            out := 0.0
            itemp := itemp[1] - 1
            itemp
        else
            if cond[i] == false
                out := 0.0
                out
            else
                out := 1.0
                itemp := lbk + 1
                itemp
    out

// inputs
n1 = input(9, title="n1", type=input.integer, minval = 1)
n2 = input(3, title="n2", type=input.integer, minval = 1)
n3 = input(3, title="n3", type=input.integer, minval = 1)

rsv = (((close - lowest(low,n1)) / (highest(high,n1) - lowest(low,n1))) * 100)
k = xsa(rsv,n2,1)
d = xsa(k,n3,1)
j = 3*k-2*d

//plot KD candles
plotcandle(k, d, k, d, color=k>=d?color.yellow:na)
plotcandle(k, d, k, d, color=d>k?color.fuchsia:na)

//short entry
shortentry = iff(xfl(k[1]>d[1] and k<=d and j>50,4), 75, 100)
pse0 = plot(shortentry,color=color.red, linewidth=2,style=plot.style_line, transp=0)

//threshold lines
h1 = hline(80,color=color.red, linestyle=hline.style_dotted)
h2 = hline(20, color=color.yellow, linestyle=hline.style_dotted)
h3 = hline(10,color=color.lime, linestyle=hline.style_dotted)
h4 = hline(90, color=color.fuchsia, linestyle=hline.style_dotted)
fill(h2,h3,color=color.yellow,transp=70)
fill(h1,h4,color=color.fuchsia,transp=70)

//long entry definitions
x = lowest(j,2)==lowest(j,8)
re = iff(crossover(j,xrf(j+0.01,1)) and x and j<19,25,0)
ple0 = plot(re,color=color.yellow, linewidth=1,style=plot.style_area, transp=0)

//define confirmed long entry signal syn
css = ((close-lowest(low,8))/(highest(high,8)-lowest(low,8))*100)
hh = crossunder(ema(css,3),20)
ce = hh[1]
aa = xrf(close,1)
bbb = xsa(max(close-aa,0),5,1)/xsa(abs(close-aa),5,1)*1000
hhh = bbb-lowest(bbb,10)
ss = (sma(hhh,2)*3+hhh*13)/16
longentry1 = iff(ss>13,sma(ss,2),ss)/6
longentry2 = iff(crossover(longentry1,1) and (longentry1<30),30,1)
ii = longentry2==30
syn = iff(ce and ii, 25, 0)
ple1 = plot(syn,color=color.green, linewidth=1,style=plot.style_area, transp=0)[/i][/i][/i]
 
G

gameg2l

New member
you got Blackcat's script, too :D
I tried this one, but prefer the one I got on #99 post
Really helpful for dip buy, accuracy is uncanny on large caps.
I only was able to find resources for coding the KDJ, unable to figure out how the histogram was rendered.. :/
 
H

hanimusa

New member
I think @BenTen Is the best best person can helping for doing this indicator as thinkorswim script
 
G

gameg2l

New member
I got the KDJ code from @wtf_dude & @diazlaz - it's working but I can't figure out how to use the relations between these lines to render the Histogram, which is critical for determining how low the relative low is.
Hopefully they see this :D please give us a hand!
 
H

hanimusa

New member
I got the KDJ code from @wtf_dude & @diazlaz - it's working but I can't figure out how to use the relations between these lines to render the Histogram, which is critical for determining how low the relative low is.
Hopefully they see this :D please give us a hand!
Can you post what you have here so the expert members solve the issue
 
S

Squeeze

New member
Hello useThinkScript Community !! Could anyone convert this script into pinescript -> thinkscript? The indicator looks like this on a chart below..


What it is suppose to do -
What Does Knoxville Divergence Mean?


The appearance of Knoxville Divergence (or KD, for short) is the suggestion - not a guarantee - that price is set to reverse course. It is a counter-trend indicator.


This means that if price has been moving upward on the 240 minute chart above, and we see a KD line above price, it is a suggestion that price is possibly going to move lower in the near future. Because of this, it is a useful indicator for counter-trend traders, or trend-traders who want to look for a pullback before they enter a trade with the longer-term trend.


How is Knoxville Divergence Built?


Knoxville Divergence is comprised of two elements:


  1. Momentum indicator. The momentum indicator - when price is rising, but the momentum indicator is falling, this is a first sign that we could see Knoxville Divergence appear on the chart. But it's not enough by itself.

  2. Relative Strength Index. If, at the same time we see the disagreement between price and the momentum indicator, we also see the relative strength index go overbought or oversold, then we have the second necessary element for KD and a KD line will appear on the chart.


Point #1: Price is fallling.


Point #2: The Momentum Indicator is rising. This means that even though price is dropping, the rate at which it is doing so has decreased. In other words, enthusiasm for selling the EUR/USD is dissipating.


Point #3: During this same time, the Relative Strength Index has dipped into oversold territory. This adds one more element of confirmation to the idea that price is set for a move upward

Code:
//@version=3
study("Knoxville Divergence", overlay=true)
//-------------------------
// Knoxville Divergence with Reversal Tabs
//-------------------------
KnoxRSILength      = input(title="Knoxville RSI",            defval=17, type=integer)
KnoxMOMLength      = input(title="Knoxville Mom",            defval=20, type=integer)
KnoxDivergence     = input(true, title="Knoxville Divergences")
KnoxLabel          = input(true, title="Knoxville Divergence Labels")
KnoxTriangle       = input(true, title="Knoxville Divergence Triangles")

ReversalTabs       = input(true,  title="Reversal Tabs")
macd_fast_period   = input(title="Reversal Tabs - MACD Fast Period",            defval=12, type=integer)
macd_slow_period   = input(title="Reversal Tabs - MACD Slow Period",            defval=26, type=integer)
macd_signal_period = input(title="Reversal Tabs - MACD Signal Period",          defval=9, type=integer)

stoch_period       = input(title="Reversal Tabs - Stochastic RSI Period",       defval=70, type=integer)
prc_k_period       = input(title="Reversal Tabs - %K Period", defval=30, type=integer)
prc_d_period       = input(title="Reversal Tabs - %D Period", defval=30, type=integer)
stoch_ob           = input(title="Reversal Tabs - Stochastic Overbought Level", defval=70, type=integer)
stoch_os           = input(title="Reversal Tabs - Stochastic Oversold Level",   defval=30, type=integer)


KnoxRSI = rsi(close,KnoxRSILength)
KnoxMOM = mom(close,KnoxMOMLength)

KnoxRSIOB = KnoxRSI > 70 ? 1 : 0

KnoxRSIOS = KnoxRSI < 30 ? 1 : 0
//------------------------------
//@RicardoSantos' Divergence Script

f_top_fractal(_src)=>_src[4] < _src[2] and _src[3] < _src[2] and _src[2] > _src[1] and _src[2] > _src[0]
f_bot_fractal(_src)=>_src[4] > _src[2] and _src[3] > _src[2] and _src[2] < _src[1] and _src[2] < _src[0]
f_fractalize(_src)=>f_top_fractal(_src) ? 1 : f_bot_fractal(_src) ? -1 : 0

fractal_top_knox = f_fractalize(KnoxMOM) > 0 ? KnoxMOM[2] : na
fractal_bot_knox = f_fractalize(KnoxMOM) < 0 ? KnoxMOM[2] : na

high_prev_knox  = valuewhen(fractal_top_knox, KnoxMOM[2], 0)[2]
high_price_knox = valuewhen(fractal_top_knox, high[2], 0)[2]
low_prev_knox   = valuewhen(fractal_bot_knox, KnoxMOM[2], 0)[2]
low_price_knox  = valuewhen(fractal_bot_knox, low[2], 0)[2]


knoxville_bearish_div = fractal_top_knox and KnoxRSIOB and high[2] > high_price_knox and KnoxMOM[2] < high_prev_knox
knoxville_bullish_div = fractal_bot_knox and KnoxRSIOS and low[2]  < low_price_knox  and KnoxMOM[2] > low_prev_knox


//-------------------------

KnoxColor = knoxville_bearish_div ? #FA0000FA  : knoxville_bullish_div ? #00FF00FA: na

plot(title='Knoxville - Bearish Divergence Lines', series = KnoxDivergence and fractal_top_knox ? high[2] : na, color=KnoxColor, linewidth=5, offset=-2)
plot(title='Knoxville - Bullish Divergence Lines', series = KnoxDivergence and fractal_bot_knox ? low[2]  : na, color=KnoxColor, linewidth=5, offset=-2)

// Labels
plotshape(title='Knoxville - Label - Bearish Divergence - Label', series = KnoxLabel and knoxville_bearish_div ? close[2] : na, text='Knox',   style=shape.labeldown, location=location.abovebar, color=#FF000010, textcolor=#008000FA, offset=-2)
plotshape(title='Knoxville - Label - Bullish Divergence - Label', series = KnoxLabel and knoxville_bullish_div ? close[2] : na, text='Knox',   style=shape.labelup,   location=location.belowbar, color=#00800010, textcolor=#008000FA, offset=-2)

// Triangles
plotshape(title='Knoxville - Triangle - Bearish Divergence - Triangles', series = KnoxTriangle and knoxville_bearish_div ? close[2] : na, text='', style=shape.triangledown, location=location.abovebar, color=#008000FA,  textcolor=#000000FA,   offset=-2)
plotshape(title='Knoxville - Triangle - Bullish Divergence - Triangles', series = KnoxTriangle and knoxville_bullish_div ? close[2] : na, text='', style=shape.triangleup,   location=location.belowbar, color=#008000FA,  textcolor=#000000FA,   offset=-2)

alertcondition(knoxville_bearish_div, title='Alert - Knoxville Bearish Divergence', message='Alert - Knoxville Bearish Divergence!')
alertcondition(knoxville_bullish_div, title='Alert - Knoxville Bullish Divergence', message='Alert - Knoxville Bearish Divergence!')


// Bob Rooker Reversal Tabs Script


[macd_line, signal_line, hist_line] = macd(close, macd_fast_period, macd_slow_period, macd_signal_period)

fast_prc_k         = 100*(close - lowest(low, stoch_period))/(highest(high, stoch_period) - lowest(low, stoch_period))
fast_prc_d         = sma(fast_prc_k, prc_d_period)

slow_prc_k         = sma(fast_prc_k, prc_k_period)
slow_prc_d         = sma(slow_prc_k, prc_d_period)

full_prc_k         = sma(fast_prc_k, prc_k_period)
full_prc_d         = sma(full_prc_k, prc_d_period)

is_buy_reversal    = crossover(macd_line,  0)  and full_prc_k < stoch_os
is_sell_reversal   = crossunder(macd_line, 0)  and full_prc_k > stoch_ob

plotshape(title = 'Reversal Tab', series = ReversalTabs? is_buy_reversal:  na, style=shape.triangleup,   color=green, size=size.small, location=location.belowbar)
plotshape(title = 'Reversal Tab', series = ReversalTabs? is_sell_reversal: na, style=shape.triangledown, color=red,   size=size.small, location=location.abovebar)

alertcondition(is_buy_reversal,  title='Alert - Buy Reversal Tab',  message='Reversal Tab BUY ALERT!')
alertcondition(is_sell_reversal, title='Alert - Sell Reversal Tab', message='Reversal Tab SELL ALERT!')

alertcondition(is_sell_reversal or is_buy_reversal, title='Alert - Buy or Sell Reversal Tab', message='Reversal Tab BUY OR SELL ALERT!')
 

Similar threads

Top