Convert TradingView Indicator to ThinkorSwim

javin82

New member
I need help converting a pine script indicator into a think script study for Thinkorswim. The name of the indicator is called Range. It is a reversal indicator and plots long and short signals. If you can help me with this, please let me know. Thank you!

PineScript code below:
Code:
//////////////
//@version=3
study("Range fv2",overlay=true)
showTrendLine = input(false, title="Show Trend Line")
colorBars = input(true, title="Color Bars?")
filterTrend = input(true, title="Filter Trend?")

//Source
src = close

//Sampling Period
per = input(defval=25, minval=1, title="Sampling Period")

//Range Multiplier
mult = input(defval=2, minval=0, title="Range Multiplier")

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

//Smooth Average Range
smoothrng(x, t, m)=>
    wper      = (t/3) - 1
    avrng     = sma(abs(x - x[1]), t)
    smoothrng = sma(avrng, wper)*m
    smoothrng
smrng = smoothrng(src, per, mult)

//Range Filter
rngfilt(x, r)=>
    rngfilt  = x
    rngfilt := x > nz(rngfilt[1]) ? ((x - r) < nz(rngfilt[1]) ? nz(rngfilt[1]) : (x - r)) : ((x + r) > nz(rngfilt[1]) ? nz(rngfilt[1]) : (x + r))
    rngfilt
filt = rngfilt(src, smrng)

//Filter Direction
upward   = 0.0
upward  := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 : nz(downward[1])

//Target Bands
hband = filt + smrng
lband = filt - smrng

//Colors
filtcolor = upward > 0 ? lime : downward > 0 ? red : orange
barcolor  = (src > filt) and (src > src[1]) and (upward > 0) ? lime : (src > filt) and (src < src[1]) and (upward > 0) ? green : (src < filt) and (src < src[1]) and (downward > 0) ? red : (src < filt) and (src > src[1]) and (downward > 0) ? maroon : orange
barcolor(colorBars ? barcolor : na)

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Plots
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

//Range Filter
if filterTrend == true
    showTrendLine := false
filtplot = plot(filterTrend ? filt : na, color=filtcolor, linewidth=4, title="Range Filter")
//
Factor=input(3, minval=1,maxval = 100)
Pd=input(3, minval=1,maxval = 100)

Up=hl2-(Factor*atr(Pd))
Dn=hl2+(Factor*atr(Pd))
TrendUp = 0.0
TrendDown = 0.0
linecolor = na
up = na
down = na
Tsl = 0.0
Trend = 0.0
TrendUp := close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
TrendDown := close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
Trend := close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)
Tsl := Trend==1? TrendUp: TrendDown
linecolor := Trend == 1 ? green : red
plot(showTrendLine ? Tsl : na, color = linecolor , style = line , linewidth = 3,title = "SuperTrend")

// Strategy


longCond = na
shortCond = na
longCond :=crossunder(Tsl,filt)
shortCond :=crossover(Tsl,filt)

// Count your long short conditions for more control with Pyramiding

sectionLongs = 0
sectionLongs := nz(sectionLongs[1])
sectionShorts = 0
sectionShorts := nz(sectionShorts[1])

if longCond
    sectionLongs := sectionLongs + 1
    sectionShorts := 0

if shortCond
    sectionLongs := 0
    sectionShorts := sectionShorts + 1

// Pyramiding

pyrl = 1


// These check to see your signal and cross references it against the pyramiding settings above

longCondition = longCond and sectionLongs <= pyrl
shortCondition = shortCond and sectionShorts <= pyrl

// Get the price of the last opened long or short

last_open_longCondition = na
last_open_shortCondition = na
last_open_longCondition := longCondition ? open : nz(last_open_longCondition[1])
last_open_shortCondition := shortCondition ? open : nz(last_open_shortCondition[1])

// Check if your last postion was a long or a short

last_longCondition = na
last_shortCondition = na
last_longCondition := longCondition ? time : nz(last_longCondition[1])
last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])

in_longCondition = last_longCondition > last_shortCondition
in_shortCondition = last_shortCondition > last_longCondition

// Take profit

isTPl = input(true, "Take Profit Long")
isTPs = input(true, "Take Profit Short")
tp = input(5, "Take Profit ", type=float)
long_tp = isTPl and crossover(high, (1+(tp/100))*last_open_longCondition) and longCondition == 0 and in_longCondition  == 1
short_tp = isTPs and crossunder(low, (1-(tp/100))*last_open_shortCondition) and shortCondition == 0 and in_shortCondition == 1


// Create a single close for all the different closing conditions.

long_close = long_tp  ? 1 : 0
short_close = short_tp ? 1 : 0

// Get the time of the last close

last_long_close = na
last_short_close = na
last_long_close := long_close ? time : nz(last_long_close[1])
last_short_close := short_close ? time : nz(last_short_close[1])


// Alerts & Signals

bton(b) => b ? 1 : 0
plotshape(longCondition , title="Long", color=green, textcolor=green, transp=0,
          style=shape.triangleup, location=location.belowbar, size=size.small,text="LONG",offset=0)


plotshape(shortCondition, title="Short", color=red, textcolor=red, transp=0,
          style=shape.triangledown, location=location.abovebar, size=size.small,text="SHORT",offset=0)


//plotshape(longCondition, title = "BUY Signal", text = "Buy", style=shape.triangleup, location=location.belowbar, color = blue, editable = false, transp = 0)
//plotshape(shortCondition, title = "SELL Signal", text = "Sell", style=shape.triangledown, location=location.abovebar, color = black, editable = false, transp = 0)

