Nxalgo
Nxalgo
0 at
https://mozilla.org/MPL/2.0/
// © nagvanshi
//@version=5
// Input parameters
// Auto Fibonacci
Fhigh = ta.highest(AutoPeriod)
Flow = ta.lowest(AutoPeriod)
FH = ta.highestbars(high, AutoPeriod)
FL = ta.lowestbars(low, AutoPeriod)
AutoHighLow = FH < FL
// Plotting
/////////////////////////////////////////////////////////////////////////
// Switch Board
////////////////////////////////////////////////////////////////////////
switchboard_group = "████ Switch Board (Turn On/Off Overlay Indicators) ████"
///////////////////////////////////////////////////////////////////////
// Fibonacci settings
devTooltip = "Deviation is a multiplier that affects how much the price should deviate from the previous
pivot in order for the bar to become a new pivot."
depthTooltip = "The minimum number of bars that will be taken into account when calculating the
indicator."
extending := extend.both
extending := extend.left
extending := extend.right
update() =>
if zigZag.update()
lastP := zigZag.lastPivot()
if not na(lastP)
if switch_fibonacci
if na(lineLast)
else
line.set_first_point(lineLast, lastP.start)
line.set_second_point(lineLast, lastP.end)
id
label.set_xy(id, x, price)
label.set_text(id, labelsAlignStr)
label.set_textcolor(id, txtColor)
_wrap(txt) =>
float m = value
r = startPrice2 + height * m
crossed = _crossing_level(close, r)
if crossed
if not na(lineIdOther)
lineId
else
lineIdOther
//////////////////////////////////////////////////////////////////////////
// Pivots
//////////////////////////////////////////////////////////////////////////
DEFAULT_COLOR = #FB8C00
type graphicSettings
string levelName
color levelColor
bool showLevel
autoAnchor = switch
=> "12M"
=> "12M"
"Biyearly" => 2
"Triyearly" => 3
"Quinquennially" => 5
"Decennially" => 10
=> 1
"Traditional" => 11
"Camarilla" => 11
"Woodie" => 9
"Classic" => 9
"Fibonacci" => 7
"DM" => 3
type pivotGraphic
line pivotLine
label pivotLabel
graphic.pivotLine.delete()
graphic.pivotLabel.delete()
pivotTimeframeChangeCounter(condition) =>
var count = 0
count += 1
count
securityPivotPointsArray = ta.pivot_point_levels(pivotTypeInput,
securityPivotTimeframeChange)
//@function Sets the ending points of the currently active pivots to `endTime`.
affixOldPivots(endTime) =>
if drawnGraphics.rows() > 0
lastGraphics = drawnGraphics.row(drawnGraphics.rows() - 1)
graphic.pivotLine.set_x2(endTime)
if positionLabelsInput == "Right"
graphic.pivotLabel.set_x(endTime)
//@function Draws pivot lines and labels from `startTime` to the approximate end of the period.
drawNewPivots(startTime) =>
newGraphics = array.new<pivotGraphic>()
levelSettings = graphicSettingsArray.get(index)
y = coord,
textcolor = levelSettings.levelColor,
color = #00000000,
xloc=xloc.bar_time)
newGraphics.push(pivotGraphic.new(pivotLine, pivotLabel))
drawnGraphics.add_row(array_id = newGraphics)
oldGraphics = drawnGraphics.remove_row(0)
graphic.delete()
securityPivotDrawConditionDeveloping = false
affixOldPivots(time)
drawNewPivots(time)
// If possible, draw pivots from the beginning of the chart if none were found
if isDailyBasedInput
drawNewPivots(FIRST_BAR_TIME)
else
runtime.error("Not enough intraday data to calculate Pivot Points. Lower the Pivots
Timeframe or turn on the 'Use Daily-based Values' option in the indicator settings.")
else
runtime.error("Not enough data to calculate Pivot Points. Lower the Pivots Timeframe in
the indicator settings.")
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General settings
grp_MAIN = "General"
// Color settings
grp_THEME = "Theme"
smoothrng(x, t, m) =>
wper001 = t * 2 - 1
smoothrng
// Range Filter
rngfilt(x, r) =>
rngfilt
// Filter Direction
// Target Bands
// Colors
isUpColor = src > filt and src > src[1] and upward > 0 ? true :
src > filt and src < src[1] and upward > 0 ? true : false
isDownColor = src < filt and src < src[1] and downward > 0 ? true :
src < filt and src > src[1] and downward > 0 ? true : false
// Fills
// Hull functions
THMA(src, len) => ta.wma(ta.wma(src, len / 3) * 3 - ta.wma(src, len / 2) - ta.wma(src, len), len)
switch modeSwitch
// Hull calculations
MHULL = HULL
SHULL = HULL[2]
// Hull color
// Hull plots
// Hull alerts
// User Inputs
showBuySell = input(true, "Show Buy & Sell", group="BUY & SELL SIGNALS")
wt2 = ta.sma(wt1, 3)
[wt1, wt2]
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]
bearSignal = fractalTop and high[2] > highPrice and src[2] < highPrev
bullSignal = fractalBot and low[2] < lowPrice and src[2] > lowPrev
[bearSignal, bullSignal]
//Components
sourcex = close
bearCond = sourcex < filt and sourcex < sourcex[1] and dn > 0 or sourcex < filt and sourcex >
sourcex[1] and dn > 0
countBull = ta.barssince(bullx)
countBear = ta.barssince(bearx)
plotshape(ta.crossunder(wt1, wt2) and wt2 >= 53, "Mild Sell", shape.xcross, location.abovebar,
color=color.red, size=size.tiny)
// Functions
atrat = ta.atr(atrLen)
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atrat[1])
direction := 1
else
[superTrend, direction]
// Get Components
ema1 = ta.ema(high, 9)
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)
barsL = 10
barsR = 10
// Colors
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
// Strong TP Points //
maj_qual = 13
maj_len = 40
min_qual = 5
min_len = 5
min = false
selll = 0.0
buyy = 0.0
bindex = 0.0
sindex = 0.0
bindex := nz(bindex[1], 0)
sindex := nz(sindex[1], 0)
ret = 0
bindex += 1
bindex
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
selll := 1
selll
selll := 2
selll
selll
buyy := 1
buyy
buyy := 2
buyy
buyy := 3
buyy
// Ha Market Bias //
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)
// }
// Oscillator {
osc_len = 7
sigcolor =
na
// Plots {
array.push(val, x)
if array.size(val) > 1
array.remove(val, 0)
if na(array.get(ema_val, 0))
EMA = array.get(ema_val, 0)
EMA
if cond
array.push(vals, x)
if array.size(vals) > n
array.remove(vals, 0)
SMA = array.avg(vals)
SMA
Stdev(x, 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
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 h >= array.get(rfilt, 1) + r
if l <= array.get(rfilt, 1) - r
rng_filt1 = array.get(rfilt, 0)
hi_band1 = rng_filt1 + r
lo_band1 = rng_filt1 - r
//----------------------------------------------------------------------------------------------------------------------------------------
-------------------------
// Smart Trail
// Wilders ma //
_wild
HRef = norm_l <= norm_h[1] ? norm_h - norm_c[1] : norm_h - norm_c[1] - 0.5 * (norm_l - norm_h[1])
LRef = norm_h >= norm_l[1] ? norm_c[1] - norm_l : norm_c[1] - norm_l - 0.5 * (norm_l[1] - norm_h)
Up = norm_c - loss
Dn = norm_c + loss
TrendUp = Up
TrendDown = Dn
Trend = 1
ex = 0.0
fib1Level = 61.8
fib2Level = 78.6
fib3Level = 88.6
l100 = trail + 0
tradeType = input.string('BOTH', 'What trades should be taken : ', options=['LONG', 'SHORT', 'BOTH',
'NONE'])
//
'60'
//Global elements
var os = 0
var target_bull = 0.
var target_bear = 0.
lime100 = #00FF00FF
red100 = #FF0000FF
blue100 = #0000FFFF
aqua100 = #00FFFFFF
darkred100 = #8B0000FF
gray100 = #808080FF
////////////////////////////////////////////
v7 = 0.0
//<triggers>
lxTrigger = false
sxTrigger = false
//Tooltip
//Webhook Message
tooltip = T_LVL)
tooltip = T_LVL)
tooltip = T_LVL)
i_sxLvlTP1 = i_lxLvlTP1
i_sxLvlTP2 = i_lxLvlTP2
i_sxLvlSL = i_lxLvlSL
i_src = close
G_DISPLAY = 'Display'
//<display>
nz(_tpLine[1])
[_tpLine]
// ——————————— <calculations>
//<SL>
switch
// ——————————— <visuals>
//<alerts labels>
plotshape(
title = 'Long',
text = 'Long',
textcolor = color.white,
color = color.green,
style = shape.labelup,
size = size.tiny,
location = location.belowbar)
plotshape(
title = 'Short',
text = 'Short',
textcolor = color.white,
color = color.red,
style = shape.labeldown,
size = size.tiny,
location = location.abovebar)
plotshape(
title = 'Close',
text = 'Close',
textcolor = color.white,
color = color.gray,
style = shape.labelup,
size = size.tiny,
location = location.absolute)
//<debug>
plot(
na,
editable = false,
display = display.data_window)
plot(
condition,
title = "condition",
editable = false,
display = display.data_window)
array.push(_array, _val)
_return = array.shift(_array)
_return
l_left =4
line.delete(
f_qDq(a_slLine,
line.new(
entryIndex,
slLine,
last_bar_index + l_left,
slLine,
style = line.style_solid,
color = c_sl)))
line.delete(
f_qDq(a_entryLine,
line.new(
entryIndex,
entryLine,
last_bar_index + l_left,
entryLine,
style = line.style_solid,
color = color.blue)))
line.delete(
f_qDq(a_tp2Line,
line.new(
entryIndex,
tp2Line,
last_bar_index + l_left,
tp2Line,
style = line.style_solid,
color = c_tp)))
line.delete(
f_qDq(a_tp1Line,
line.new(
entryIndex,
tp1Line,
last_bar_index + l_left,
tp1Line,
style = line.style_solid,
color = c_tp)))
label.delete(
f_qDq(a_slLabel,
label.new(
last_bar_index + l_left,
slLine,
style = label.style_label_left,
textcolor = color.white,
color = c_sl)))
label.delete(
f_qDq(a_entryLabel,
label.new(
last_bar_index + l_left,
entryLine,
style = label.style_label_left,
textcolor = color.white,
color = color.blue)))
label.delete(
f_qDq(a_tp2label,
label.new(
last_bar_index + l_left,
tp2Line,
style = label.style_label_left,
textcolor = color.white,
color = c_tp)))
label.delete(
f_qDq(a_tp1label,
label.new(
last_bar_index + l_left,
tp1Line,
'TP1: ' + str.tostring(tp1Line, '##.###'),
style = label.style_label_left,
textcolor = color.white,
color = c_tp)))
//<any_alert_function_call>
if longE
if shortE
if longX
if shortX
//////////////////////////////////////////////
LenghtBool1 = input.bool(false,'',group=g_EMAS,inline='len1')
LenghtBool3 = input.bool(false,'',group=g_EMAS,inline='len3')
LenghtBool4 = input.bool(true,'',group=g_EMAS,inline='len4')
switch type
////////////////////////////////////////////
VWAPrice = ta.vwap(VWAPSource)
///////////////////////////////////////////////////
//////////////////////////////////////////////////
POIATR = ta.atr(99)
ColorSupply = input.color(color.rgb(204, 17, 92, 65), title = 'Supply', group = G_POI, inline = 'POI3')
ColorSupplyOutline = input.color(#11010100, title = 'Supply Edges - POI', group = G_POI, inline = 'POI3')
ColorDemand = input.color(color.rgb(0, 138, 153, 65), title = 'Demand', group = G_POI, inline = 'POI4')
ColorDemandOutline = input.color(#1a0101d3, title = 'Demand Edges - POI', group = G_POI, inline =
'POI4')
SwingLength = input.int(4, title = 'High/Low Swing Length', group = G_POI, minval = 1, maxval = 50,
inline= 'POI1')
HistoryDemandKepp = input.int(8, title = 'History to maintain', minval = 5, maxval = 50, group = G_POI,
inline= 'POI1')
BoxWidth = input.float(2, title = 'Supply/Demand Box Width', group = G_POI, minval = 1, maxval = 10,
step = 0.5, inline= 'POI2')
array.unshift(array, new_value_to_add)
array.pop(array)
atr_threshold = POIATR * 2
okay_to_draw = true
for i = 0 to array.size(box_array) - 1
okay_to_draw := false
break
else
okay_to_draw := true
okay_to_draw
box_left = array.get(bn_array, 0)
box_right = bar_index
if box_type == 1
box_top := array.get(value_array, 0)
box_bottom := box_top - atr_buffer
else if box_type == -1
box_bottom := array.get(value_array, 0)
//delete oldest box, and then create a new box and add it to the array
ArrayAddPopF(label_array, box.new( left = box_left, top = poi, right = box_right, bottom = poi,
border_color = color.new(ColorLabelPOI,90),
ArrayAddPopF(label_array, box.new( left = box_left, top = poi, right = box_right, bottom = poi,
border_color = color.new(ColorLabelPOI,90),
for i = 0 to array.size(box_array) - 1
level_to_break = box.get_top(array.get(box_array,i))
copied_box = box.copy(array.get(box_array,i))
ArrayAddPopF(bos_array, copied_box)
box.set_top(array.get(bos_array,0), mid)
box.set_bottom(array.get(bos_array,0), mid)
box.delete(array.get(box_array, i))
box.delete(array.get(label_array, i))
for i = 0 to array.size(box_array) - 1
level_to_break = box.get_bottom(array.get(box_array,i))
copied_box = box.copy(array.get(box_array,i))
ArrayAddPopF(bos_array, copied_box)
box.set_top(array.get(bos_array,0), mid)
box.set_bottom(array.get(bos_array,0), mid)
box.delete(array.get(label_array, i))
BoxExtendEndPointF(box_array) =>
for i = 0 to array.size(box_array) - 1
//
//END CALCULATIONS
//
if not na(SwingHigh)
ArrayAddPopF(SwingHighValHues, SwingHigh)
ArrayAddPopF(SwingHighBNS, bar_index[SwingLength])
ArrayAddPopF(SwingLowValues, SwingLow)
ArrayAddPopF(SwingLowBNS, bar_index[SwingLength])
BoxExtendEndPointF(SupplyBoxCurrent)
BoxExtendEndPointF(DemandBoxCurrent)
rs = ta.rsi(close, Rsi_value)
candle_length = 1
gapp = high - low > gapvalue // or rs<50 // Condition for Min candle size to be eligible for giving signal
- Buy Calls
gapp2 = high - low > gapvalue // or rs>55 // Condition for Min candle size to be eligible for giving signal
- Sell Calls
xbull = open < close and high - low > 2 * gapvalue and close > (high + open) / 2
xbear = open > close and high - low > 2 * gapvalue and close < (low + open) / 2
rev1 = rs > 68 and open > close and high - low > gapvalue + 0.5 and low != close // over red candles "S" -
uptrend
rev1a = rs > 90 and open < close and high != close and open != low // over green candles"S" - uptrend
sellrev = rev1 or rev1a
rev2 = rs < 50 and open < close and open == low // over green candles"B"
rev3 = rs < 30 and open > close and open != high and barstate.isconfirmed != xbear // over red
candles"B"
rev4 = rs < 85 and close == high and high - low > gapvalue and open < close // over green candle in both
trends
//////////////////////////////////////////////////////////////////////////////////////////
showAOE = input.bool(defval = true, title = "Show Area of Interest", group = "Swing Blocks")
highArr.unshift(high), lowArr.unshift(low)
timeArr.unshift(time), volArr.unshift(volume)
closeArr.unshift(close), openArr.unshift(open)
drawAOE() =>
atr = ta.atr(14)
if showAOE
if closeArr.size() > 50
if aoeLevels.size() == 0
aoeLevels.put("High",
border_color = #00000000,
text_size = size.normal,
text_color = color.rgb(14, 0, 3)
))
aoeLevels.put("Low",
border_color = #00000000,
text_size = size.normal,
text_color = color.rgb(0, 7, 4)
))
getHighBox = aoeLevels.get("High")
else
getHighBox.set_text ("")
getLowBox = aoeLevels.get("Low")
else
getLowBox.set_text ("")
drawAOE()
////////////////////////////////////////////////////////////////////////////////////////////
source = close
// MACD Options
// EMA Option
// Calculate EMA
elder_color = elder_bulls
: elder_bears
//////////////////////////////////////////////////////////////////////////////////////////