Quant Algo
Quant Algo
// get rsi
rsiSource = input(title='RSI Source', defval=close)
rsiLength = input(title='RSI Length', defval=14)
rsiMiddle = input(title='RSI Middle', defval=50)
rsiLower = input(title='RSI Middle', defval=65)
// get 50ema
emaLength1 = input(title='EMA 1 Lenght', defval=50)
emaLength2 = input(title='EMA 2 Lenght', defval=120)
emaLength3 = input(title='EMA 3 Lenght', defval=120)
src1 = input(close, title='Source')
ema3 = ta.ema(close, emaLength3)
smma = 0.0
smma := na(smma[1]) ? ema3 : (smma[1] * (emaLength3 - 1) + src1) / emaLength3
if input_ma_type == 'EMA'
result := ta.ema(input_source, input_ma_period)
result
result
ha = ticker.heikinashi(syminfo.tickerid)
get_dpr() =>
buyPressure = 0.
sellPressure = 0.
priceDelta = 0.
priceRange = 0.
dpr = 0.
dominance = 0.
if nzVolume
for i = 0 to length
priceDelta := close[i] - open[i]
priceRange := high[i] - low[i]
if priceDelta > 0
buyPressure += priceDelta / priceRange * nzVolume[i]
if priceDelta < 0
sellPressure += priceDelta / priceRange * nzVolume[i]
if dominance != 0.
dpr := 100 * (buyPressure / dominance)
else
dpr := 50
// -Plot
===================================================================================
===== //
plotshape(not dispSqueeze ? true : na, 'Squeeze On/Off', shape.diamond,
location.bottom, noSqz ? #2DD204 : #5c5c5c)
cond8 = noSqz
cond9 = companion > 50
import loxx/loxxmas/1
alpha = 0.
if (clean == "Advanced")
alpha := 2.0 / (2.0 + (per - 1.0) / 2.0)
else
alpha := 2.0 / (1.0 + per)
_declen()=>
mtckstr = str.tostring(syminfo.mintick)
da = str.split(mtckstr, ".")
temp = array.size(da)
dlen = 0.
if syminfo.mintick < 1
dstr = array.get(da, 1)
dlen := str.length(dstr)
dlen
sig = nz(val[1])
// alerts
alertcondition(Trend == 1 and Trend[1] == -1 and longFilter and Cond1 and (not
ApplyNewFilter or buycond5) and (not ApplyNewFilter2 or cond8) and (not
ApplyNewFilter3 or cond9) and (not ApplyNewFilter4 or cond10), title='Buy Signal',
message='Buy Signal')
alertcondition(Trend == -1 and Trend[1] == 1 and shortFilter and Cond2 and (not
ApplyNewFilter or sellcond6) and (not ApplyNewFilter2 or cond8) and (not
ApplyNewFilter3 or cond9) and (not ApplyNewFilter4 or cond11), title='Sell Signal',
message='Sell Signal')
//
i_showDash = input.bool(true, 'Show dashboard?', group='Dashboard Settings')
lookback = input.int(defval=2, title='Trend Strength', tooltip='Optimal value: [30m
and lower TF - "2"], [45m and higher TF - "4"]. Check User Manual To Learn More')
oneSet = input.timeframe(defval='240', title='First Timeframe', group='Set
Timeframe',
tooltip='Allows you to set different time frames for looking at the trend.')
twoSet = input.timeframe(defval='D', title='Second Timeframe', group='Set
Timeframe')
threeSet = input.timeframe(defval='W', title='Third Timeframe', group='Set
Timeframe')
fourSet = input.timeframe(defval='M', title='Fourth Timeframe', group='Set
Timeframe')
f_getHTF() =>
ph1 = ta.pivothigh(high, lookback, lookback)
pl1 = ta.pivotlow(low, lookback, lookback)
highLevel = ta.valuewhen(ph1, high[lookback], 0)
lowLevel = ta.valuewhen(pl1, low[lookback], 0)
barsSinceHigh = ta.barssince(ph1) + lookback
barsSinceLow = ta.barssince(pl1) + lookback
timeSinceHigh = time[barsSinceHigh]
timeSinceLow = time[barsSinceLow]
[ph1, pl1, highLevel, lowLevel, barsSinceHigh, barsSinceLow, timeSinceHigh,
timeSinceLow]
// Check to ensure boxes are all higher timeframe than the chart to remove glyph
and gray out box if that's the case
tfInMinutes(simple string tf = "") =>
float chartTf =
timeframe.multiplier * (
timeframe.isseconds ? 1. / 60 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
float result = tf == "" ? chartTf : request.security(syminfo.tickerid, tf,
chartTf)
// Define glyphs
glyph1 = TF1Check ? na : inUptrend1 ? '▲ ': '▼ '
glyph2 = TF2Check ? na : inUptrend2 ? '▲ ': '▼ '
glyph3 = TF3Check ? na : inUptrend3 ? '▲ ': '▼ '
glyph4 = TF4Check ? na : inUptrend4 ? '▲ ': '▼ '
// Dashboard Create
var trend_text = ''
var strenght_text = ''
var strenght_color = color.white
var strenght_bg = color.white
var trend_color = color.white
var trend_bg = color.white
var table_position = dashboard_location == 'Top Left' ? position.top_left :
dashboard_location == 'Bottom Left' ? position.bottom_left :
dashboard_location == 'Middle Right' ? position.middle_right :
dashboard_location == 'Bottom Center' ? position.bottom_center :
dashboard_location == 'Top Right' ? position.top_right :
position.bottom_right
//Headings
table.cell(dashboard, 0, 1, 'Quant Algo', width = 5, text_color = color.white,
text_size = table_text_size, bgcolor = color.rgb(0, 0, 0, 24))
table.cell(dashboard, 2, 1, 'Dashboard v4', width = 5, text_color =
color.white, text_size = table_text_size, bgcolor = color.rgb(0, 0, 0, 24))
table.cell(dashboard, 0, 2, 'TF1', width = 5, text_color = color.white,
text_size = table_text_size, bgcolor = color.rgb(0, 0, 0, 24))
table.cell(dashboard, 0, 3, 'TF2', width = 5, text_color = color.white,
text_size = table_text_size, bgcolor = color.rgb(0, 0, 0, 24))
table.cell(dashboard, 0, 4, 'TF3', width = 5, text_color = color.white,
text_size = table_text_size, bgcolor = color.rgb(0, 0, 0, 24))
table.cell(dashboard, 0, 5, 'TF4', width = 5, text_color = color.white,
text_size = table_text_size, bgcolor = color.rgb(0, 0, 0, 24))
table.cell(dashboard, 0, 6, 'Trend', width = 5, text_color = color.white,
text_size = table_text_size, bgcolor = color.rgb(0, 0, 0, 24))
table.cell(dashboard, 0, 7, 'Trend Strength', width = 5, text_color =
color.white, text_size = table_text_size, bgcolor = color.rgb(0, 0, 0, 24))
//Bands
i_showBands = input.bool(true, 'Show Quant Algo Premium/Discount Bands?')
groupQA = " Quant Algo Premium/Discount Bands"
deviationUpSize = array.size(deviationUpList)
deviationDownSize = array.size(deviationDownList)
sizeLimitDev = 1000
array.push(deviationUpList, deviationUp)
array.push(deviationDownList, deviationDown)
medianUpDeviation = array.median(deviationUpList)
medianDownDeviation = array.median(deviationDownList)
pivotUpsSize = array.size(pivotUps)
pivotDownsSize = array.size(pivotDowns)
sizeLimitBand = 2000
medianPivotUp = array.median(pivotUps)
medianPivotDown = array.median(pivotDowns)
extremeUpFill = extremeUpColor
extremeDownFill = extremeDownColor
extremeUpFill1 = extremeUpColor1
extremeDownFill1 = extremeDownColor1
extremeUpFill2 = extremeUpColor2
extremeDownFill2 = extremeDownColor2
greencolor = #2DD204
redcolor = #D2042D