plotshape(long_tp and last_longCondition > nz(last_long_close[1]), text ="TP", title="Take Profit Long", style=shape.triangledown,
   location=location.abovebar, color = red, editable = false, transp = 0)
plotshape(short_tp and last_shortCondition > nz(last_short_close[1]) , text ="TP", title="Take Profit Short", style=shape.triangleup,
   location=location.belowbar, color = lime, editable = false, transp = 0)

alertcondition(bton(longCondition), title="Long Alert")
alertcondition(bton(shortCondition), title="Short Alert")
alertcondition(bton(long_tp and last_longCondition > nz(last_long_close[1])), title="Take Profit Long")
alertcondition(bton(short_tp and last_shortCondition > nz(last_short_close[1])), title="Take Profit Short")

Any help I can get with this will be greatly appreciated! Thank you!

Admin's Notes:

You can now use this thread to make your own request. If there is a TradingView script that you would like to see in ThinkorSwim, please post the source code and link to that script below. We'll try our best to help you with the conversion.

Below are the TradingView scripts that have been converted to TOS.
 
Last edited by a moderator:

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!
 

Volatility Trading Range

VTR is a momentum indicator that shows if a stock is overbought or oversold based on its Weekly and Monthly average volatility trading range.

Download the indicator

Squeeze

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


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.
OhqnFwI.png


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!')
 

ala

New member
Anybody could help me figuring out how to convert a thinkscript to pine script with a [-1] and [1] combined?

Code:
input fastLength = 3;
input slowLength = 17;
input averageType = AverageType.SIMPLE;
plot green = MovingAverage(averageType, close[-1], fastLength) - MovingAverage(averageType, close[1], slowLength) ;
 

nightowl

New member
VIP
ive found a indicator created by chris moody for tradingview that can be used for entry confirmation using his vixfix which i believe is comparable with buy the dip. it is an rsi and ema crossover and used to enter when the rsi crosses above the ema. It looks like great entry signals from backtesting. Here is the code:

Code:
//Created by Chris Moody on 8/8/2014 by Request for motcha1
//RSI Indicator with EMA of RSI for Signal
//Great Confirrming Signal for CM_Williams_Vix_Fix [URL]https://www.tradingview.com/v/og7JPrRA/[/URL]
study(title="CM_RSI_EMA", shorttitle="CM_RSI_EMA_", overlay=false)
src = close, 
len = input(20, minval=1, title="RSI Length")
len2 = input(10, minval=1, title="EMA of RSI Length")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
emaRSI = ema(rsi,len2)

plot(rsi, title="RSI", style=line, linewidth=3, color=silver)
plot(emaRSI, title="EMA of RSI", style=circles, linewidth=2, color=red)
band1 = hline(80, title="Upper Line", linestyle=dashed, linewidth=3, color=red)
band0 = hline(20, title="Lower Line", linestyle=dashed, linewidth=3, color=lime)
fill(band1, band0, color=purple, transp=90)
 

rick888

New member
VIP
Hello, Is there anybody can help to convert the TOS Standard Deviation Channel for Tradingview and Tradestation . Please ,
Here is the code from TOS , thank you so much!!!

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2009-2020
#

input price = close;
input deviations = 2.0;
input fullRange = Yes;
input length = 21;

def regression;
def stdDeviation;
if (fullRange) {
    regression = InertiaAll(price);
    stdDeviation = stdevAll(price);
} else {
    regression = InertiaAll(price, length);
    stdDeviation = stdevAll(price, length);
}

plot UpperLine = regression + deviations * stdDeviation;
plot MiddleLine = regression;
plot LowerLine = regression - deviations * stdDeviation;

UpperLine.SetDefaultColor(GetColor(8));
MiddleLine.SetDefaultColor(GetColor(8));
LowerLine.SetDefaultColor(GetColor(8));
 

gameg2l

