Swiss Knife
Swiss Knife
//https://t.me/+UAk3hqvoD89jZTlk
indicator("Swiss Knife",overlay = true)
ag = 3
donchian(len) =>
math.avg(ta.lowest(len), ta.highest(len))
// Function to calculate indicators\
sumArray(arr) =>
sum = 0.0
if not(array.size(arr)>0)
sum
else
for i = 0 to array.size(arr) - 1
// Populate the new array with elements from the original array
for i = startt to stopp
array.push(newArray, array.get(arr, i))
find_index(values,weights,start,stop)=>
w_index = WeightedArraySum(sliceArray(values, start, stop),sliceArray(weights,
start, stop))
int(w_index)-1
getLastFractalValues(n) =>
bool upflagDownFrontier = true
bool upflagUpFrontier0 = true
bool upflagUpFrontier1 = true
bool upflagUpFrontier2 = true
bool upflagUpFrontier3 = true
bool upflagUpFrontier4 = true
bool downflagDownFrontier = true
bool downflagUpFrontier0 = true
bool downflagUpFrontier1 = true
bool downflagUpFrontier2 = true
bool downflagUpFrontier3 = true
bool downflagUpFrontier4 = true
// UpFractal conditions
for i = 1 to n
upflagDownFrontier := upflagDownFrontier and (high[n-i] < high[n])
upflagUpFrontier0 := upflagUpFrontier0 and (high[n+i] < high[n])
upflagUpFrontier1 := upflagUpFrontier1 and (high[n+1] <= high[n] and
high[n+i + 1] < high[n])
upflagUpFrontier2 := upflagUpFrontier2 and (high[n+1] <= high[n] and
high[n+2] <= high[n] and high[n+i + 2] < high[n])
upflagUpFrontier3 := upflagUpFrontier3 and (high[n+1] <= high[n] and
high[n+2] <= high[n] and high[n+3] <= high[n] and high[n+i + 3] < high[n])
upflagUpFrontier4 := upflagUpFrontier4 and (high[n+1] <= high[n] and
high[n+2] <= high[n] and high[n+3] <= high[n] and high[n+4] <= high[n] and high[n+i
+ 4] < high[n])
// DownFractal conditions
for i = 1 to n
downflagDownFrontier := downflagDownFrontier and (low[n-i] > low[n])
downflagUpFrontier0 := downflagUpFrontier0 and (low[n+i] > low[n])
downflagUpFrontier1 := downflagUpFrontier1 and (low[n+1] >= low[n] and
low[n+i + 1] > low[n])
downflagUpFrontier2 := downflagUpFrontier2 and (low[n+1] >= low[n] and
low[n+2] >= low[n] and low[n+i + 2] > low[n])
downflagUpFrontier3 := downflagUpFrontier3 and (low[n+1] >= low[n] and
low[n+2] >= low[n] and low[n+3] >= low[n] and low[n+i + 3] > low[n])
downflagUpFrontier4 := downflagUpFrontier4 and (low[n+1] >= low[n] and
low[n+2] >= low[n] and low[n+3] >= low[n] and low[n+4] >= low[n] and low[n+i + 4] >
low[n])
if downFractal
last_down_value := close[n]
if upFractal
last_up_value := close[n]
[last_down_value, last_up_value]//[upFractal,downFractal]//
basisType = "SMMA"
basisLen = 24
offsetSigma = 6
offsetALMA = 0.85
delayOffset = 0
screener_func(h, l, c, o) =>
l1=3
l2=5
l3=7
l4=11
l5=13
l6=17
[upFractal1,downFractal1] = getLastFractalValues(l1)
[upFractal2,downFractal2] = getLastFractalValues(l2)
[upFractal3,downFractal3] = getLastFractalValues(l3)
[upFractal4,downFractal4] = getLastFractalValues(l4)
[upFractal5,downFractal5] = getLastFractalValues(l5)
[upFractal6,downFractal6] = getLastFractalValues(l6)
upval = c*6-
(upFractal1[1]+upFractal2[1]+upFractal3[1]+upFractal4[1]+upFractal5[1]+upFractal6[1
])
downval =
(downFractal1[1]+downFractal2[1]+downFractal3[1]+downFractal4[1]+downFractal5[1]+do
wnFractal6[1])-c*6
mtCond = (upval-downval)>0
percent_upper_wick = upper_wick/spread
percent_lower_wick = lower_wick/spread
percent_body_length = body_length/spread
volume_signal1 = 100*(buying_volume-selling_volume)/volume
cc = 0
fast_length1 = 120
slow_length1 = 260
src1 = volume_signal1
signal_length1 = 90
// Calculating
fast_ma1 =variant('SMMA', src1[delayOffset], fast_length1, offsetSigma,
offsetALMA)
slow_ma1 = variant('SMMA', src1[delayOffset], slow_length1, offsetSigma,
offsetALMA)
macd1 = fast_ma1 - slow_ma1
signal1 = variant('SMMA', macd1[delayOffset], signal_length1, offsetSigma,
offsetALMA)
cumulative_buying_volume = ta.cum(buying_volume)
cumulative_selling_volume = ta.cum(selling_volume)
src =
100*(cumulative_buying_volume-cumulative_selling_volume)/((cumulative_buying_volume
+cumulative_selling_volume)/2)
fast_ma =variant('SMMA', src[delayOffset], 12, offsetSigma, offsetALMA)
slow_ma = variant('SMMA', src[delayOffset], 26, offsetSigma, offsetALMA)
macd = fast_ma - slow_ma
signal = variant('SMMA', macd[delayOffset], 9, offsetSigma, offsetALMA)
inp_num_bins = 250
inp_type = 'Volume'
//
-----------------------------------------------------------------------------
float intrabar_poc = na
//
-----------------------------------------------------------------------------
size = array.size(intrabar_highs)
if size > 0
for i = 0 to inp_num_bins - 1
array.push(tpo_bins, 0)
for j = 0 to num_vals - 1
intrabar_high = array.get(intrabar_highs, j)
intrabar_low = array.get(intrabar_lows, j)
intrabar_volume = inp_type == "Time" ? 1 : array.get(intrabar_vol,
j)
if inside_bin
current = array.get(tpo_bins, i)
array.set(tpo_bins, i, current + (1 * intrabar_volume))
else if spans_bin
current = array.get(tpo_bins, i)
val = (bin_top - bin_bottom) / (intrabar_high - intrabar_low) *
intrabar_volume
array.set(tpo_bins, i, current + val)
else if up_bin
current = array.get(tpo_bins, i)
val = (intrabar_high - bin_bottom) / (intrabar_high -
intrabar_low) * intrabar_volume
array.set(tpo_bins, i, current + val)
else if dn_bin
current = array.get(tpo_bins, i)
val = (bin_top - intrabar_low) / (intrabar_high - intrabar_low)
* intrabar_volume
array.set(tpo_bins, i, current + val)
poc_val = array.max(tpo_bins)
poc_index = array.indexof(tpo_bins, poc_val)
src2 = ta.wma(close,100)-ta.wma(cc,100)
// Additional Indicators
rsi = ta.rsi(c, 14)
rsiC = rsi > 50
source = close
lengthRSI = 14
lengthStoch = 7
smoothK = 3
smoothD = 3
rsi1 = ta.rsi(source, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)
stochC = k>50
conversionPeriods = 9
basePeriods = 26
laggingSpan2Periods = 52
displacement = 26
SmoothedTrueRange = 0.0
SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len)
+ TrueRange
SmoothedDirectionalMovementPlus = 0.0
SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) -
(nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus = 0.0
SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) -
(nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus
// Create table
var tbl = table.new(position.middle_right, 5, 18, frame_color = #151715,
frame_width = 1, border_width = 2, border_color = color.new(color.white, 100))
if barstate.islast
// Daily
table.cell(tbl, 1, 0, "Daily", text_halign = text.align_center, bgcolor =
na,text_color = color.white)
table.cell(tbl, 1, 1, "MACD", text_halign = text.align_center, bgcolor =
macdC_d ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 1, 2, "AO", text_halign = text.align_center, bgcolor = aoC_d ?
color.green : color.red, text_color = color.black, text_size = size.small)
table.cell(tbl, 1, 3, "SAR", text_halign = text.align_center, bgcolor =
sarC_d ? color.green : color.red, text_color = color.black, text_size = size.small)
table.cell(tbl, 1, 4, "SuperTrend", text_halign = text.align_center, bgcolor =
supertrendC_d ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 1, 5, "DPO", text_halign = text.align_center, bgcolor =
dpoC_d ? color.green : color.red, text_color = color.black, text_size = size.small)
table.cell(tbl, 1, 6, "RSI", text_halign = text.align_center, bgcolor =
rsiC_d ? color.green : color.red, text_color = color.black, text_size = size.small)
table.cell(tbl, 1, 7, "Stochastic", text_halign = text.align_center, bgcolor =
stochC_d ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 1, 8, "BB", text_halign = text.align_center, bgcolor = bbC_d ?
color.green : color.red, text_color = color.black, text_size = size.small)
table.cell(tbl, 1, 9, "Ichimoku", text_halign = text.align_center, bgcolor =
ichimokuC_d ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 1, 10, "Chande", text_halign = text.align_center, bgcolor =
cmoC_d ? color.green : color.red, text_color = color.black, text_size = size.small)
table.cell(tbl, 1, 11, "Donchian", text_halign = text.align_center, bgcolor =
donchianC_d ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 1, 12, "ADX", text_halign = text.align_center, bgcolor = adxC_d
? color.green : color.red, text_color = color.black, text_size = size.small)
table.cell(tbl, 1, 13, "VolMom", text_halign = text.align_center, bgcolor =
vmCond_d ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 1, 14, "CumVolMom", text_halign = text.align_center, bgcolor =
cvmCond_d ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 1, 15, "POCMom", text_halign = text.align_center, bgcolor =
pocCond_d ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 1, 16, "Fractals", text_halign = text.align_center, bgcolor =
mtCond_d ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 1, 17, str.tostring(100*(math.round(((dc/17)+1)/2,2)))+'/100',
text_halign = text.align_center, bgcolor = dc>0 ? color.green : color.red,
text_color = color.black, text_size = size.small)
// 1-hour
table.cell(tbl, 3, 0, "1-Hour", text_halign = text.align_center, bgcolor =
na,text_color = color.white)
table.cell(tbl, 3, 1, "MACD", text_halign = text.align_center, bgcolor =
macdC_1h ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 3, 2, "AO", text_halign = text.align_center, bgcolor = aoC_1h ?
color.green : color.red, text_color = color.black, text_size = size.small)
table.cell(tbl, 3, 3, "SAR", text_halign = text.align_center, bgcolor = sarC_1h
? color.green : color.red, text_color = color.black, text_size = size.small)
table.cell(tbl, 3, 4, "SuperTrend", text_halign = text.align_center, bgcolor =
supertrendC_1h ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 3, 5, "DPO", text_halign = text.align_center, bgcolor = dpoC_1h
? color.green : color.red, text_color = color.black, text_size = size.small)
table.cell(tbl, 3, 6, "RSI", text_halign = text.align_center, bgcolor = rsiC_1h
? color.green : color.red, text_color = color.black, text_size = size.small)
table.cell(tbl, 3, 7, "Stochastic", text_halign = text.align_center, bgcolor =
stochC_1h ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 3, 8, "BB", text_halign = text.align_center, bgcolor = bbC_1h ?
color.green : color.red, text_color = color.black, text_size = size.small)
table.cell(tbl, 3, 9, "Ichimoku", text_halign = text.align_center, bgcolor =
ichimokuC_1h ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 3, 10, "Chande", text_halign = text.align_center, bgcolor =
cmoC_1h ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 3, 11, "Donchian", text_halign = text.align_center, bgcolor =
donchianC_1h ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 3, 12, "ADX", text_halign = text.align_center, bgcolor =
adxC_1h ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 3, 13, "VolMom", text_halign = text.align_center, bgcolor =
vmCond_1h ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 3, 14, "CumVolMom", text_halign = text.align_center, bgcolor =
cvmCond_1h ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 3, 15, "POCMom", text_halign = text.align_center, bgcolor =
pocCond_1h ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 3, 16, "Fractals", text_halign = text.align_center, bgcolor =
mtCond_1h ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 3, 17, str.tostring(100*(math.round(((d1h/17)+1)/2,2)))+'/100',
text_halign = text.align_center, bgcolor = d1h>0 ? color.green : color.red,
text_color = color.black, text_size = size.small)
// 15 minutes
table.cell(tbl, 4, 0, "15-Min", text_halign = text.align_center, bgcolor =
na,text_color = color.white)
table.cell(tbl, 4, 1, "MACD", text_halign = text.align_center, bgcolor =
macdC_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 2, "AO", text_halign = text.align_center, bgcolor =
aoC_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 3, "SAR", text_halign = text.align_center, bgcolor =
sarC_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 4, "SuperTrend", text_halign = text.align_center, bgcolor =
supertrendC_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 5, "DPO", text_halign = text.align_center, bgcolor =
dpoC_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 6, "RSI", text_halign = text.align_center, bgcolor =
rsiC_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 7, "Stochastic", text_halign = text.align_center, bgcolor =
stochC_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 8, "BB", text_halign = text.align_center, bgcolor =
bbC_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 9, "Ichimoku", text_halign = text.align_center, bgcolor =
ichimokuC_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 10, "Chande", text_halign = text.align_center, bgcolor =
cmoC_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 11, "Donchian", text_halign = text.align_center, bgcolor =
donchianC_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 12, "ADX", text_halign = text.align_center, bgcolor =
adxC_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 13, "VolMom", text_halign = text.align_center, bgcolor =
vmCond_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 14, "CumVolMom", text_halign = text.align_center, bgcolor =
cvmCond_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 15, "POCMom", text_halign = text.align_center, bgcolor =
pocCond_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 16, "Fractals", text_halign = text.align_center, bgcolor =
mtCond_15m ? color.green : color.red, text_color = color.black, text_size =
size.small)
table.cell(tbl, 4, 17,
str.tostring(100*(math.round(((d15m/17)+1)/2,2)))+'/100', text_halign =
text.align_center, bgcolor = d15m>0 ? color.green : color.red, text_color =
color.black, text_size = size.small)
plot(ta.ema(close,10),color=color.lime,linewidth=1)
plot(ta.ema(close,20),color=color.yellow,linewidth=1)
plot(ta.ema(close,50),color=color.orange,linewidth=1)
plot(ta.ema(close,100),color=color.red,linewidth=1)
plot(ta.ema(close,200),color=color.purple,linewidth=1)
rating = trendSum
rsii = ta.rsi(rating, 21)
rsima = ta.ema(rsii, 14)
isCurrentRangeSmaller() =>
srcHigh = high
srcLow = low
length = 20
rangeRatio = (srcHigh - srcLow) / srcLow
avgRangeRatio = math.sum(rangeRatio, length) / length
rangeRatio < avgRangeRatio
src=close
// Calculate indicators
rsi = ta.rsi(src, 14)
[macdLine, signalLine, _] = ta.macd(src, 12, 26, 9)
stochK = ta.stoch(close, high, low, 14)
obv = ta.obv
mfi = ta.mfi(src, 14)
adLine = ta.accdist
// RSI Divergence
[regBullRsi, hidBullRsi] = divLib.bullish(rsi, low, depth)
[regBearRsi, hidBearRsi] = divLib.bearish(rsi, high, depth)
// MACD Divergence
[regBullMacd, hidBullMacd] = divLib.bullish(macdLine, low, depth)
[regBearMacd, hidBearMacd] = divLib.bearish(macdLine, high, depth)
// Stochastic Divergence
[regBullStoch, hidBullStoch] = divLib.bullish(stochK, low, depth)
[regBearStoch, hidBearStoch] = divLib.bearish(stochK, high, depth)
// OBV Divergence
[regBullObv, hidBullObv] = divLib.bullish(obv, low, depth)
[regBearObv, hidBearObv] = divLib.bearish(obv, high, depth)
// MFI Divergence
[regBullMfi, hidBullMfi] = divLib.bullish(mfi, low, depth)
[regBearMfi, hidBearMfi] = divLib.bearish(mfi, high, depth)
// MACD Signals
plotshape(regBullMacd, title="MACD Regular Bullish", location=location.belowbar,
color=color.green, style=shape.triangleup, size=size.small, text="MACD Div")
plotshape(regBearMacd, title="MACD Regular Bearish", location=location.abovebar,
color=color.red, style=shape.triangledown, size=size.small, text="MACD Div")
// Stochastic Signals
plotshape(regBullStoch, title="Stochastic Regular Bullish",
location=location.belowbar, color=color.green, style=shape.triangleup,
size=size.small, text="Stoch Div")
plotshape(regBearStoch, title="Stochastic Regular Bearish",
location=location.abovebar, color=color.red, style=shape.triangledown,
size=size.small, text="Stoch Div")
// OBV Signals
plotshape(regBullObv, title="OBV Regular Bullish", location=location.belowbar,
color=color.green, style=shape.triangleup, size=size.small, text="OBV Div")
plotshape(regBearObv, title="OBV Regular Bearish", location=location.abovebar,
color=color.red, style=shape.triangledown, size=size.small, text="OBV Div")
// MFI Signals
plotshape(regBullMfi, title="MFI Regular Bullish", location=location.belowbar,
color=color.green, style=shape.triangleup, size=size.small, text="MFI Div")
plotshape(regBearMfi, title="MFI Regular Bearish", location=location.abovebar,
color=color.red, style=shape.triangledown, size=size.small, text="MFI Div")
import HoanGhetti/SimpleTrendlines/5 as tl
input_len = 10
pivotLow = fixnan(ta.pivotlow(input_len, input_len))
plData.lines.trendline.set_style(line.style_dashed)
plData.lines.trendline.set_color(plData.values.slope>0?color.green:color.red)
plData.lines.trendline.set_width(2)
plData.lines.startline.set_width(2)
pivotHigh = fixnan(ta.pivothigh(input_len, input_len))
plData.lines.trendline.set_style(line.style_dashed)
plData.lines.trendline.set_color(plData.values.slope>0?color.green:color.red)
plData.lines.trendline.set_width(2)
plData.lines.startline.set_width(2)
plData1.lines.trendline.set_style(line.style_dashed)
plData1.lines.trendline.set_color(plData1.values.slope>0?color.green:color.red)
plData1.lines.trendline.set_width(2)
plData1.lines.startline.set_width(2)
kama(src,Length)=>
xPrice = src
xvnoise = math.abs(xPrice - xPrice[1])
nAMA = 0.0
nfastend = 0.666
nslowend = 0.0645
nsignal = math.abs(xPrice - xPrice[Length])
nnoise = math.sum(xvnoise, Length)
nefratio = nnoise != 0? nsignal / nnoise: 0
nsmooth = math.pow(nefratio * (nfastend - nslowend) + nslowend, 2)
nAMA := nz(nAMA[1]) + nsmooth * (xPrice - nz(nAMA[1]))
nAMA
src2 = ohlc4
bgcolor(totalDistance>0?color.rgb(0,150,0,50):color.rgb(150,0,0,50))