// Premium Lux Algo Strategy (Converted from Indicator)
// © LuxAlgo, Converted to strategy by user request
//@version=5
strategy("Premium Lux Algo Strategy", overlay=true, precision=0,
max_labels_count=500, default_qty_type=strategy.percent_of_equity,
default_qty_value=10)
// === INPUTS ===
sensitivity = input.float(5.5, "Sensitivity (0.5 - 12)", 0.5, 12, step=0.05, group
= 'Settings')
ShowSmartTrail = input.bool(true, 'Smart Trail ', inline = 'overlayLine1',
group = 'Settings')
maj = input(true, title='TP Points', inline = 'overlayLine1', group = 'Settings')
enableReversal = input.bool(false, 'Reversal Signal ', inline =
'overlayLine2', group = 'Settings')
show_ha = input.bool(false, 'Trend Tracker', inline = 'overlayLine2', group =
'Settings')
enableSR = input(false, 'Support/Resistance ', inline = 'overlayLine3', group
= 'Settings')
usePsar = input.bool(false, 'PSAR', inline = 'overlayLine3', group =
'Settings')
show_rev = input.bool(true, 'Reversal Cloud ', inline = 'overlayLine4', group
= 'Settings')
Show_rangefilter = input.bool(true, 'Range Filter', inline = 'overlayLine4', group
= 'Settings')
Show_SuperIchi = input.bool(true, 'SuperIchi ', inline = 'overlayLine5',
group = 'Settings')
Show_TBO = input.bool(true, 'Show TBO', inline = 'overlayLine5', group =
'Settings')
// Functions
supertrend(_src, factor, atrLen) =>
atrat = ta.atr(atrLen)
upperBand = _src + factor * atrat
lowerBand = _src - factor * atrat
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ?
lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ?
upperBand : prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atrat[1])
direction := 1
else if prevSuperTrend == prevUpperBand
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
superTrend := direction == -1 ? lowerBand : upperBand
[superTrend, direction]
// Get Components
ocAvg = math.avg(open, close)
ema1 = ta.ema(high, 9)
ema2 = ta.ema(high, 12)
ema3 = ta.ema(high, 15)
ema4 = ta.ema(high, 18)
sma1 = ta.sma(close, 5)
sma2 = ta.sma(close, 6)
sma3 = ta.sma(close, 7)
sma4 = ta.sma(close, 8)
sma5 = ta.sma(close, 9)
sma6 = ta.sma(close, 10)
sma7 = ta.sma(close, 11)
sma8 = ta.sma(close, 12)
sma9 = ta.sma(close, 13)
sma10 = ta.sma(close, 14)
sma11 = ta.sma(close, 15)
sma12 = ta.sma(close, 16)
sma13 = ta.sma(close, 17)
sma14 = ta.sma(close, 18)
sma15 = ta.sma(close, 19)
sma16 = ta.sma(close, 20)
psar = ta.sar(0.02, 0.02, 0.2)
[supertrend, direction] = supertrend(close, sensitivity, 11)
barsL = 10
barsR = 10
pivotHigh = fixnan(ta.pivothigh(barsL, barsR)[1])
pivotLow = fixnan(ta.pivotlow(barsL, barsR)[1])
// Colors
green = #04994b, green2 = #15c02a
red = #b4060d, red2 = #ff0002
p5 = plot(ocAvg, "", na, editable=false)
p6 = plot(psar, "PSAR", usePsar ? (psar < ocAvg ? green : red) : na, 1,
plot.style_circles, editable=false)
fill(p5, p6, usePsar ? (psar < ocAvg ? color.new(green, 90) : color.new(red, 90)) :
na, editable=false)
y1 = low - (ta.atr(30) * 2)
y2 = high + (ta.atr(30) * 2)
bull = ta.crossover(close, supertrend) and close >= sma9
bear = ta.crossunder(close, supertrend) and close <= sma9
buy = bull ? label.new(bar_index, y1, "▲", xloc.bar_index, yloc.price, #04994b,
label.style_label_up, color.white, size.normal) : na
sell = bear ? label.new(bar_index, y2, "▼", xloc.bar_index, yloc.price, #b4060d,
label.style_label_down, color.white, size.normal) : na
// Strong TP Points //
maj_qual = 13
maj_len = 40
min_qual = 5
min_len = 5
min = false
selll = 0.0
buyy = 0.0
lele(qual, len) =>
bindex = 0.0
sindex = 0.0
bindex := nz(bindex[1], 0)
sindex := nz(sindex[1], 0)
ret = 0
if close > close[4]
bindex += 1
bindex
if close < close[4]
sindex += 1
sindex
if bindex > qual and close < open and high >= ta.highest(high, len)
bindex := 0
ret := -1
ret
if sindex > qual and close > open and low <= ta.lowest(low, len)
sindex := 0
ret := 1
ret
return_1 = ret
return_1
major = lele(maj_qual, maj_len)
minor = lele(min_qual, min_len)
if minor == -1 and min == true
selll := 1
selll
if major == -1 and maj == true
selll := 2
selll
if major == -1 and maj == true and minor == -1 and min == true
selll := 3
selll
if minor == 1 and min == true
buyy := 1
buyy
if major == 1 and maj == true
buyy := 2
buyy
if major == 1 and maj == true and minor == 1 and min == true
buyy := 3
buyy
plotshape(selll == 2, style=shape.xcross, location=location.abovebar,
color=color.new(#354996, 0), textcolor=color.new(color.white, 0), offset=0)
plotshape(buyy == 2, style=shape.xcross, location=location.belowbar,
color=color.new(#354996, 0), textcolor=color.new(color.white, 0), offset=0)
// Ha Market Bias //
tf(_res, _exp, gaps_on) =>
gaps_on == 0 ? request.security(syminfo.tickerid, _res, _exp) : gaps_on == true
? request.security(syminfo.tickerid, _res, _exp, barmerge.gaps_on,
barmerge.lookahead_off) : request.security(syminfo.tickerid, _res, _exp,
barmerge.gaps_off, barmerge.lookahead_off)
ha_htf = ''
ha_len = 100
ha_len2 = 100
// Calculations {
o = ta.ema(open, ha_len)
c = ta.ema(close, ha_len)
h = ta.ema(high, ha_len)
l = ta.ema(low, ha_len)
haclose = tf(ha_htf, (o + h + l + c) / 4, 0)
xhaopen = tf(ha_htf, (o + c) / 2, 0)
haopen = na(xhaopen[1]) ? (o + c) / 2 : (xhaopen[1] + haclose[1]) / 2
hahigh = math.max(h, math.max(haopen, haclose))
halow = math.min(l, math.min(haopen, haclose))
o2 = tf(ha_htf, ta.ema(haopen, ha_len2), 0)
c2 = tf(ha_htf, ta.ema(haclose, ha_len2), 0)
h2 = tf(ha_htf, ta.ema(hahigh, ha_len2), 0)
l2 = tf(ha_htf, ta.ema(halow, ha_len2), 0)
ha_avg = (h2 + l2) / 2
// }
// Oscillator {
osc_len = 7
osc_bias = 100 *(c2 - o2)
osc_smooth = ta.ema(osc_bias, osc_len)
sigcolor =
(osc_bias > 0) and (osc_bias >= osc_smooth) ? color.new(color.lime, 35) :
(osc_bias > 0) and (osc_bias < osc_smooth) ? color.new(color.lime, 75) :
(osc_bias < 0) and (osc_bias <= osc_smooth) ? color.new(color.red, 35) :
(osc_bias < 0) and (osc_bias > osc_smooth) ? color.new(color.red, 75) :
na
// }
// Plots {
p_h = plot(h2, "Bias High", color=color(na), display=display.none, editable=false)
p_l = plot(l2, "Bias Low", color=color(na), display=display.none, editable=false)
p_avg = plot(ha_avg, "Bias Avergae", color=color(na), display=display.none,
editable=false)
fill(p_l, p_h, show_ha ? sigcolor : na)
col = o2 > c2 ? color.red : color.lime
// }
// Range Filter DW
//---------------------Range
Filter-----------------------------------------------------------------------------
-----------------------------------------
//Conditional Sampling EMA Function
Cond_EMA(x, cond, n) =>
var val = array.new_float(0)
var ema_val = array.new_float(1)
if cond
array.push(val, x)
if array.size(val) > 1
array.remove(val, 0)
if na(array.get(ema_val, 0))
array.fill(ema_val, array.get(val, 0))
array.set(ema_val, 0, (array.get(val, 0) - array.get(ema_val, 0)) * (2 / (n
+ 1)) + array.get(ema_val, 0))
EMA = array.get(ema_val, 0)
EMA
//Conditional Sampling SMA Function
Cond_SMA(x, cond, n) =>
var vals = array.new_float(0)
if cond
array.push(vals, x)
if array.size(vals) > n
array.remove(vals, 0)
SMA = array.avg(vals)
SMA
//Standard Deviation Function
Stdev(x, n) =>
math.sqrt(Cond_SMA(math.pow(x, 2), 1, n) - math.pow(Cond_SMA(x, 1, n), 2))
//Range Size Function
rng_size(x, scale, qty, n) =>
ATR = Cond_EMA(ta.tr(true), 1, n)
AC = Cond_EMA(math.abs(x - x[1]), 1, n)
SD = Stdev(x, n)
rng_size = scale == 'Pips' ? qty * 0.0001 : scale == 'Points' ? qty *
syminfo.pointvalue : scale == '% of Price' ? close * qty / 100 : scale == 'ATR' ?
qty * ATR : scale == 'Average Change' ? qty * AC : scale == 'Standard Deviation' ?
qty * SD : scale == 'Ticks' ? qty * syminfo.mintick : qty
rng_size
//Two Type Range Filter Function
rng_filt(h, l, rng_, n, type, smooth, sn, av_rf, av_n) =>
rng_smooth = Cond_EMA(rng_, 1, sn)
r = smooth ? rng_smooth : rng_
var rfilt = array.new_float(2, (h + l) / 2)
array.set(rfilt, 1, array.get(rfilt, 0))
if type == 'Type 1'
if h - r > array.get(rfilt, 1)
array.set(rfilt, 0, h - r)
if l + r < array.get(rfilt, 1)
array.set(rfilt, 0, l + r)
if type == 'Type 2'
if h >= array.get(rfilt, 1) + r
array.set(rfilt, 0, array.get(rfilt, 1) + math.floor(math.abs(h -
array.get(rfilt, 1)) / r) * r)
if l <= array.get(rfilt, 1) - r
array.set(rfilt, 0, array.get(rfilt, 1) - math.floor(math.abs(l -
array.get(rfilt, 1)) / r) * r)
rng_filt1 = array.get(rfilt, 0)
hi_band1 = rng_filt1 + r
lo_band1 = rng_filt1 - r
rng_filt2 = Cond_EMA(rng_filt1, rng_filt1 != rng_filt1[1], av_n)
hi_band2 = Cond_EMA(hi_band1, rng_filt1 != rng_filt1[1], av_n)
lo_band2 = Cond_EMA(lo_band1, rng_filt1 != rng_filt1[1], av_n)
rng_filt = av_rf ? rng_filt2 : rng_filt1
hi_band = av_rf ? hi_band2 : hi_band1
lo_band = av_rf ? lo_band2 : lo_band1
[hi_band, lo_band, rng_filt]
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Inputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Filter Type
f_type = 'Type 2'
//Movement Source
mov_src = 'Close'
//Range Size Inputs
rng_qty = 2.618
rng_scale = 'Average Change'
//Range Period
rng_per = 14
//Range Smoothing Inputs
smooth_range = true
smooth_per = 27
//Filter Value Averaging Inputs
av_vals = false
av_samples = 2
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Definitions
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//High And Low Values
h_val = mov_src == 'Wicks' ? high : close
l_val = mov_src == 'Wicks' ? low : close
//Range Filter Values
[h_band, l_band, filt] = rng_filt(h_val, l_val, rng_size((h_val + l_val) / 2,
rng_scale, rng_qty, rng_per), rng_per, f_type, smooth_range, smooth_per, av_vals,
av_samples)
//Direction Conditions
var fdir = 0.0
fdir := filt > filt[1] ? 1 : filt < filt[1] ? -1 : fdir
upward = fdir == 1 ? 1 : 0
downward = fdir == -1 ? 1 : 0
//Colors
filt_color = upward ? #36db7f : downward ? #be130f : #cccccc
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Outputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Filter Plot
filt_plot = plot(Show_rangefilter ? filt : na, color=filt_color, linewidth=3,
title='Filter', transp=0)
//Bar Color
//External Trend Output
plot(fdir, editable=false, display=display.none, title='External Output - Trend
Signal', transp=100)
// Superlchi + TBO
tenkan_len = 6
tenkan_mult = 2
kijun_len = 5
kijun_mult = 3.
spanB_len = 26
spanB_mult = 4.
offset = 0
//------------------------------------------------------------------------------
avg(srcc,length,mult)=>
atr = ta.atr(length)*mult
up = hl2 + atr
dn = hl2 - atr
upper = 0.,lower = 0.
upper := srcc[1] < upper[1] ? math.min(up,upper[1]) : up
lower := srcc[1] > lower[1] ? math.max(dn,lower[1]) : dn
os = 0,max = 0.,min = 0.
os := srcc > upper ? 1 : srcc < lower ? 0 : os[1]
spt = os == 1 ? lower : upper
max := ta.cross(srcc,spt) ? math.max(srcc,max[1]) : os == 1 ?
math.max(srcc,max[1]) : spt
min := ta.cross(srcc,spt) ? math.min(srcc,min[1]) : os == 0 ?
math.min(srcc,min[1]) : spt
math.avg(max,min)
//------------------------------------------------------------------------------
tenkan = avg(close,tenkan_len,tenkan_mult)
kijun = avg(close,kijun_len,kijun_mult)
senkouA = math.avg(kijun,tenkan)
senkouB = avg(close,spanB_len,spanB_mult)
//------------------------------------------------------------------------------
tenkan_css = #2157f3
kijun_css = #ff5d00
cloud_a = color.new(color.teal,80)
cloud_b = color.new(color.red,80)
chikou_css = #7b1fa2
plot(Show_SuperIchi ? tenkan : na,'Tenkan-Sen',tenkan_css)
plot(Show_SuperIchi ? kijun : na,'Kijun-Sen',kijun_css)
plot(ta.crossover(tenkan,kijun) ? kijun :
na,'Crossover',#2157f3,3,plot.style_circles)
plot(ta.crossunder(tenkan,kijun) ? kijun :
na,'Crossunder',#ff5d00,3,plot.style_circles)
A = plot(Show_SuperIchi ? senkouA : na,'Senkou Span A',na,offset=offset-1)
B = plot(Show_SuperIchi ? senkouB : na,'Senkou Span B',na,offset=offset-1)
fill(A,B,senkouA > senkouB ? cloud_a : cloud_b)
plot(close,'Chikou',chikou_css,offset=-offset+1,display=display.none)
//------------------------- TBO | https://www.thebettertraders.com -----------//
// Get user input
bool enableCustomTBO = input(false, "Enable?", "Custom trend settings are not
enabled by default. The default settings loaded are not shown publicly. You have
the option to enter your own custom settings as you get more familiar with the
TBO.", group="CUSTOM TREND STRENGTH SETTINGS")
var fastLen = input.int(1, "TBO Fast", 1, group="CUSTOM TREND STRENGTH
SETTINGS")
var mediumLen = input.int(2, "TBO Medium", 2, group="CUSTOM TREND STRENGTH
SETTINGS")
var medfastLen = input.int(3, "TBO Med Fast", 3, group="CUSTOM TREND
STRENGTH SETTINGS")
var slowLen = input.int(4, "TBO Slow", 4, group="CUSTOM TREND STRENGTH
SETTINGS")
bool enableRSI = input(false, "Enable?", "Enable this if you wish to combine
an RSI requirement with the TBO Long or TBO Short signal. The default settings
shown here have no importance, they are just placeholders and are not significant.
It is raccomended to have the RSI showing when this is enabled so you can see what
kind of settings will work.", group="TBO LONG/SHORT W/ RSI")
var shortRsiBand = input.int(70, "Short RSI Band", 1, 100, group="TBO
LONG/SHORT W/ RSI")
var shortBandGL = input.string("Greater Than", "Greater/Less Than", ["Greater
Than", "Less Than"], group="TBO LONG/SHORT W/ RSI")
var longRsiBand = input.int(30, "Long RSI Band", 1, 100, group="TBO
LONG/SHORT W/ RSI")
var longBandGL = input.string("Less Than", "Greater Than", ["Greater Than",
"Less Than"], group="TBO LONG/SHORT W/ RSI")
var rsiLen = input.int(14, "TBO Med Fast", 1, group="TBO LONG/SHORT W/
RSI")
bool enableTP = input(false, "Enable?", group="TAKE PROFIT SETTINGS")
var longTPperc = input.int(9, "TP Long %", 1, group="TAKE PROFIT SETTINGS")
var shortTPperc = input.int(9, "TP Short %", 1, group="TAKE PROFIT SETTINGS")
bool static = input(false, "Static", "If enabled will plot a signal every
time volume gets greater than your defined value.", group="DHP VOLUME SCALPING")
var volThreshold = input.int(20000, "Volume", 1, group="DHP VOLUME SCALPING")
bool maMultiple = input(false, "MA Multiple", "If disabled the script will
only plot when volume is above the average value defined. If you're trading stocks
the static option is recommended.", group="DHP VOLUME SCALPING")
var avgMultiple = input.float(1, "Multiple", 0.1, 10, 0.1, group="DHP VOLUME
SCALPING")
longCondition = bull
shortCondition = bear
if longCondition
strategy.entry("Long", strategy.long)
if shortCondition
strategy.entry("Short", strategy.short)
if bear
strategy.close("Long")
if bull
strategy.close("Short")