New member
So to make converting this indicator ( https://usethinkscript.com/threads/convert-tradingview-indicator.3302/post-39993) more attractive, I am providing some picture examples of this indicate. NOTE it's a leading indicator meaning if you see it, probability is , you're at a lower price stock range comparative to near future (depending on your time frame) 30m is about 1month run. 15 min about two weeks etc.
Honestly, even scalping with 1min can he helpful. Of course , it's all relative to where the stock price is at on the daily chart. As well as subjective to market conditions and outlook, But it's been super accurate on all big stocks I've been watching. Thinking I'd have made money just buy buying in on these makes me so sad... Why did I need to play options... Anyways. Link to the indicator question is : https://usethinkscript.com/threads/convert-tradingview-indicator.3302/post-39993

The higher the histogram the more likely the pump

Here r the examples.:
Ey5BRA7e


Even the tsla pull back
tv15ehih

Prior to the Pump
bHQFRblx


Try it out and help us out.
I just want it on TOS because then I can scan and put alerts on these histograms... And it's a nuance to look at two sites for charts
Thanks for any help!

Edit:update next day's chart on TSLA dip buy signals
PuFpR6zT
 
Last edited:

Ahmar824

Member
Need help with this pine code to convert to TOS

https://www.tradingview.com/x/09LsEGmL/

Complete Ichimoku Trader modified - by @cryptomrdavis

Thank you!

Code below

Code:
//@version=2
//strategy('Complete Ichimoku Trader [I]modified[/I] - original by @kingthies / mod by @cryptomrdavis', shorttitle='Complete Ichimoku Trader [I]modified[/I] - original by @kingthies / mod by @cryptomrdavis', overlay=true)
study('Complete Ichimoku Trader [I]modified[/I] - by @cryptomrdavis -', shorttitle='Complete Ichimoku Trader [I]modified[/I] - @cryptomrdavis -', overlay=true)

sp = input(true, title="Welcome to the modified Version of the Complete Ichimoku Trader - original by @ethies. This version has some extra lines of code and gives you less signals as the original one.")
haopen = security(heikinashi(tickerid), period, open)
hahigh = security(heikinashi(tickerid), period, high)
halow = security(heikinashi(tickerid), period, low)
haclose = security(heikinashi(tickerid), period, close)
heikUpColor() => haclose > haopen
heikDownColor() => haclose <= haopen
o = haopen
c = haclose
src = haclose
price = haclose

rsilength = input(13, title="RSI")
VolSMA = input(20, title="Volume")
uptrendlength = input(2, title="Uptrend Length")
downtrendlength = input(2, title="Downtrend Length")
ShowCloud = input(false, title="Show Ichimoku Cloud?")
ShowIchiLines = input(false, title="Show Ichimoku Lines?")

v1 = volume
v2 = sma(volume,VolSMA)

//RSI//
up1 = rma(max(change(src), 0), 9)
down1 = rma(-min(change(src), 0), 9)
rsi = down1 == 0 ? 100 : up1 == 0 ? 0 : 100 - (100 / (1 + up1 / down1))
K = sma(stoch(c, hahigh, halow, 14), 3)
D = sma(K, 3)

myrsi = rsi(c,rsilength)

//KDJ//
ilong = 9
isig = 3
bcwsma(s,l,m) =>
    _s = s
    _l = l
    _m = m
    _bcwsma = (_m*_s+(_l-_m)*nz(_bcwsma[1]))/_l
    _bcwsma

h = highest(hahigh, ilong)
l = lowest(halow,ilong)
RSV = 100*((c-l)/(h-l))
pK = bcwsma(RSV, isig, 1)
pD = bcwsma(pK, isig, 1)
pJ = 3 * pK-2 * pD
KD = avg(pK,pD)

//EMAs//
EMA5 = ema(price,5)
EMA7 = ema(price,7)
EMA10 = ema(price,10)
EMA14= ema(price,14)
VOLEMA = avg(volume,20)

/// --- TREND --- ///
avghigh = sma(h, uptrendlength)
avglow = sma(l, downtrendlength)
uptrend = h > avghigh
downtrend = l < avglow

//ICHIMOKU BUY & SELL//
conversionPeriods = 9
basePeriods = 26
laggingSpan2Periods = 52
displacement = 26
donchian(len) => avg(lowest(len), highest(len))
resolve(src, default) =>
    if na(src)
        default
    else
        src
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = offset(avg(conversionLine, baseLine), displacement)
leadLine2 = offset(donchian(laggingSpan2Periods), displacement)
tk_cross_bull = crossover(conversionLine, baseLine)
tk_cross_bear = crossunder(conversionLine, baseLine)
cross_y = (conversionLine[1] * (baseLine - baseLine[1]) - baseLine[1] * (conversionLine - conversionLine[1])) / ((baseLine - baseLine[1]) - (conversionLine - conversionLine[1]))
tk_cross_below_kumo = cross_y <= leadLine2[1] and cross_y <= leadLine1[1] and cross_y <= leadLine2 and cross_y <= leadLine1
tk_cross_above_kumo = cross_y >= leadLine2[1] and cross_y >= leadLine1[1] and cross_y >= leadLine2 and cross_y >= leadLine1
tk_cross_inside_kumo = (not tk_cross_below_kumo) and (not tk_cross_above_kumo)
pk_cross_bull = crossover(haclose, baseLine)
pk_cross_bear = crossunder(haclose, baseLine)
cross_pk_y = (haclose[1] * (baseLine - baseLine[1]) - baseLine[1] * (haclose - haclose[1])) / ((baseLine - baseLine[1]) - (haclose - haclose[1]))
pk_cross_below_kumo = cross_pk_y <= leadLine2[1] and cross_pk_y <= leadLine1[1] and cross_pk_y <= leadLine2 and cross_pk_y <= leadLine1
pk_cross_above_kumo = cross_pk_y >= leadLine2[1] and cross_pk_y >= leadLine1[1] and cross_pk_y >= leadLine2 and cross_pk_y >= leadLine1
pk_cross_inside_kumo = (not pk_cross_below_kumo) and (not pk_cross_above_kumo)
kumo_bull = (crossover(haclose, leadLine1) and leadLine1 > leadLine2) or (crossover(haclose, leadLine2) and leadLine2 > leadLine1)
kumo_bear = (crossunder(haclose, leadLine2) and leadLine1 > leadLine2) or (crossunder(haclose, leadLine1) and leadLine2 > leadLine1)
price_below_kumo = (haclose < leadLine2 and haclose < leadLine1)
price_above_kumo = (haclose > leadLine2 and haclose > leadLine1)
price_inside_kumo = (not price_below_kumo) and (not price_above_kumo)
no_dp_leadLine1 = avg(conversionLine, baseLine)
no_dp_leadLine2 = donchian(laggingSpan2Periods)
lead_line_cross_bull = crossover(no_dp_leadLine1, no_dp_leadLine2)
lead_line_cross_bear = crossunder(no_dp_leadLine1, no_dp_leadLine2)
price_below_kumo := (haclose < no_dp_leadLine2 and haclose < no_dp_leadLine1)
price_above_kumo := (haclose > no_dp_leadLine2 and haclose > no_dp_leadLine1)
price_inside_kumo := (not price_below_kumo) and (not price_above_kumo)
past_price = offset(haclose, displacement)
lag_line_bull_cross = haclose > haclose[displacement]
lag_line_bear_cross = haclose < haclose[displacement]
past_price_below_kumo = (past_price < leadLine2 and past_price < leadLine1)
past_price_above_kumo = (past_price > leadLine2 and past_price > leadLine1)
past_price_inside_kumo = (leadLine2 < past_price and past_price < leadLine1) and (leadLine1 < past_price and past_price < leadLine2)

//BUY & SELL
buycond = (tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and rising(pJ[1],1) and heikUpColor() and uptrend and v1 >= v2 and rising(myrsi,1) or
(pk_cross_below_kumo or pk_cross_inside_kumo or pk_cross_above_kumo) and rising(pJ[1],1) and heikUpColor() and uptrend and v1 >= v2 and rising(myrsi,1) or
(past_price_below_kumo or past_price_above_kumo or past_price_inside_kumo) and rising(pJ[1],1) and heikUpColor() and uptrend and v1 >= v2 and rising(myrsi,1)
sellcond = (tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and falling(pJ[1],1) and heikDownColor()and falling(myrsi,1) and downtrend or
(pk_cross_below_kumo or pk_cross_inside_kumo or pk_cross_above_kumo) and falling(pJ[1],1) and heikDownColor() and falling(myrsi,1) and downtrend or
(past_price_below_kumo or past_price_above_kumo or past_price_inside_kumo) and falling(pJ[1],1) and heikDownColor() and falling(myrsi,1) and downtrend

signalfilter = 0
signalfilter := sellcond ? 1 : buycond ? 2 : nz(signalfilter[1])
filvar = signalfilter == 1 ? 1:0
buySignal = (signalfilter != signalfilter[1] and filvar == 0)
sellSignal = (signalfilter != signalfilter[1] and filvar == 1)

//PLOT
plotshape(buySignal, color=green, text= "Buy", location= location.belowbar,style= shape.labelup, textcolor=white, size = size.tiny, title="Buy Alert",editable=false, transp=60)
plotshape(sellSignal, color=red, text= "Sell", location= location.abovebar,style= shape.labeldown, textcolor=white, size = size.tiny, title="Sell Alert", editable=false, transp=60)

SenkouA = donchian(laggingSpan2Periods)
SenkouB = (conversionLine[basePeriods] + baseLine[basePeriods]) / 2
plot(ShowIchiLines and conversionLine ? conversionLine : na, color=red, title="Tenkan")
plot(ShowIchiLines and baseLine ? baseLine : na, color=blue, title="Kijun")
plot(ShowIchiLines and price ? price : na, color= teal , title="Chikou", offset = -displacement)
A = plot(ShowCloud and SenkouA[displacement] ? SenkouA[displacement] : na, color=purple, title="SenkouA")
B = plot(ShowCloud and SenkouB ? SenkouB : na, color=green, title="SenkouB")
fill(A, B, color=green)

//Alert Conditions
alertcondition(buySignal, title='Buy Alert', message='Buy Alert')
alertcondition(sellSignal, title='Sell Alert', message='Sell Alert')
 

coneill17

New member
Can anyone help me transfer this code to tos? Its from tradeview. https://www.tradingview.com/v/K50st6bg/
Code:
//@version=3

study("5 min volume scalper", overlay=true)

src = close
len=input(15)

Length = isintraday and interval >= 1 ? len/interval * 7 : isintraday and interval < 60 ? 60/interval * 24 * 7 : 7

nv = change(src) > 0 ? volume : change(src) < 0 ? -volume : 0*volume
cnv = cum(nv)
cnv_tb = cnv - sma(cnv,Length)

// Conditions

longCond = na
shortCond = na
longCond := crossover(cnv_tb,0)
shortCond :=crossunder(cnv_tb,0)

// Count your long short conditions for more control with Pyramiding

sectionLongs = 0
sectionLongs := nz(sectionLongs[1])
sectionShorts = 0
sectionShorts := nz(sectionShorts[1])

if longCond
    sectionLongs := sectionLongs + 1
    sectionShorts := 0

if shortCond
    sectionLongs := 0
    sectionShorts := sectionShorts + 1
    
// Pyramiding

pyrl = 1


// These check to see your signal and cross references it against the pyramiding settings above

longCondition = longCond and sectionLongs <= pyrl
shortCondition = shortCond and sectionShorts <= pyrl

// Get the price of the last opened long or short

last_open_longCondition = na
last_open_shortCondition = na
last_open_longCondition := longCondition ? open : nz(last_open_longCondition[1])
last_open_shortCondition := shortCondition ? open : nz(last_open_shortCondition[1])

// Check if your last postion was a long or a short

last_longCondition = na
last_shortCondition = na
last_longCondition := longCondition ? time : nz(last_longCondition[1])
last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])

in_longCondition = last_longCondition > last_shortCondition
in_shortCondition = last_shortCondition > last_longCondition

// Take profit

isTPl = input(true, "Take Profit Long")
isTPs = input(true, "Take Profit Short")
tp = input(0.15, "Take Profit ", type=float)
long_tp = isTPl and crossover(high, (1+(tp/100))*last_open_longCondition) and longCondition == 0 and in_longCondition  == 1
short_tp = isTPs and crossunder(low, (1-(tp/100))*last_open_shortCondition) and shortCondition == 0 and in_shortCondition == 1


// Create a single close for all the different closing conditions.

long_close = long_tp  ? 1 : 0
short_close = short_tp ? 1 : 0

// Get the time of the last close

last_long_close = na
last_short_close = na
last_long_close := long_close ? time : nz(last_long_close[1])
last_short_close := short_close ? time : nz(last_short_close[1])


// Alerts & Signals

bton(b) => b ? 1 : 0
plotshape(longCondition, title = "BUY Signal", text = "Buy", style=shape.triangleup, location=location.belowbar, color = blue, editable = false, transp = 0)
plotshape(shortCondition, title = "SELL Signal", text = "Sell", style=shape.triangledown, location=location.abovebar, color = black, editable = false, transp = 0)

plotshape(long_tp and last_longCondition > nz(last_long_close[1]), text ="TP", title="Take Profit Long", style=shape.triangledown,
   location=location.abovebar, color = red, editable = false, transp = 0)
plotshape(short_tp and last_shortCondition > nz(last_short_close[1]) , text ="TP", title="Take Profit Short", style=shape.triangleup,
   location=location.belowbar, color = lime, editable = false, transp = 0)

alertcondition(bton(longCondition), title="Buy Alert")
alertcondition(bton(shortCondition), title="Sell Alert")
alertcondition(bton(long_tp and last_longCondition > nz(last_long_close[1])), title="Take Profit Long")
alertcondition(bton(short_tp and last_shortCondition > nz(last_short_close[1])), title="Take Profit Short")
 

BenTen

Administrative
Staff
VIP
This is a variation of classical MACD that uses volume instead of price.

@BW138 Easy enough. I just changed close to volume

Here you go:

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2020
#

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

plot Value = MovingAverage(averageType, volume, fastLength) - MovingAverage(averageType, volume, slowLength);
plot Avg = MovingAverage(averageType, Value, MACDLength);

plot Diff = Value - Avg;
plot ZeroLine = 0;

plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 

Aziat

New member
VIP
Can anyone help me transfer this code from trading view to tos?

Code:
//@version=4
// This indicator displays the pre-market volume (note: without the post-market of the previous day).
// Unusual pre-market volume often indicates that institutional market makers are moving the market,
// which is a good sign for unusual high price movement.
// The indicator helps me to spot, if a pre-market gap is confirmed with enough (unusual) volume.
//
// You can define, what "unusual" means by you, by adjusting the SMA length and the SMA multiplier.
// The default is a length of 21 bars and a 2.5 multiplier, meaning I'm interested in a stock, if
// the pre-market volume exeeds the average pre-market volume by 2.5 times.
study("Pre-Market Volume Profile")
averageLength = input(title="SMA Length", type=input.integer, defval=21, minval=-1)
averageMultiplier = input(title="SMA Multiplier", type=input.float, defval=2.5, minval=-1, step=.25)

tickerExtended = tickerid(syminfo.prefix, syminfo.ticker, session.extended, adjustment.splits)
tickerRegular = tickerid(syminfo.prefix, syminfo.ticker, session.regular, adjustment.splits)

timeExtended = security(tickerExtended, resolution="1440", expression=time, lookahead=true)
timeRegular = security(tickerRegular, resolution="1440", expression=time, lookahead=true)

volumePreMarket= 0.0
volumePreMarket := nz(volumePreMarket[1])

if timeExtended != timeRegular
    volumePreMarket := na
    
if timeExtended > timeRegular
    volumePreMarket := volume

averagePreMaarketVolume = ema(volumePreMarket * averageMultiplier, averageLength)

plot(volumePreMarket, style=plot.style_histogram, linewidth=4, title="Pre-Market Volume")
plot(averagePreMaarketVolume, color=color.orange, linewidth=2, title="Multiplied Avg.", trackprice=true)
 

FOTM_8888

Member
VIP
Need help with this pine code to convert to TOS

https://www.tradingview.com/x/09LsEGmL/

Complete Ichimoku Trader modified - by @cryptomrdavis

Thank you!

Code below

Code:
//@version=2
//strategy('Complete Ichimoku Trader [I]modified[/I] - original by @kingthies / mod by @cryptomrdavis', shorttitle='Complete Ichimoku Trader [I]modified[/I] - original by @kingthies / mod by @cryptomrdavis', overlay=true)
study('Complete Ichimoku Trader [I]modified[/I] - by @cryptomrdavis -', shorttitle='Complete Ichimoku Trader [I]modified[/I] - @cryptomrdavis -', overlay=true)

sp = input(true, title="Welcome to the modified Version of the Complete Ichimoku Trader - original by @ethies. This version has some extra lines of code and gives you less signals as the original one.")
haopen = security(heikinashi(tickerid), period, open)
hahigh = security(heikinashi(tickerid), period, high)
halow = security(heikinashi(tickerid), period, low)
haclose = security(heikinashi(tickerid), period, close)
heikUpColor() => haclose > haopen
heikDownColor() => haclose <= haopen
o = haopen
c = haclose
src = haclose
price = haclose

rsilength = input(13, title="RSI")
VolSMA = input(20, title="Volume")
uptrendlength = input(2, title="Uptrend Length")
downtrendlength = input(2, title="Downtrend Length")
ShowCloud = input(false, title="Show Ichimoku Cloud?")
ShowIchiLines = input(false, title="Show Ichimoku Lines?")

v1 = volume
v2 = sma(volume,VolSMA)

//RSI//
up1 = rma(max(change(src), 0), 9)
down1 = rma(-min(change(src), 0), 9)
rsi = down1 == 0 ? 100 : up1 == 0 ? 0 : 100 - (100 / (1 + up1 / down1))
K = sma(stoch(c, hahigh, halow, 14), 3)
D = sma(K, 3)

myrsi = rsi(c,rsilength)

//KDJ//
ilong = 9
isig = 3
bcwsma(s,l,m) =>
    _s = s
    _l = l
    _m = m
    _bcwsma = (_m*_s+(_l-_m)*nz(_bcwsma[1]))/_l
    _bcwsma

h = highest(hahigh, ilong)
l = lowest(halow,ilong)
RSV = 100*((c-l)/(h-l))
pK = bcwsma(RSV, isig, 1)
pD = bcwsma(pK, isig, 1)
pJ = 3 * pK-2 * pD
KD = avg(pK,pD)

//EMAs//
EMA5 = ema(price,5)
EMA7 = ema(price,7)
EMA10 = ema(price,10)
EMA14= ema(price,14)
VOLEMA = avg(volume,20)

/// --- TREND --- ///
avghigh = sma(h, uptrendlength)
avglow = sma(l, downtrendlength)
uptrend = h > avghigh
downtrend = l < avglow

//ICHIMOKU BUY & SELL//
conversionPeriods = 9
basePeriods = 26
laggingSpan2Periods = 52
displacement = 26
donchian(len) => avg(lowest(len), highest(len))
resolve(src, default) =>
    if na(src)
        default
    else
        src
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = offset(avg(conversionLine, baseLine), displacement)
leadLine2 = offset(donchian(laggingSpan2Periods), displacement)
tk_cross_bull = crossover(conversionLine, baseLine)
tk_cross_bear = crossunder(conversionLine, baseLine)
cross_y = (conversionLine[1] * (baseLine - baseLine[1]) - baseLine[1] * (conversionLine - conversionLine[1])) / ((baseLine - baseLine[1]) - (conversionLine - conversionLine[1]))
tk_cross_below_kumo = cross_y <= leadLine2[1] and cross_y <= leadLine1[1] and cross_y <= leadLine2 and cross_y <= leadLine1
tk_cross_above_kumo = cross_y >= leadLine2[1] and cross_y >= leadLine1[1] and cross_y >= leadLine2 and cross_y >= leadLine1
tk_cross_inside_kumo = (not tk_cross_below_kumo) and (not tk_cross_above_kumo)
pk_cross_bull = crossover(haclose, baseLine)
pk_cross_bear = crossunder(haclose, baseLine)
cross_pk_y = (haclose[1] * (baseLine - baseLine[1]) - baseLine[1] * (haclose - haclose[1])) / ((baseLine - baseLine[1]) - (haclose - haclose[1]))
pk_cross_below_kumo = cross_pk_y <= leadLine2[1] and cross_pk_y <= leadLine1[1] and cross_pk_y <= leadLine2 and cross_pk_y <= leadLine1
pk_cross_above_kumo = cross_pk_y >= leadLine2[1] and cross_pk_y >= leadLine1[1] and cross_pk_y >= leadLine2 and cross_pk_y >= leadLine1
pk_cross_inside_kumo = (not pk_cross_below_kumo) and (not pk_cross_above_kumo)
kumo_bull = (crossover(haclose, leadLine1) and leadLine1 > leadLine2) or (crossover(haclose, leadLine2) and leadLine2 > leadLine1)
kumo_bear = (crossunder(haclose, leadLine2) and leadLine1 > leadLine2) or (crossunder(haclose, leadLine1) and leadLine2 > leadLine1)
price_below_kumo = (haclose < leadLine2 and haclose < leadLine1)
price_above_kumo = (haclose > leadLine2 and haclose > leadLine1)
price_inside_kumo = (not price_below_kumo) and (not price_above_kumo)
no_dp_leadLine1 = avg(conversionLine, baseLine)
no_dp_leadLine2 = donchian(laggingSpan2Periods)
lead_line_cross_bull = crossover(no_dp_leadLine1, no_dp_leadLine2)
lead_line_cross_bear = crossunder(no_dp_leadLine1, no_dp_leadLine2)
price_below_kumo := (haclose < no_dp_leadLine2 and haclose < no_dp_leadLine1)
price_above_kumo := (haclose > no_dp_leadLine2 and haclose > no_dp_leadLine1)
price_inside_kumo := (not price_below_kumo) and (not price_above_kumo)
past_price = offset(haclose, displacement)
lag_line_bull_cross = haclose > haclose[displacement]
lag_line_bear_cross = haclose < haclose[displacement]
past_price_below_kumo = (past_price < leadLine2 and past_price < leadLine1)
past_price_above_kumo = (past_price > leadLine2 and past_price > leadLine1)
past_price_inside_kumo = (leadLine2 < past_price and past_price < leadLine1) and (leadLine1 < past_price and past_price < leadLine2)

//BUY & SELL
buycond = (tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and rising(pJ[1],1) and heikUpColor() and uptrend and v1 >= v2 and rising(myrsi,1) or
(pk_cross_below_kumo or pk_cross_inside_kumo or pk_cross_above_kumo) and rising(pJ[1],1) and heikUpColor() and uptrend and v1 >= v2 and rising(myrsi,1) or
(past_price_below_kumo or past_price_above_kumo or past_price_inside_kumo) and rising(pJ[1],1) and heikUpColor() and uptrend and v1 >= v2 and rising(myrsi,1)
sellcond = (tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and falling(pJ[1],1) and heikDownColor()and falling(myrsi,1) and downtrend or
(pk_cross_below_kumo or pk_cross_inside_kumo or pk_cross_above_kumo) and falling(pJ[1],1) and heikDownColor() and falling(myrsi,1) and downtrend or
(past_price_below_kumo or past_price_above_kumo or past_price_inside_kumo) and falling(pJ[1],1) and heikDownColor() and falling(myrsi,1) and downtrend

signalfilter = 0
signalfilter := sellcond ? 1 : buycond ? 2 : nz(signalfilter[1])
filvar = signalfilter == 1 ? 1:0
buySignal = (signalfilter != signalfilter[1] and filvar == 0)
sellSignal = (signalfilter != signalfilter[1] and filvar == 1)

//PLOT
plotshape(buySignal, color=green, text= "Buy", location= location.belowbar,style= shape.labelup, textcolor=white, size = size.tiny, title="Buy Alert",editable=false, transp=60)
plotshape(sellSignal, color=red, text= "Sell", location= location.abovebar,style= shape.labeldown, textcolor=white, size = size.tiny, title="Sell Alert", editable=false, transp=60)

SenkouA = donchian(laggingSpan2Periods)
SenkouB = (conversionLine[basePeriods] + baseLine[basePeriods]) / 2
plot(ShowIchiLines and conversionLine ? conversionLine : na, color=red, title="Tenkan")
plot(ShowIchiLines and baseLine ? baseLine : na, color=blue, title="Kijun")
plot(ShowIchiLines and price ? price : na, color= teal , title="Chikou", offset = -displacement)
A = plot(ShowCloud and SenkouA[displacement] ? SenkouA[displacement] : na, color=purple, title="SenkouA")
B = plot(ShowCloud and SenkouB ? SenkouB : na, color=green, title="SenkouB")
fill(A, B, color=green)

//Alert Conditions
alertcondition(buySignal, title='Buy Alert', message='Buy Alert')
alertcondition(sellSignal, title='Sell Alert', message='Sell Alert')
this ichimoku look very good, please can someone help? will be really appreciate
 

BlockWar

New member
Hi I love your work I'm new to trading as well, but there is this indicator from Tradingview that I would love to have ported to TOS.
Is it possible you can help me with this.

https://in.tradingview.com/script/HOx9WOnJ-Automatic-Support-Resistance/


Code:
//@version=3
// study version 0.2

study("Automatic Support & Resistance by getmohsin.py", shorttitle = "Auto S/R by getmohsin.py", overlay=true)

left = input(defval=50, title="Left Bars", type=integer)
right = input(defval=25, title="Right Bars", type=integer)
quick_right = input(defval=5, title="Quick Right", type=integer)
src = input(defval="Close",options = ["Close","High/Low"], title = "Source")


pivot_high = iff(src=="Close",pivothigh(close,left,right),pivothigh(high,left,right))
pivot_lows = iff(src=="Close",pivotlow(close, left,right),pivotlow(low,left,right))

quick_pivot_high = iff(src=="Close",pivothigh(close,left,quick_right),pivothigh(high,left,quick_right))
quick_pivot_lows = iff(src=="Close",pivotlow(close, left,quick_right),pivotlow(low, left,quick_right))

level1 = iff(src=="Close",valuewhen(quick_pivot_high, close[quick_right], 0),valuewhen(quick_pivot_high, high[quick_right], 0))
level2 = iff(src=="Close",valuewhen(quick_pivot_lows, close[quick_right], 0),valuewhen(quick_pivot_lows, low[quick_right], 0))
level3 = iff(src=="Close",valuewhen(pivot_high, close
, 0),valuewhen(pivot_high, high
, 0))
level4 = iff(src=="Close",valuewhen(pivot_lows, close
, 0),valuewhen(pivot_lows, low
, 0))
level5 = iff(src=="Close",valuewhen(pivot_high, close
, 1),valuewhen(pivot_high, high
, 1))
level6 = iff(src=="Close",valuewhen(pivot_lows, close
, 1),valuewhen(pivot_lows, low
, 1))
level7 = iff(src=="Close",valuewhen(pivot_high, close
, 2),valuewhen(pivot_high, high
, 2))
level8 = iff(src=="Close",valuewhen(pivot_lows, close
, 2),valuewhen(pivot_lows, low
, 2))

level1_col = close >= level1 ? green : red
level2_col = close >= level2 ? green : red
level3_col = close >= level3 ? green : red
level4_col = close >= level4 ? green : red
level5_col = close >= level5 ? green : red
level6_col = close >= level6 ? green : red
level7_col = close >= level7 ? green : red
level8_col = close >= level8 ? green : red

plot(level1, style=line, color=level1_col, show_last=1, linewidth=3, trackprice=true)
plot(level2, style=line, color=level2_col, show_last=1, linewidth=3, trackprice=true)
plot(level3, style=line, color=level3_col, show_last=1, linewidth=3, trackprice=true)
plot(level4, style=line, color=level4_col, show_last=1, linewidth=3, trackprice=true)
plot(level5, style=line, color=level5_col, show_last=1, linewidth=3, trackprice=true)
plot(level6, style=line, color=level6_col, show_last=1, linewidth=3, trackprice=true)
plot(level7, style=line, color=level7_col, show_last=1, linewidth=3, trackprice=true)
plot(level8, style=line, color=level8_col, show_last=1, linewidth=3, trackprice=true)
 
Last edited by a moderator:

korygill

Active member
VIP
Hey @BlockWar, welcome to the site. This should really be a new question to keep discussions to the original thread. You might look at existing indicators here that might do the same thing. It is prob possible to port that indicator to TOS, but that might take time for someone to do.
 

BubbaVT21

New member
I wanted to see if anyone can convert the TradingView indicator to TOS. It looks interesting.
Thanks,

Code:
//@version=4
study("(JS) Tip-and-Dip Oscillator 2.0", shorttitle="(JS)TDO2", overlay=false)
//Inputs
lkbk = input(title="Lookback Period", defval=40, minval=1)
smooth = input(defval=2, title="Smoothing Value", maxval=4, minval=1)
range = input(defval=1, title="Color Range", step=0.1)
colsch = input(defval=1, title="Color Scheme", maxval=4, minval=1)
dark = input(defval=true, type=input.bool, title="Using Dark Mode")
//Lowest Close Standard Deviation
wvfL = (lowest(close, lkbk) - high) / lowest(close, lkbk) * -100
sDevL = 3 * stdev(wvfL, lkbk)
midLineL = sma(wvfL, lkbk)
lowerBandL = midLineL - sDevL
upperBandL = midLineL + sDevL
//Highest Close Standard Deviation
wvfH = (highest(close, lkbk) - low) / highest(close, lkbk) * -100
sDevH = 3 * stdev(wvfH, lkbk)
midLineH = sma(wvfH, lkbk)
lowerBandH = midLineH - sDevH
upperBandH = midLineH + sDevH
//High and Low Ranges
rangeHighL = highest(wvfL, lkbk) * 0.95
rangeLowL = lowest(wvfL, lkbk) * 1.2
rangeHighH = highest(wvfH, lkbk) * 0.8
rangeLowH = lowest(wvfH, lkbk) * 1.05
//EMA Smoothing
ema = smooth + 1
newL = ema(wvfL, ema)
newH = ema(wvfH, ema)
new = ema(wvfL - wvfH * -1, ema)
//Final Histogram
histo1 = new + newL
histo2 = new + newH
histo3 = ema(histo1 / 10 + histo2 / 10, ema)
//Histogram Color Conditions
hc1 = histo3 > range ? #4caf50 :
   histo3 > range * -1 ? #ffeb3b : histo3 <= range * -1 ? #f44336 : na
hc2 = histo3 > range ? #2196f3 :
   histo3 > range * -1 ? #9c27b0 : histo3 <= range * -1 ? #e91e63 : na
hc3 = histo3 > range ? #ffeb3b :
   histo3 > range * -1 ? #f44336 : histo3 <= range * -1 ? #ff9800 : na
hc4 = histo3 > range ? color.white :
   histo3 > range * -1 ? color.silver : histo3 <= range * -1 ? color.gray : na
hcol = colsch == 1 ? hc1 : colsch == 2 ? hc2 : colsch == 3 ? hc3 : hc4
//Conditions For Background and Arrows
top1 = histo3 >= 0
top2 = histo3 < histo3[1]
top3 = histo3 > histo3[1]
top4 = histo3[2] > histo3[1]
bot1 = histo3 < 0
bot2 = histo3 > histo3[1]
bot3 = histo3 < histo3[1]
bot4 = histo3[2] < histo3[1]
topc = histo3[1] > histo3[2]
botc = histo3[1] < histo3[2]
//Arrow Conditions
chrt = top1 and top2 and topc
chrb = bot1 and bot2 and botc
chrtb = top1 and top3 and top4
chrbt = bot1 and bot3 and bot4
s1 = smooth == 1
s4 = smooth == 4
ac1 = chrb ? #81c784 : chrtb ? #4caf50 : chrt ? #ef9a9a : #f44336
ac2 = chrb ? #64b5f6 : chrtb ? #2196f3 : chrt ? #f48fb1 : #e91e63
ac3 = chrb ? #fff176 : chrtb ? #ffeb3b : chrt ? #ffb74d : #ff9800
ac4 = color.aqua
arwcol = colsch == 1 ? ac1 : colsch == 2 ? ac2 : colsch == 3 ? ac3 : ac4
//Background Colors and Conditions {Note: adding the gray makes the colors pop more with a dark bg}
bgcolor(colsch == 4 ? na : dark ? color.gray : na, editable=false)
bg1 = top1 and top3 ? #4caf50 :
   top1 and top2 ? #1b5e20 : bot1 and bot3 ? #f44336 : bot1 and bot2 ? #b71c1c : na
bg2 = top1 and top3 ? #2196f3 :
   top1 and top2 ? #0d47a1 : bot1 and bot3 ? #e91e63 : bot1 and bot2 ? #880e4f : na
bg3 = top1 and top3 ? #ffeb3b :
   top1 and top2 ? #fbc02d : bot1 and bot3 ? #ff9800 : bot1 and bot2 ? #e65100 : na
bg4 = top1 and top3 ? color.white : top1 and top2 ? color.silver :
   bot1 and bot3 ? color.gray : bot1 and bot2 ? color.black : na
bcol = colsch == 1 ? bg1 : colsch == 2 ? bg2 : colsch == 3 ? bg3 : bg4
bgcolor(bcol)
//Final Plot
hline(0, title="Zero Line", color=color.white, linestyle=hline.style_dashed, linewidth=1)
plot(histo3, style=plot.style_columns, color=hcol, linewidth=1, transp=50)
//Arrow Plots
plotchar(chrb, title="Downtrend Bottom", char="↑", location=location.bottom, color=arwcol, size=size.tiny, offset=s1 ? -1 : s4 ? -3 : -2)
plotchar(chrtb, title="Uptrend Bottom", char="▲", location=location.bottom, color=arwcol, size=size.tiny, offset=s1 ? -1 : s4 ? -3 : -2)
plotchar(chrt, title="Uptrend Top", char="↓", location=location.top, color=arwcol, size=size.tiny, offset=s1 ? -1 : s4 ? -3 : -2)
plotchar(chrbt, title="Downtrend Top", char="▼", location=location.top, color=arwcol, size=size.tiny, offset=s1 ? -1 : s4 ? -3 : -2)
//Alerts
alertcondition(chrb, "Downtrend Bottom", "A downtrend bottom has been detected!")
alertcondition(chrtb, "Uptrend Bottom", "An uptrend bottom has been detected!")
alertcondition(chrt, "Uptrend Top", "An uptrend top has been detected!")
alertcondition(chrbt, "Downtrend Top", "A downtrend top has been detected!")
 

New Indicator: Buy the Dip

Check out our Buy the Dip indicator and see how it can help you find profitable swing trading ideas. Scanner, watchlist columns, and add-ons are included.

Download the indicator

Similar threads

Top