0% found this document useful (0 votes)
251 views24 pages

Ote

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
251 views24 pages

Ote

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 24

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.

0
at https://mozilla.org/MPL/2.0/
// © polatelektrikhakan

/// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © Crypto_Wolf_Traders

//@version=5
strategy("TT-Scalper-Veins-OTE", overlay=true, max_labels_count=500,
default_qty_type = strategy.percent_of_equity, default_qty_value = 25,
initial_capital = 500)
///////////////////////////////////////////////////////////////////////////////
//-----------------------------CRYPTO-WOLF-TRADERS---------------------------//
///////////////////////////////////////////////////////////////////////////////
// SIGNAL MEANINGS//
//"Buy Label" = Strong Buy//
//"Sell Label" = Strong Sell//
//"Don't Long" = Green Cross//
//"Don't Short" = Red Cross//
//"Weak Buy " = Green Circle//
//"Weak Sell" = Red Circle//
//"Reversal Buy" = Green Diamond//
//"Reversal Sell" = Red Diamond//

// Get user settings


res = input.timeframe(title='TIMEFRAME', defval='', group ="NON
REPAINT HA")
showBuySell = input(true, "BUY/SELL SIGNALS ON/OFF", group="BUY & SELL
SIGNALS")
sensitivity = input.float(3.0, "SENSITIVITY (1-6)", 0.1, 10, group="BUY &
SELL SIGNALS")
percentStop = input.float(1.0, "STOP LOSS %", 0, group="BUY & SELL SIGNALS")
percentTake = input.float(0.28, "TAKE PROFIT %", 0, group="BUY & SELL
SIGNALS")
percentTake2 = input.float(0.56, "TAKE PROFIT2 %", 0, group="BUY & SELL
SIGNALS")
percentTake3 = input.float(0.84, "TAKE PROFIT3 %", 0, group="BUY & SELL
SIGNALS")
percentTake4 = input.float(1.12, "TAKE PROFIT4 %", 0, group="BUY & SELL
SIGNALS")
percentTake5 = input.float(1.40, "TAKE PROFIT5 %", 0, group="BUY & SELL
SIGNALS")
//Strong Buy/Sell
showStrongBuySell = input(true, "STRONG BUY/SELL SIGNALS ON/OFF", group="STRONG
BUY & SELL SIGNALS")
sensitivity2 = input.float(6.4, "SENSITIVITY", 0.1, 20, group="STRONG BUY &
SELL SIGNALS")
percentStrongStop = input.float(1.0, "STOP LOSS %", 0)
percentStrongTake = input.float(0.28, "TAKE PROFIT %", 0)
percentStrongTake2 = input.float(0.56, "TAKE PROFIT2 %", 0)
percentStrongTake3 = input.float(0.84, "TAKE PROFIT3 %", 0)
percentStrongTake4 = input.float(1.12, "TAKE PROFIT4 %", 0)
percentStrongTake5 = input.float(1.40, "TAKE PROFIT5 %", 0)

offsetSignal = input.float(1, "SIGNAL OFFSET", 0, group="BUY & SELL SIGNALS")


showReversal = input(true, "REVERSAL SIGNALS ON/OFF", group="BUY & SELL
SIGNALS")
// Entry & Exit
enableE = input(true, "EXIT & ENTRY ON/OFF", group="EXIT & ENTRY")
Stop = input.color(color.new(#83868f, 5), "STOP LOSS", group="EXIT &
ENTRY")
Entry = input.color(color.new(#8d020e, 5), "ENTRY", group="EXIT &
ENTRY")
Tp1 = input.color(color.new(#038007, 5), "TAKE PROFIT", group="EXIT &
ENTRY")
// Supply & Demand
enableSD = input(false, "SUPPLY & DEMAND ON/OFF", group="SUPPLY & DEMAND")
mitigation = input.string('Wick', 'MITIGATION', options = ['Wick', 'Close'],
group ="SUPPLY & DEMAND")
length = input.int(20, 'VOLUME PIVOT', minval = 1, group ="SUPPLY &
DEMAND")
bull_ext_last = input.int(1, 'DEMAND', minval = 1, inline = 'bull', group
="SUPPLY & DEMAND")
bull_avg_css = input.color(color.new(#019106, 1), '', inline = 'bull', group
="SUPPLY & DEMAND")
bull_css = input.color(color.new(#00000000, 100), '', inline = 'bull',
group ="SUPPLY & DEMAND")
bg_bull_css = input.color(color.new(#00ff0a, 90), '', inline = 'bull', group
="SUPPLY & DEMAND")
bear_ext_last = input.int(1, 'SUPPLY', minval = 1 , inline = 'bear', group
="SUPPLY & DEMAND")
bear_avg_css = input.color(color.new(#86020d, 1), '', inline = 'bear', group
="SUPPLY & DEMAND")
bear_css = input.color(color.new(#00000000, 100), '', inline = 'bear',
group ="SUPPLY & DEMAND")
bg_bear_css = input.color(color.new(#ff0015, 90), '', inline = 'bear', group
="SUPPLY & DEMAND")
line_style = input.string("Solid", "LINE STYLE", ["Solid", "Dotted",
"Dashed"], group ="SUPPLY & DEMAND")
line_width = input.int(2, 'LINE WIDTH', minval = 1, group ="SUPPLY &
DEMAND")
// Support & Resistance
enableSR = input(false, "SUPPORT & RESISTANCE ON/Off", group="SUPPORT &
RESISTANCE")
colorSup = input(#00dbff, "SUPPORT", group="SUPPORT & RESISTANCE")
colorRes = input(#E91E63, "RESISTANCE", group="SUPPORT & RESISTANCE")
strengthSR = input.int(6, "S/R STRENGTH", 1, group="SUPPORT & RESISTANCE")
lineStyle1 = input.string("Solid", "LINE STYLE", ["Solid", "Dotted",
"Dashed"], group="SUPPORT & RESISTANCE")
lineWidth1 = input.int(2, "LINE WIDTH", 1, group="SUPPORT & RESISTANCE")
expandSR = input(false, "EXTEND LINES", group = "SUPPORT & RESISTANCE")
useZones = input(false, "ZONE ON/OFF", group="SUPPORT & RESISTANCE")
useHLZones = input(false, "HIGH LOW ZONES ON/OFF", group="SUPPORT &
RESISTANCE")
zoneWidth = input.int(4, "ZONE WIDTH %", 0, tooltip="it's calculated using
% of the distance between highest/lowest in last 300 bars", group="SUPPORT &
RESISTANCE")
// Trend Table
showDashboard = input(false, "TeiwazTrading ON/OFF", group="TeiwazTrading
DASHBOARD")
locationDashboard = input.string("Top Right", "Table Location", ["Top Right",
"Middle Right", "Bottom Right", "Top Center", "Middle Center", "Bottom Center",
"Top Left", "Middle Left", "Bottom Left"], group="TREND DASHBOARD")
tableTextColor = input(color.rgb(236, 233, 233), "TEXT", group="TeiwazTrading
DASHBOARD")
tableBgColor = input(color.black, "BACKGROUND", group="TeiwazTrading
DASHBOARD")
sizeDashboard = input.string("Small", "TABLE SIZE", ["Large", "Normal",
"Small", "Tiny"], group="TeiwazTrading DASHBOARD")
showPdHlc = input(false, "PREVIOUS DAY H/L/C", group="PREVIOUS DAY HIGH LOW
CLOSE")
lineColor = input.color(#028a07, "LINE COLORS", group="PREVIOUS DAY HIGH
LOW CLOSE")
lineStyle = input.string("Solid", "LINE STYLE", ["Solid", "Dotted",
"Dashed"], group ="PREVIOUS DAY HIGH LOW CLOSE")
lineWidth = input.int(1, "LINE WIDTH", group="PREVIOUS DAY HIGH LOW CLOSE")

// Create non-repainting security function


rp_security(_symbol, _res, _src) =>
request.security(_symbol, _res, _src[barstate.isrealtime ? 1 : 0])

htfHigh = rp_security(syminfo.tickerid, res, high)


htfLow = rp_security(syminfo.tickerid, res, low)

// Main Indicator
// Functions
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
smoothrng = ta.ema(avrng, wper) * m
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
percWidth(len, perc) => (ta.highest(len) - ta.lowest(len)) * perc / 100
securityNoRep(sym, res, src) => request.security(sym, res, src, barmerge.gaps_off,
barmerge.lookahead_on)
swingPoints(prd) =>
pivHi = ta.pivothigh(prd, prd)
pivLo = ta.pivotlow (prd, prd)
last_pivHi = ta.valuewhen(pivHi, pivHi, 1)
last_pivLo = ta.valuewhen(pivLo, pivLo, 1)
hh = pivHi and pivHi > last_pivHi ? pivHi : na
lh = pivHi and pivHi < last_pivHi ? pivHi : na
hl = pivLo and pivLo > last_pivLo ? pivLo : na
ll = pivLo and pivLo < last_pivLo ? pivLo : na
[hh, lh, hl, ll]
f_chartTfInMinutes() =>
float _resInMinutes = timeframe.multiplier * (
timeframe.isseconds ? 1 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
f_kc(src, len, sensitivity) =>
basis = ta.sma(src, len)
span = ta.atr(len)
[basis + span * sensitivity, basis - span * sensitivity]
wavetrend(src, chlLen, avgLen) =>
esa = ta.ema(src, chlLen)
d = ta.ema(math.abs(src - esa), chlLen)
ci = (src - esa) / (0.015 * d)
wt1 = ta.ema(ci, avgLen)
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]
f_fractalize (src) => f_top_fractal(src) ? 1 : f_bot_fractal(src) ? -1 : 0
f_findDivs(src, topLimit, botLimit) =>
fractalTop = f_fractalize(src) > 0 and src[2] >= topLimit ? src[2] : na
fractalBot = f_fractalize(src) < 0 and src[2] <= botLimit ? src[2] : na
highPrev = ta.valuewhen(fractalTop, src[2], 0)[2]
highPrice = ta.valuewhen(fractalTop, high[2], 0)[2]
lowPrev = ta.valuewhen(fractalBot, src[2], 0)[2]
lowPrice = ta.valuewhen(fractalBot, low[2], 0)[2]
bearSignal = fractalTop and high[1] > highPrice and src[1] < highPrev
bullSignal = fractalBot and low[1] < lowPrice and src[1] > lowPrev
[bearSignal, bullSignal]

// Get components
source = input(close, title = "Smoothring Source", group = "Smoothing")
smrng1_input= input.int(55, "Smring1", 1, 200 , 1 , group = "Smoothing")
smrng1_sens = input.float(defval = 3.0,title = "sens",minval = 0.1, maxval = 100 ,
step = 0.01 , group = "Smoothing")
smrng2_input= input.int(200, "Smring2", 1, 500 , 1 , group = "Smoothing")
smrng1 = smoothrng(source, smrng1_input, smrng1_sens)
smrng2 = smoothrng(source, smrng2_input, sensitivity)
smrng = (smrng1 + smrng2) / 2
filt = rngfilt(source, smrng)
up = 0.0, up := filt > filt[1] ? nz(up[1]) + 1 : filt < filt[1] ? 0 :
nz(up[1])
dn = 0.0, dn := filt < filt[1] ? nz(dn[1]) + 1 : filt > filt[1] ? 0 :
nz(dn[1])
bullCond = bool(na), bullCond := source > filt and source > source[1] and up > 0
or source > filt and source < source[1] and up > 0
bearCond = bool(na), bearCond := source < filt and source < source[1] and dn > 0
or source < filt and source > source[1] and dn > 0
lastCond = 0, lastCond := bullCond ? 1 : bearCond ? -1 : lastCond[1]
bull = bullCond and lastCond[1] == -1
bear = bearCond and lastCond[1] == 1
smrng3 = smoothrng(source, smrng2_input, sensitivity2)
smrngstrong = (smrng1 + smrng3) / 2
filt2 = rngfilt(source, smrngstrong)
up2 = 0.0, up2 := filt2 > filt2[1] ? nz(up2[1]) + 1 : filt2 < filt2[1] ? 0 :
nz(up2[1])
dn2 = 0.0, dn2 := filt2 < filt2[1] ? nz(dn2[1]) + 1 : filt2 > filt2[1] ? 0 :
nz(dn2[1])
strongbullCond = bool(na), strongbullCond := source > filt2 and source > source[1]
and up2 > 0 or source > filt2 and source < source[1] and up2 > 0
strongbearCond = bool(na), strongbearCond := source < filt2 and source < source[1]
and dn2 > 0 or source < filt2 and source > source[1] and dn2 > 0
lastCond2 = 0, lastCond2 := strongbullCond ? 1 : strongbearCond ? -1 :
lastCond2[1]
strongbull = strongbullCond and lastCond2[1] == -1
strongbear = strongbearCond and lastCond2[1] == 1
countBull = ta.barssince(bull)
countBear = ta.barssince(bear)
countStrongBull = ta.barssince(strongbull)
countStrongBear = ta.barssince(strongbear)
trigger = nz(countBull, bar_index) < nz(countBear, bar_index) ? 1 : 0
rsi = ta.rsi(close, 28)
rsiOb = rsi > 78 and rsi > ta.ema(rsi, 10)
rsiOs = rsi < 27 and rsi < ta.ema(rsi, 10)
dHigh = securityNoRep(syminfo.tickerid, "D", high [1])
dLow = securityNoRep(syminfo.tickerid, "D", low [1])
dClose = securityNoRep(syminfo.tickerid, "D", close[1])
ema = ta.ema(close, 144)
emaBull = close > ema
equal_tf(res) => str.tonumber(res) == f_chartTfInMinutes() and not
timeframe.isseconds
higher_tf(res) => str.tonumber(res) > f_chartTfInMinutes() or timeframe.isseconds
too_small_tf(res) => (timeframe.isweekly and res=="1") or (timeframe.ismonthly and
str.tonumber(res) < 10)
securityNoRep1(sym, res, src) =>
bool bull_ = na
bull_ := equal_tf(res) ? src : bull_
bull_ := higher_tf(res) ? request.security(sym, res, src, barmerge.gaps_off,
barmerge.lookahead_on) : bull_
bull_array = request.security_lower_tf(syminfo.tickerid, higher_tf(res) ?
str.tostring(f_chartTfInMinutes()) + (timeframe.isseconds ? "S" : "") :
too_small_tf(res) ? (timeframe.isweekly ? "3" : "10") : res, src)
if array.size(bull_array) > 1 and not equal_tf(res) and not higher_tf(res)
bull_ := array.pop(bull_array)
array.clear(bull_array)
bull_
TF1Bull = securityNoRep1(syminfo.tickerid, "1" , emaBull)
TF3Bull = securityNoRep1(syminfo.tickerid, "3" , emaBull)
TF5Bull = securityNoRep1(syminfo.tickerid, "5" , emaBull)
TF15Bull = securityNoRep1(syminfo.tickerid, "15" , emaBull)
TF30Bull = securityNoRep1(syminfo.tickerid, "30" , emaBull)
TF60Bull = securityNoRep1(syminfo.tickerid, "60" , emaBull)
TF120Bull = securityNoRep1(syminfo.tickerid, "120" , emaBull)
TF240Bull = securityNoRep1(syminfo.tickerid, "240" , emaBull)
TF480Bull = securityNoRep1(syminfo.tickerid, "480" , emaBull)
TFDBull = securityNoRep1(syminfo.tickerid, "1440", emaBull)
[wt1, wt2] = wavetrend(close, 5, 10)
[wtDivBear1, wtDivBull1] = f_findDivs(wt2, 15, -40)
[wtDivBear2, wtDivBull2] = f_findDivs(wt2, 45, -65)
wtDivBull = wtDivBull1 or wtDivBull2
wtDivBear = wtDivBear1 or wtDivBear2

// Colors
white = #00e4fd, white30 = color.new(white, 100)
blue = #fd00a4, blue30 = color.new(blue, 100)
whiteish = #ffffff, whiteish30 = color.new(whiteish , 100)

// Plot
off = percWidth(300, offsetSignal)
barcolor(up > dn ? white : blue)
plotshape(showBuySell and bull ? low - off : na, "Buy Label" , shape.labelup ,
location.absolute, color(#028a14), 0, "Buy" , color.white, size=size.tiny)
plotshape(showBuySell and bear ? high + off : na, "Sell Label", shape.labeldown,
location.absolute, color(#8b010d), 0, "Sell", color.white, size=size.tiny)
plotshape(showStrongBuySell and strongbull ? low - off : na, "Strong Buy Label" ,
shape.labelup , location.absolute, color(#028a14), 0, "Strong-Buy" , color.white,
size=size.tiny)
plotshape(showStrongBuySell and strongbear ? high + off : na, "Strong Sell Label",
shape.labeldown, location.absolute, color(#8b010d), 0, "Strong-Sell", color.white,
size=size.tiny)
plotshape(ta.crossover(wt1, wt2) and wt2 <= -53, "Don't Sell/Bottom" ,
shape.xcross, location.belowbar, color(#fd0015), size=size.tiny)
plotshape(ta.crossunder(wt1, wt2) and wt2 >= 53, "Don't Buy/Top", shape.xcross,
location.abovebar, color(#00ff22), size=size.tiny)
plotshape(wtDivBull, "Weak Buy ", shape.circle , location.belowbar,
color(#00ff22), size=size.auto)
plotshape(wtDivBear, "Weak Sell", shape.circle, location.abovebar, color(#fd0015),
size=size.auto)
plotshape(showReversal and rsiOs, "Reversal Buy" , shape.diamond,
location.belowbar, color(#00ff22), size=size.tiny)
plotshape(showReversal and rsiOb, "Reversal Sell", shape.diamond,
location.abovebar, color(#fd0015), size=size.tiny)

srcStop = close
atrBand = srcStop * (percentStop / 100)
atrBand2 = srcStop * (percentTake / 100)
atrBand3 = srcStop * (percentTake2 / 100)
atrBand4 = srcStop * (percentTake3 / 100)
atrBand5 = srcStop * (percentTake4 / 100)
atrBand6 = srcStop * (percentTake5 / 100)
atrStop = trigger ? srcStop - atrBand : srcStop + atrBand
atrTake = trigger ? srcStop - atrBand2 : srcStop + atrBand2
atrTake2 = trigger ? srcStop - atrBand3 : srcStop + atrBand3
atrTake3 = trigger ? srcStop - atrBand4 : srcStop + atrBand4
atrTake4 = trigger ? srcStop - atrBand5 : srcStop + atrBand5
atrTake5 = trigger ? srcStop - atrBand6 : srcStop + atrBand6
lastTrade(src) => ta.valuewhen(bull or bear, src, 0)
entry_y = lastTrade(srcStop)
stop_y = lastTrade(atrStop)
tp1_y = (entry_y - lastTrade(atrTake)) + entry_y
tp2_y = (entry_y - lastTrade(atrTake2)) + entry_y
tp3_y = (entry_y - lastTrade(atrTake3)) + entry_y
tp4_y = (entry_y - lastTrade(atrTake4)) + entry_y
tp5_y = (entry_y - lastTrade(atrTake5)) + entry_y

// Labels
labelTpSl(y, txt, color) =>
label labelTpSl = percentStop and enableE != 0 ? label.new(bar_index + 1, y,
txt, xloc.bar_index, yloc.price, color, label.style_label_left, color.white,
size.normal) : na
label.delete(labelTpSl[1])
labelTpSl(entry_y, "Entry: " + str.tostring(math.round_to_mintick(entry_y)), color
= Entry)
labelTpSl(stop_y , "StopLoss: " + str.tostring(math.round_to_mintick(stop_y)),
color = Stop)
labelTpSl(tp1_y, "Take Profit 1: " + str.tostring(math.round_to_mintick(tp1_y)),
color = Tp1)
labelTpSl(tp2_y, "Take Profit 2: " + str.tostring(math.round_to_mintick(tp2_y)),
color = Tp1)
labelTpSl(tp3_y, "Take Profit 3: " + str.tostring(math.round_to_mintick(tp3_y)),
color = Tp1)
labelTpSl(tp4_y, "Take Profit 4: " + str.tostring(math.round_to_mintick(tp4_y)),
color = Tp1)
labelTpSl(tp5_y, "Take Profit 5: " + str.tostring(math.round_to_mintick(tp5_y)),
color = Tp1)
lineTpSl(y, color) =>
line lineTpSl = percentStop and enableE != 0 ? line.new(bar_index - (trigger ?
countBull : countBear) + 4, y, bar_index + 1, y, xloc.bar_index, extend.none,
color, line.style_solid) : na
line.delete(lineTpSl[1])
lineTpSl(entry_y, color = Entry)
lineTpSl(stop_y, color = Stop)
lineTpSl(tp1_y, color = Tp1)
lineTpSl(tp2_y, color = Tp1)
lineTpSl(tp3_y, color = Tp1)
lineTpSl(tp4_y, color = Tp1)
lineTpSl(tp5_y, color = Tp1)

// SUPPLY & DEMAND


//Functions

//Line Style function


get_line_style(style) =>
out = switch style
'Solid' => line.style_solid
'Dashed' => line.style_dashed
'Dotted' => line.style_dotted

//Function to get order block coordinates


get_coordinates(condition, top, btm, ob_val)=>
var ob_top = array.new_float(0)
var ob_btm = array.new_float(0)
var ob_avg = array.new_float(0)
var ob_left = array.new_int(0)

float ob = na

//Append coordinates to arrays


if condition and enableSD
avg = math.avg(top, btm)

array.unshift(ob_top, top)
array.unshift(ob_btm, btm)
array.unshift(ob_avg, avg)
array.unshift(ob_left, time[length])

ob := ob_val

[ob_top, ob_btm, ob_avg, ob_left, ob]

//Function to remove mitigated order blocks from coordinate arrays


remove_mitigated(ob_top, ob_btm, ob_left, ob_avg, target, bull)=>
mitigated = false
target_array = bull ? ob_btm : ob_top

for element in target_array


idx = array.indexof(target_array, element)

if (bull ? target < element : target > element)


mitigated := true

array.remove(ob_top, idx)
array.remove(ob_btm, idx)
array.remove(ob_avg, idx)
array.remove(ob_left, idx)

mitigated
//Function to set order blocks
set_order_blocks(ob_top, ob_btm, ob_left, ob_avg, ext_last, bg_css, border_css,
lvl_css)=>
var ob_box = array.new_box(0)
var ob_lvl = array.new_line(0)

//Fill arrays with boxes/lines


if barstate.isfirst
for i = 0 to ext_last-1
array.unshift(ob_box, box.new(na,na,na,na
, xloc = xloc.bar_time
, extend= extend.right
, bgcolor = bg_css
, border_color = color.new(border_css, 70)))

array.unshift(ob_lvl, line.new(na,na,na,na
, xloc = xloc.bar_time
, extend = extend.right
, color = lvl_css
, style = get_line_style(line_style)
, width = line_width))

//Set order blocks


if barstate.islast
if array.size(ob_top) > 0
for i = 0 to math.min(ext_last-1, array.size(ob_top)-1)
get_box = array.get(ob_box, i)
get_lvl = array.get(ob_lvl, i)

box.set_lefttop(get_box, array.get(ob_left, i), array.get(ob_top,


i))
box.set_rightbottom(get_box, array.get(ob_left, i),
array.get(ob_btm, i))

line.set_xy1(get_lvl, array.get(ob_left, i), array.get(ob_avg, i))


line.set_xy2(get_lvl, array.get(ob_left, i)+1, array.get(ob_avg,
i))

//Global elements
var os = 0
var target_bull = 0.
var target_bear = 0.

n = bar_index
upper = ta.highest(length)
lower = ta.lowest(length)

if mitigation == 'Close'
target_bull := ta.lowest(close, length)
target_bear := ta.highest(close, length)
else
target_bull := lower
target_bear := upper

os := high[length] > upper ? 0 : low[length] < lower ? 1 : os[1]

phv = ta.pivothigh(volume, length, length)


//Get bullish/bearish order blocks coordinates
[bull_top
, bull_btm
, bull_avg
, bull_left
, bull_ob] = get_coordinates(phv and os == 1, hl2[length], low[length],
low[length])

[bear_top
, bear_btm
, bear_avg
, bear_left
, bear_ob] = get_coordinates(phv and os == 0, high[length], hl2[length],
high[length])

//Remove mitigated order blocks


mitigated_bull = remove_mitigated(bull_top
, bull_btm
, bull_left
, bull_avg
, target_bull
, true)

mitigated_bear = remove_mitigated(bear_top
, bear_btm
, bear_left
, bear_avg
, target_bear
, false)

//Set bullish order blocks


set_order_blocks(bull_top
, bull_btm
, bull_left
, bull_avg
, bull_ext_last
, bg_bull_css
, bull_css
, bull_avg_css)

//Set bearish order blocks


set_order_blocks(bear_top
, bear_btm
, bear_left
, bear_avg
, bear_ext_last
, bg_bear_css
, bear_css
, bear_avg_css)

// SUPPORT & RESISTANCE

percWidth1(len, perc) => (ta.highest(len) - ta.lowest(len)) * perc / 100

// Get components
rb = 10
prd = 284
ChannelW = 10
label_loc = 55
style1 = lineStyle1 == "Solid" ? line.style_solid : lineStyle1 == "Dotted" ?
line.style_dotted : line.style_dashed
ph = ta.pivothigh(rb, rb)
pl = ta.pivotlow (rb, rb)
sr_levels = array.new_float(21, na)
prdhighest = ta.highest(prd)
prdlowest = ta.lowest(prd)
cwidth = percWidth(prd, ChannelW)
zonePerc = percWidth(300, zoneWidth)
aas = array.new_bool(41, true)
u1 = 0.0, u1 := nz(u1[1])
d1 = 0.0, d1 := nz(d1[1])
highestph = 0.0, highestph := highestph[1]
lowestpl = 0.0, lowestpl := lowestpl[1]
var sr_levs = array.new_float(21, na)
label hlabel = na, label.delete(hlabel[1])
label llabel = na, label.delete(llabel[1])
var sr_lines = array.new_line(21, na)
var sr_linesH = array.new_line(21, na)
var sr_linesL = array.new_line(21, na)
var sr_linesF = array.new_linefill(21, na)
var sr_labels = array.new_label(21, na)
if ph or pl
for x = 0 to array.size(sr_levels) - 1
array.set(sr_levels, x, na)
highestph := prdlowest
lowestpl := prdhighest
countpp = 0
for x = 0 to prd
if na(close[x])
break
if not na(ph[x]) or not na(pl[x])
highestph := math.max(highestph, nz(ph[x], prdlowest), nz(pl[x],
prdlowest))
lowestpl := math.min(lowestpl, nz(ph[x], prdhighest), nz(pl[x],
prdhighest))
countpp += 1
if countpp > 40
break
if array.get(aas, countpp)
upl = (ph[x] ? high[x + rb] : low[x + rb]) + cwidth
dnl = (ph[x] ? high[x + rb] : low[x + rb]) - cwidth
u1 := countpp == 1 ? upl : u1
d1 := countpp == 1 ? dnl : d1
tmp = array.new_bool(41, true)
cnt = 0
tpoint = 0
for xx = 0 to prd
if na(close[xx])
break
if not na(ph[xx]) or not na(pl[xx])
chg = false
cnt += 1
if cnt > 40
break
if array.get(aas, cnt)
if not na(ph[xx])
if high[xx + rb] <= upl and high[xx + rb] >= dnl
tpoint += 1
chg := true
if not na(pl[xx])
if low[xx + rb] <= upl and low[xx + rb] >= dnl
tpoint += 1
chg := true
if chg and cnt < 41
array.set(tmp, cnt, false)
if tpoint >= strengthSR
for g = 0 to 40 by 1
if not array.get(tmp, g)
array.set(aas, g, false)
if ph[x] and countpp < 21
array.set(sr_levels, countpp, high[x + rb])
if pl[x] and countpp < 21
array.set(sr_levels, countpp, low[x + rb])

// Plot
var line highest_ = na, line.delete(highest_)
var line lowest_ = na, line.delete(lowest_)
var line highest_fill1 = na, line.delete(highest_fill1)
var line highest_fill2 = na, line.delete(highest_fill2)
var line lowest_fill1 = na, line.delete(lowest_fill1)
var line lowest_fill2 = na, line.delete(lowest_fill2)
hi_col = close >= highestph ? colorSup : colorRes
lo_col = close >= lowestpl ? colorSup : colorRes
if enableSR
highest_ := line.new(bar_index - 311, highestph, bar_index, highestph,
xloc.bar_index, expandSR ? extend.both : extend.right, hi_col, style1, lineWidth1)
lowest_ := line.new(bar_index - 311, lowestpl , bar_index, lowestpl ,
xloc.bar_index, expandSR ? extend.both : extend.right, lo_col, style1, lineWidth1)
if useHLZones
highest_fill1 := line.new(bar_index - 311, highestph + zonePerc, bar_index,
highestph + zonePerc, xloc.bar_index, expandSR ? extend.both : extend.right, na)
highest_fill2 := line.new(bar_index - 311, highestph - zonePerc, bar_index,
highestph - zonePerc, xloc.bar_index, expandSR ? extend.both : extend.right, na)
lowest_fill1 := line.new(bar_index - 311, lowestpl + zonePerc , bar_index,
lowestpl + zonePerc , xloc.bar_index, expandSR ? extend.both : extend.right, na)
lowest_fill2 := line.new(bar_index - 311, lowestpl - zonePerc , bar_index,
lowestpl - zonePerc , xloc.bar_index, expandSR ? extend.both : extend.right, na)
linefill.new(highest_fill1, highest_fill2, color.new(hi_col, 90))
linefill.new(lowest_fill1 , lowest_fill2 , color.new(lo_col, 90))
if ph or pl
for x = 0 to array.size(sr_lines) - 1
array.set(sr_levs, x, array.get(sr_levels, x))
for x = 0 to array.size(sr_lines) - 1
line.delete(array.get(sr_lines, x))
line.delete(array.get(sr_linesH, x))
line.delete(array.get(sr_linesL, x))
linefill.delete(array.get(sr_linesF, x))
if array.get(sr_levs, x) and enableSR
line_col = close >= array.get(sr_levs, x) ? colorSup : colorRes
array.set(sr_lines, x, line.new(bar_index - 355, array.get(sr_levs, x),
bar_index, array.get(sr_levs, x), xloc.bar_index, expandSR ? extend.both :
extend.right, line_col, style1, lineWidth1))
if useZones
array.set(sr_linesH, x, line.new(bar_index - 355, array.get(sr_levs, x)
+ zonePerc, bar_index, array.get(sr_levs, x) + zonePerc, xloc.bar_index, expandSR ?
extend.both : extend.right, na))
array.set(sr_linesL, x, line.new(bar_index - 355, array.get(sr_levs, x)
- zonePerc, bar_index, array.get(sr_levs, x) - zonePerc, xloc.bar_index, expandSR ?
extend.both : extend.right, na))
array.set(sr_linesF, x, linefill.new(array.get(sr_linesH, x),
array.get(sr_linesL, x), color.new(line_col, 90)))
for x = 0 to array.size(sr_labels) - 1
label.delete(array.get(sr_labels, x))
if array.get(sr_levs, x) and enableSR
lab_loc = close >= array.get(sr_levs, x) ? label.style_label_up :
label.style_label_down
lab_col = close >= array.get(sr_levs, x) ? colorSup : colorRes

////////////////////////////////////////////////////////////////////////////////
// Alerts
// to automate put this in trendinview message:
{{strategy.order.alert_message}}
i_alert_txt_entry_long = input.text_area(defval = "", title = "Long Entry Message",
group = "Alerts")
i_alert_txt_exit_long = input.text_area(defval = "", title = "Long Exit Message",
group = "Alerts")
i_alert_txt_entry_short = input.text_area(defval = "", title = "Short Entry
Message", group = "Alerts")
i_alert_txt_exit_short = input.text_area(defval = "", title = "Short Exit Message",
group = "Alerts")
//i_alert_txt_TP_long = input.text_area(defval = "", title = "Long TP Message",
group = "Alerts")
//i_alert_txt_TP_short = input.text_area(defval = "", title = "Short TP Message",
group = "Alerts")
//i_alert_txt_SL_long = input.text_area(defval = "", title = "Long SL Message",
group = "Alerts")
//i_alert_txt_SL_short = input.text_area(defval = "", title = "Short SL Message",
group = "Alerts")

// Entries and Exits with TP/SL


if bull
strategy.close("Short" ,alert_message = i_alert_txt_exit_short, comment =
"Close Short")
strategy.entry("Long" , strategy.long , alert_message = i_alert_txt_entry_long)
strategy.exit("Take Profit 1", from_entry = "Long", limit = tp1_y , qty_percent
= 20)//, alert_message = i_alert_txt_TP_long)
strategy.exit("Take Profit 2", from_entry = "Long", limit = tp2_y , qty_percent
= 20)//, alert_message = i_alert_txt_TP_long)
strategy.exit("Take Profit 3", from_entry = "Long", limit = tp3_y , qty_percent
= 20)//, alert_message = i_alert_txt_TP_long)
strategy.exit("Take Profit 4", from_entry = "Long", limit = tp4_y , qty_percent
= 30)//, alert_message = i_alert_txt_TP_long)
strategy.exit("Take Profit 5", from_entry = "Long", limit = tp5_y , qty_percent
= 100)//, alert_message = i_alert_txt_TP_long)
strategy.exit("Stop Loss", from_entry = "Long", loss = stop_y, comment_loss =
"Long Stop Loss")//, alert_message = i_alert_txt_SL_long)

if bear
strategy.close("Long" , alert_message = i_alert_txt_exit_long , comment =
"Close Long")
strategy.entry("Short" , strategy.short, alert_message =
i_alert_txt_entry_short)
strategy.exit("Take Profit 1", from_entry = "Short", limit = tp1_y ,
qty_percent = 20)//, alert_message = i_alert_txt_TP_short)
strategy.exit("Take Profit 2", from_entry = "Short", limit = tp2_y ,
qty_percent = 20)//, alert_message = i_alert_txt_TP_short)
strategy.exit("Take Profit 3", from_entry = "Short", limit = tp3_y ,
qty_percent = 20)//, alert_message = i_alert_txt_TP_short)
strategy.exit("Take Profit 4", from_entry = "Short", limit = tp4_y ,
qty_percent = 30)//, alert_message = i_alert_txt_TP_short)
strategy.exit("Take Profit 5", from_entry = "Short", limit = tp5_y ,
qty_percent = 100)//, alert_message = i_alert_txt_TP_short)
strategy.exit("Stop Loss", from_entry = "Short", loss = stop_y, comment_loss =
"Short Stop Loss")//, alert_message = i_alert_txt_SL_short)

//indicator(title='Alma Moving Average Ribbon Reverse Length [', shorttitle='RLA


MA', overlay=true)
/// Security Function///
f_security(_symbol, _res, _src, _repaint) =>
request.security(_symbol, _res, _src[_repaint ? 0 : barstate.isrealtime ? 1 :
0])[_repaint ? 0 : barstate.isrealtime ? 0 : 1]
/// Inputs ///
cstm_res = input.timeframe(defval='', title='Resolution', group='Source settings',
tooltip='Custom resolution for function security, be careful sometimes you plot the
plots from wrong references.')
frep_src = input.bool(defval=true, title='Allow Repainting', group='Source
settings', tooltip='Function Repaint')
src_opt = input.source(defval=close, title='Main Source', group='Source settings',
tooltip='Main Source')
alrt_00 = input.bool(defval=true, title='Active Alerts', group='Alert Settings',
tooltip='Active or desactive all alerts Active or desactive all alerts')
alrt_04 = input.bool(defval=false, title='Active Visual TrendAlerts', group='Alert
Settings', tooltip='Active or desactive all plotshape with trend direction alerts')
sfty_rnge = input.int(defval=00001, minval=00000, maxval=01000, step=00001,
title='Offset For Visual Alerts', group='Alert Settings', tooltip='Offset Value to
shot visul alerts')
alrt_01 = input.string(defval='#08', title='First source signal to activate alert',
options=['#08', '#07', '#06', '#05', '#04', '#03', '#02', '#01'], group='Alert
Settings', tooltip='First signal used for the crossing with the second signal then
in the third field choose the type of crossing ')
alrt_02 = input.string(defval='#07', title='Second source signal to activate
alert', options=['#07', '#06', '#05', '#04', '#03', '#02', '#01'], group='Alert
Settings', tooltip='Second signal used for the crossing with the first signal then
in the third field choose the type of crossing ')
alrt_03 = input.string(defval='ALL', title='Condition to activate alert',
options=['OVER', 'UNDER', 'ALL'], group='Alert Settings', tooltip='Choose the type
of crossing for both signals')
log_swch = input.bool(defval=false, title='Use log scale?', group='Source
settings', tooltip='Use log scale i the ind=icator')
fill_opt = input.bool(defval=true, title='Fill body of plots', group='Color
options', tooltip='Show Or Hide Colored Space Betwen The Plots')
main_len = input.int(defval=00423, minval=00001, maxval=01000, step=00001,
title='lma Main Length', group='Lenght settings', tooltip='Default Value 423')
ofs_alma = input.float(defval=1.0, minval=00.01, maxval=00001, step=00.01,
title='Main Offset lma', group='Lenght settings', tooltip='Default Value 0.1')
sig_alma = input.int(defval=00009, minval=00001, maxval=01000, step=00001,
title='Main Sigma lma', group='Lenght settings', tooltip='Default Value 9')
/// Source ///
source1 = log_swch ? f_security(syminfo.tickerid, cstm_res, math.log(open),
frep_src) : f_security(syminfo.tickerid, cstm_res, open, frep_src)
/// Brain & Autolength ///
alma_ma_01 = ta.alma(source, main_len, ofs_alma, sig_alma)
length_02 = math.round(main_len / math.phi)
alma_ma_02 = ta.alma(source, length_02, ofs_alma, sig_alma)
length_03 = math.round(length_02 / math.phi)
alma_ma_03 = ta.alma(source, length_03, ofs_alma, sig_alma)
length_04 = math.round(length_03 / math.phi)
alma_ma_04 = ta.alma(source, length_04, ofs_alma, sig_alma)
length_05 = math.round(length_04 / math.phi)
alma_ma_05 = ta.alma(source, length_05, ofs_alma, sig_alma)
length_06 = math.round(length_05 / math.phi)
alma_ma_06 = ta.alma(source, length_06, ofs_alma, sig_alma)
length_07 = math.round(length_06 / math.phi)
alma_ma_07 = ta.alma(source, length_07, ofs_alma, sig_alma)
length_08 = math.round(length_07 / math.phi)
alma_ma_08 = ta.alma(source, length_08, ofs_alma, sig_alma)
length_0x = math.round(length_08 / math.phi)
alma_ma_0x = ta.alma(source, length_0x, ofs_alma, sig_alma)
/// Colors ///
fxc_heatmap_ad_pro_0(_source) => //(_source, _center, _steps, _c_bearWeak,
_c_bearStrong, _c_bullWeak, _c_bullStrong)
ad_center = input.int(defval=000, minval=-100, maxval=100, step=001,
title='centerline', group='A/D Plots Colors Gradient', tooltip='(- ∞ to ∞)
centerline used to determine if signal is bullish/bearish')
ad_steps = input.int(defval=020, minval=0002, maxval=423, step=001,
title='Steps in the gradient', group='A/D Plots Colors Gradient', tooltip='Maximum
number of steps in the gradient from the weak color to the strong color')
ca_bullStrong = input.color(color.rgb(000, 255, 000, 035), title='Advanced
signal bull strong%', group='A/D Plots Colors Gradient', tooltip='Setting colors
AD')
ca_bullWeak = input.color(color.rgb(000, 255, 050, 055), title='Advanced signal
bull weak', group='A/D Plots Colors Gradient', tooltip='Setting colors AD')
cd_bearWeak = input.color(color.rgb(255, 000, 050, 055), title='Declined signal
bear weak', group='A/D Plots Colors Gradient', tooltip='Setting colors AD')
cd_bearStrong = input.color(color.rgb(255, 000, 000, 035), title='Declined
signal bear strong', group='A/D Plots Colors Gradient', tooltip='Setting colors
AD')
var float _qtyAdvDec = 0.
var float _maxSteps = math.max(1, ad_steps)
bool _xUp = ta.crossover(_source, ad_center)
bool _xDn = ta.crossunder(_source, ad_center)
float _chg = ta.change(_source)
bool _up = _chg > 0
bool _dn = _chg < 0
bool _srcBull = _source > ad_center
bool _srcBear = _source < ad_center
_qtyAdvDec := _srcBull ? _xUp ? 1 : _up ? math.min(_maxSteps, _qtyAdvDec + 1) :
_dn ? math.max(1, _qtyAdvDec - 1) : _qtyAdvDec : _srcBear ? _xDn ? 1 : _dn ?
math.min(_maxSteps, _qtyAdvDec + 1) : _up ? math.max(1, _qtyAdvDec - 1) :
_qtyAdvDec : _qtyAdvDec
var color _return = na
_return := _srcBull ? color.from_gradient(_qtyAdvDec, 1, _maxSteps,
ca_bullWeak, ca_bullStrong) : _srcBear ? color.from_gradient(_qtyAdvDec, 1,
_maxSteps, cd_bearWeak, cd_bearStrong) : _return
_return

fxc_heatmap_ad_pro_2(_source) => //(_source, _center, _steps, _c_bearWeak,


_c_bearStrong, _c_bullWeak, _c_bullStrong)
ad_center = input.int(defval=000, minval=-100, maxval=100, step=001,
title='centerline', group='A/D Fill Colors Gradient', tooltip='(- ∞ to ∞)
centerline used to determine if signal is bullish/bearish')
ad_steps = input.int(defval=020, minval=0002, maxval=423, step=001,
title='Steps in the gradient', group='A/D Fill Colors Gradient', tooltip='Maximum
number of steps in the gradient from the weak color to the strong color')
ca_bullStrong = input.color(color.rgb(0, 225, 255, 55), title='Advanced signal
bull strong%', group='A/D Fill Colors Gradient', tooltip='Setting colors AD')
ca_bullWeak = input.color(color.rgb(0, 255, 255, 85), title='Advanced signal
bull weak', group='A/D Fill Colors Gradient', tooltip='Setting colors AD')
cd_bearWeak = input.color(color.rgb(255, 0, 128, 85), title='Declined signal
bear weak', group='A/D Fill Colors Gradient', tooltip='Setting colors AD')
cd_bearStrong = input.color(color.rgb(255, 0, 179, 70), title='Declined signal
bear strong', group='A/D Fill Colors Gradient', tooltip='Setting colors AD')
var float _qtyAdvDec = 0.
var float _maxSteps = math.max(1, ad_steps)
bool _xUp = ta.crossover(_source, ad_center)
bool _xDn = ta.crossunder(_source, ad_center)
float _chg = ta.change(_source)
bool _up = _chg > 0
bool _dn = _chg < 0
bool _srcBull = _source > ad_center
bool _srcBear = _source < ad_center
_qtyAdvDec := _srcBull ? _xUp ? 1 : _up ? math.min(_maxSteps, _qtyAdvDec + 1) :
_dn ? math.max(1, _qtyAdvDec - 1) : _qtyAdvDec : _srcBear ? _xDn ? 1 : _dn ?
math.min(_maxSteps, _qtyAdvDec + 1) : _up ? math.max(1, _qtyAdvDec - 1) :
_qtyAdvDec : _qtyAdvDec
var color _return = na
_return := _srcBull ? color.from_gradient(_qtyAdvDec, 1, _maxSteps,
ca_bullWeak, ca_bullStrong) : _srcBear ? color.from_gradient(_qtyAdvDec, 1,
_maxSteps, cd_bearWeak, cd_bearStrong) : _return
_return

//=>OutPuts Colors
col_mav_01 = fxc_heatmap_ad_pro_0(alma_ma_02 - alma_ma_01)
col_maf_01 = fxc_heatmap_ad_pro_2(alma_ma_02 - alma_ma_01)
col_mav_02 = fxc_heatmap_ad_pro_0(alma_ma_03 - alma_ma_02)
col_maf_02 = fxc_heatmap_ad_pro_2(alma_ma_03 - alma_ma_02)
col_mav_03 = fxc_heatmap_ad_pro_0(alma_ma_04 - alma_ma_03)
col_maf_03 = fxc_heatmap_ad_pro_2(alma_ma_04 - alma_ma_03)
col_mav_04 = fxc_heatmap_ad_pro_0(alma_ma_05 - alma_ma_04)
col_maf_04 = fxc_heatmap_ad_pro_2(alma_ma_05 - alma_ma_04)
col_mav_05 = fxc_heatmap_ad_pro_0(alma_ma_06 - alma_ma_05)
col_maf_05 = fxc_heatmap_ad_pro_2(alma_ma_06 - alma_ma_05)
col_mav_06 = fxc_heatmap_ad_pro_0(alma_ma_07 - alma_ma_06)
col_maf_06 = fxc_heatmap_ad_pro_2(alma_ma_07 - alma_ma_06)
col_mav_07 = fxc_heatmap_ad_pro_0(alma_ma_08 - alma_ma_07)
col_maf_07 = fxc_heatmap_ad_pro_2(alma_ma_08 - alma_ma_07)
col_mav_08 = fxc_heatmap_ad_pro_0(alma_ma_0x - alma_ma_08)
col_maf_08 = fxc_heatmap_ad_pro_2(alma_ma_0x - alma_ma_08)
/// PLots ///
pl_ma_01 = plot(series=log_swch ? math.exp(alma_ma_01) : alma_ma_01, title='LMA
#01', color=col_mav_01, linewidth=2, style=plot.style_line,
offset=input.int(defval=00, title='Offset LMA #01', group='Offset LMA Plots'),
editable=true, display=display.all)
pl_ma_02 = plot(series=log_swch ? math.exp(alma_ma_02) : alma_ma_02, title='LMA
#02', color=col_mav_02, linewidth=2, style=plot.style_line,
offset=input.int(defval=00, title='Offset LMA #02', group='Offset LMA Plots'),
editable=true, display=display.all)
pl_ma_03 = plot(series=log_swch ? math.exp(alma_ma_03) : alma_ma_03, title='LMA
#03', color=col_mav_03, linewidth=2, style=plot.style_line,
offset=input.int(defval=00, title='Offset LMA #03', group='Offset LMA Plots'),
editable=true, display=display.all)
pl_ma_04 = plot(series=log_swch ? math.exp(alma_ma_04) : alma_ma_04, title='LMA
#04', color=col_mav_04, linewidth=2, style=plot.style_line,
offset=input.int(defval=00, title='Offset LMA #04', group='Offset LMA Plots'),
editable=true, display=display.all)
pl_ma_05 = plot(series=log_swch ? math.exp(alma_ma_05) : alma_ma_05, title='LMA
#05', color=col_mav_05, linewidth=2, style=plot.style_line,
offset=input.int(defval=00, title='Offset LMA #05', group='Offset LMA Plots'),
editable=true, display=display.all)
pl_ma_06 = plot(series=log_swch ? math.exp(alma_ma_06) : alma_ma_06, title='LMA
#06', color=col_mav_06, linewidth=2, style=plot.style_line,
offset=input.int(defval=00, title='Offset LMA #06', group='Offset LMA Plots'),
editable=true, display=display.all)
pl_ma_07 = plot(series=log_swch ? math.exp(alma_ma_07) : alma_ma_07, title='LMA
#07', color=col_mav_07, linewidth=2, style=plot.style_line,
offset=input.int(defval=00, title='Offset LMA #07', group='Offset LMA Plots'),
editable=true, display=display.all)
pl_ma_08 = plot(series=log_swch ? math.exp(alma_ma_08) : alma_ma_08, title='LMA
#08', color=col_mav_08, linewidth=2, style=plot.style_line,
offset=input.int(defval=00, title='Offset LMA #08', group='Offset LMA Plots'),
editable=true, display=display.all)
/// Fill ///
fill(plot1=pl_ma_01, plot2=pl_ma_02, color=fill_opt ? col_maf_01 : na, title='Fill
color', editable=false, fillgaps=true, transp=90)
fill(plot1=pl_ma_02, plot2=pl_ma_03, color=fill_opt ? col_maf_02 : na, title='Fill
color', editable=false, fillgaps=true, transp=90)
fill(plot1=pl_ma_03, plot2=pl_ma_04, color=fill_opt ? col_maf_03 : na, title='Fill
color', editable=false, fillgaps=true, transp=90)
fill(plot1=pl_ma_04, plot2=pl_ma_05, color=fill_opt ? col_maf_04 : na, title='Fill
color', editable=false, fillgaps=true, transp=90)
fill(plot1=pl_ma_05, plot2=pl_ma_06, color=fill_opt ? col_maf_05 : na, title='Fill
color', editable=false, fillgaps=true, transp=90)
fill(plot1=pl_ma_06, plot2=pl_ma_07, color=fill_opt ? col_maf_06 : na, title='Fill
color', editable=false, fillgaps=true, transp=90)
fill(plot1=pl_ma_07, plot2=pl_ma_08, color=fill_opt ? col_maf_07 : na, title='Fill
color', editable=false, fillgaps=true, transp=90)
/// PlotShape ///
cal_psh_val = 100 * (alma_ma_08 - alma_ma_07) / (alma_ma_08 + alma_ma_07) + 100 *
((alma_ma_07 - alma_ma_06) / (alma_ma_07 + alma_ma_06))
psh_cond_all = cal_psh_val > 0 and cal_psh_val > cal_psh_val[sfty_rnge] ? 1 :
cal_psh_val < 0 and cal_psh_val < cal_psh_val[sfty_rnge] ? 2 : 3
plotshape(series=alrt_04 ? psh_cond_all == 1 ? false : na : na, title='Plotshape',
style=shape.triangleup, location=location.bottom, color=color.new(color.green,
050), editable=true, size=size.tiny, display=display.all)
plotshape(series=alrt_04 ? psh_cond_all == 2 ? false : na : na, title='Plotshape',
style=shape.triangledown, location=location.top, color=color.new(color.red, 050),
editable=true, size=size.tiny, display=display.all)
///=>Fuction alert selection
f_crossalrt(ma01, ma02, crosstype) =>
src_01 = ma01 == '#08' ? alma_ma_01 : ma01 == '#07' ? alma_ma_02 : ma01 ==
'#06' ? alma_ma_03 : ma01 == '#05' ? alma_ma_04 : ma01 == '#04' ? alma_ma_05 : ma01
== '#03' ? alma_ma_06 : ma01 == '#02' ? alma_ma_07 : ma01 == '#01' ? alma_ma_08 :
0.0 // In doubt, return zero
src_02 = ma02 == '#07' ? alma_ma_02 : ma02 == '#06' ? alma_ma_03 : ma02 ==
'#05' ? alma_ma_04 : ma02 == '#04' ? alma_ma_05 : ma02 == '#03' ? alma_ma_06 : ma02
== '#02' ? alma_ma_07 : ma02 == '#01' ? alma_ma_08 : 0.0 // In doubt, return zero
cros_tp = crosstype == 'OVER' ? ta.crossover(src_01, src_02) : crosstype ==
'UNDER' ? ta.crossunder(src_01, src_02) : crosstype == 'ALL' ? ta.cross(src_01,
src_02) : na // In doubt
cros_tp
signal_alert = f_crossalrt(alrt_01, alrt_02, alrt_03)
///=>Alert post
if alrt_00 and signal_alert
alert('Symbol = (' + syminfo.tickerid + ') TimeFrame = (' + timeframe.period +
') Current Price (' + str.tostring(close) + ') The Moving Average Oscillator LMA
Cross Alarm Has Been Activated', alert.freq_once_per_bar_close)
/// End Of The Code///

// RSI Settings for user


rsiSource = input.source(title='RSI Source', defval=close)
rsiLength = input.int(title='RSI Length', defval=7)
rsiOverbought = input.int(title='RSI Overbought', defval=75, minval=50, maxval=100)
rsiOversold = input.int(title='RSI Oversold', defval=25, minval=1, maxval=50)
upcol = input.color(defval=#00ff2a, title='Zig Zag 1 Up Color')
dncol = input.color(defval=#fd0404, title='Zig Zag 1 Down Color')

// RSI value based on inbuilt RSI


rsiValue = ta.rsi(rsiSource, rsiLength)

// Get the current state


isOverbought = rsiValue >= rsiOverbought
isOversold = rsiValue <= rsiOversold

// State of the last extreme 0 for initialization, 1 = overbought, 2 = oversold


var laststate = 0

// Highest and Lowest prices since the last state change


var hhh = low
var lll = high

// Labels
var label labelll = na
var label labelhh = na

// Swing lines
var line line_up = na
var line line_down = na

// We go from overbought straight to oversold NEW DRAWINGS CREATED HERE


if bool(laststate == 1 and isOversold)
lll := low
labelll := label.new(bar_index, high, style=label.style_label_up,
color=#32CD32, size=size.small)
label.set_text(labelll, "100% Accurate BUY")
labelhh_low = label.get_x(labelhh)
labelhh_pos = label.get_y(labelhh)
line_down := line.new(bar_index, high, labelhh_low, labelhh_pos, width=2,
color=dncol)

// We go from oversold straight to overbought NEW DRAWINGS CREATED HERE


if bool(laststate == 2 and isOverbought)
hhh := high
labelhh := label.new(bar_index, high, style=label.style_label_down,
color=color.new(#ff0062, 20), size=size.small)
label.set_text(labelhh, "100% Accurate SELL")
labelll_low = label.get_x(labelll)
labelll_pos = label.get_y(labelll)
line_up := line.new(bar_index, high, labelll_low, labelll_pos, width=2,
color=upcol)

// If we are overbought
if bool(isOverbought)
if high >= hhh
hhh := high
label.set_x(labelhh, bar_index)
label.set_y(labelhh, high)
line.set_x1(line_up, bar_index)
line.set_y1(line_up, high)
laststate := 1

// If we are oversold
if bool(isOversold)
if low <= lll
lll := low
label.set_x(labelll, bar_index)
label.set_y(labelll, low)
line.set_x1(line_down, bar_index)
line.set_y1(line_down, low)
laststate := 2

// If last state was overbought and we are overbought


if bool(laststate == 1 and isOverbought)
if hhh <= high
hhh := high
label.set_x(labelhh, bar_index)
label.set_y(labelhh, high)
line.set_x1(line_up, bar_index)
line.set_y1(line_up, high)

// If we are oversold and the last state was oversold, move the drawings to the
lowest price
if bool(laststate == 2 and isOversold)
if low <= lll
lll := low
label.set_x(labelll, bar_index)
label.set_y(labelll, low)
line.set_x1(line_down, bar_index)
line.set_y1(line_down, low)

// If last state was overbought


if bool(laststate == 1)
if hhh <= high
hhh := high
label.set_x(labelhh, bar_index)
label.set_y(labelhh, high)
line.set_x1(line_up, bar_index)
line.set_y1(line_up, high)

// If last state was oversold


if bool(laststate == 2)
if lll >= low
lll := low
label.set_x(labelll, bar_index)
label.set_y(labelll, low)
line.set_x1(line_down, bar_index)
line.set_y1(line_down, low)
// Elder Impulse System
source11 = close

// MACD Options
macd_length_fast = input.int(defval=8, minval=1, title="MACD Fast Length")
macd_length_slow = input.int(defval=21, minval=1, title="MACD Slow Length")
macd_length_signal = input.int(defval=7, minval=1, title="MACD Signal Length")

// Calculate MACD
macd_ma_fast = ta.ema(source, macd_length_fast)
macd_ma_slow = ta.ema(source, macd_length_slow)
macd = macd_ma_fast - macd_ma_slow
macd_signal = ta.ema(macd, macd_length_signal)
macd_histogram = macd - macd_signal

// EMA Option
ema_length = input.int(defval=21, minval=1, title="EMA Length")

// Calculate EMA
ema1 = ta.ema(source, ema_length)

// Calculate Elder Impulse


elder_bulls = (ema[0] > ema[1]) and (macd_histogram[0] > macd_histogram[1])
elder_bears = (ema[0] < ema[1]) and (macd_histogram[0] < macd_histogram[1])
elder_color = elder_bulls ? color.green : elder_bears ? color.red : color.blue

barcolor(elder_color)

// Calculate Previous Day High (PDH) and Previous Day Low (PDL)
var float pdh = na
var float pdl = na

is_new_day = ta.change(time("D"))

if bool(is_new_day)
pdh := high[1]
pdl := low[1]

plot(pdh, title="Previous Day High", color=#04fd10, linewidth=1)


plot(pdl, title="Previous Day Low", color=#fd0101, linewidth=1)

// Exit feature
exit_condition = bool((isOverbought and elder_bears) or (isOversold and
elder_bulls))

// Plot the "X" symbol for exit condition


plotshape(series=exit_condition, location=location.abovebar, color=#fcfbf9,
style=shape.cross, text="X", size=size.small)

// Parameters
fib_lower = input(0.144, title='Fibonacci Lower Level')
fib_upper = input(0.886, title='Fibonacci Upper Level')

// Calculate 4-Hour Highs and Lows


four_hour_high = request.security(syminfo.tickerid, 'D', high[2])
four_hour_low = request.security(syminfo.tickerid, 'D', low[2])

// Define OTE Zone


ote_upper = four_hour_high - (four_hour_high - four_hour_low) * fib_lower
ote_lower = four_hour_high - (four_hour_high - four_hour_low) * fib_upper

// Plot 4-Hour Highs, Lows, and OTE Zone


//line.new(x1=bar_index[2], y1=four_hour_high, x2=bar_index, y2=four_hour_high,
color=#fa007d, width=1, extend=extend.right)
//line.new(x1=bar_index[2], y1=four_hour_low, x2=bar_index, y2=four_hour_low,
color=#05cafc, width=1, extend=extend.right)
ote_upper_plot = plot(ote_upper, color=#ffffff, linewidth=2, title='OTE Upper',
trackprice=false)
ote_lower_plot = plot(ote_lower, color=#ffffff, linewidth=2, title='OTE Lower',
trackprice=false)
//fill(ote_upper_plot, ote_lower_plot, color=color.new(color.silver, 80))

// Notes
// The red line represents the daily high, while the green line represents the
daily low.
// The gray area represents the optimal trade entry (OTE) zone based on Fibonacci
retracement levels.

//indicator("Auto Fib Retracement", overlay=true)

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."
// pivots threshold
threshold_multiplier = input.float(title="Deviation", defval=3, minval=0,
tooltip=devTooltip)
depth = input.int(title="Depth", defval=10, minval=2, tooltip=depthTooltip)
reverse = input(false, "Reverse")
var extendLeft = input(false, "Extend Left | Extend Right", inline = "Extend
Lines")
var extendRight = input(true, "", inline = "Extend Lines")
var extending = extend.none
if extendLeft and extendRight
extending := extend.both
if extendLeft and not extendRight
extending := extend.left
if not extendLeft and extendRight
extending := extend.right
prices = input(true, "Show Prices")
levels = input(true, "Show Levels", inline = "Levels")
levelsFormat = input.string("Values", "", options = ["Values", "Percent"], inline =
"Levels")
labelsPosition = input.string("Left", "Labels Position", options = ["Left",
"Right"])
var int backgroundTransparency = input.int(95, "Background Transparency", minval =
0, maxval = 100)

import TradingView/ZigZag/6 as zigzag

update()=>
var settings = zigzag.Settings.new(threshold_multiplier, depth, color(na),
false, false, false, false, "Absolute", true)
var zigzag.ZigZag zigZag = zigzag.newInstance(settings)
var zigzag.Pivot lastP = na
var float startPrice = na
var float height = na
settings.devThreshold := ta.atr(10) / close * 100 * threshold_multiplier
if zigZag.update()
lastP := zigZag.lastPivot()
if not na(lastP)
var line lineLast = na
if na(lineLast)
lineLast := line.new(lastP.start.tm, lastP.start.price,
lastP.end.tm, lastP.end.price, xloc=xloc.bar_time, color=color.gray, width=1,
style=line.style_dashed)
else
line.set_xy1(lineLast, lastP.start.tm, lastP.start.price)
line.set_xy2(lineLast, lastP.end.tm, lastP.end.price)

startPrice := reverse ? lastP.start.price : lastP.end.price


endPrice = reverse ? lastP.end.price : lastP.start.price
height := (startPrice > endPrice ? -1 : 1) * math.abs(startPrice -
endPrice)
[lastP, startPrice, height]

[lastP, startPrice, height] = update()

_draw_line(price, col) =>


var id = line.new(lastP.start.tm, lastP.start.price, time, price,
xloc=xloc.bar_time, color=col, width=1, extend=extending)
line.set_xy1(id, lastP.start.tm, price)
line.set_xy2(id, lastP.end.tm, price)
id

_draw_label(price, txt, txtColor) =>


x = labelsPosition == "Left" ? lastP.start.tm : not extendRight ?
lastP.end.tm : time
labelStyle = labelsPosition == "Left" ? label.style_label_right :
label.style_label_left
align = labelsPosition == "Left" ? text.align_right : text.align_left
labelsAlignStrLeft = txt + '\n
\n'
labelsAlignStrRight = ' ' + txt + '\n
\n'
labelsAlignStr = labelsPosition == "Left" ? labelsAlignStrLeft :
labelsAlignStrRight
var id = label.new(x=x, y=price, xloc=xloc.bar_time, text=labelsAlignStr,
textcolor=txtColor, style=labelStyle, textalign=align, color=#00000000)
label.set_xy(id, x, price)
label.set_text(id, labelsAlignStr)
label.set_textcolor(id, txtColor)

_wrap(txt) =>
"(" + str.tostring(txt, format.mintick) + ")"

_label_txt(level, price) =>


l = levelsFormat == "Values" ? str.tostring(level) : str.tostring(level * 100)
+ "%"
(levels ? l : "") + (prices ? _wrap(price) : "")

_crossing_level(series float sr, series float r) =>


(r > sr and r < sr[1]) or (r < sr and r > sr[1])

processLevel(bool show, float value, color colorL, line lineIdOther) =>


float m = value
r = startPrice + height * m
crossed = _crossing_level(close, r)
if show and not na(lastP)
lineId = _draw_line(r, colorL)
_draw_label(r, _label_txt(m, r), colorL)
if crossed
alert("Autofib: " + syminfo.ticker + " crossing level " +
str.tostring(value))
if not na(lineIdOther)
linefill.new(lineId, lineIdOther, color = color.new(colorL,
backgroundTransparency))
lineId
else
lineIdOther

show_0 = input(true, "", inline = "Level0")


value_0 = input(0, "", inline = "Level0")
color_0 = input(#fafafa, "", inline = "Level0")

show_0_236 = input(true, "", inline = "Level0")


value_0_236 = input(0.272, "", inline = "Level0")
color_0_236 = input(#fefefe, "", inline = "Level0")

show_0_382 = input(true, "", inline = "Level1")


value_0_382 = input(0.5, "", inline = "Level1")
color_0_382 = input(#eff308, "", inline = "Level1")

show_0_5 = input(true, "", inline = "Level1")


value_0_5 = input(0.618, "", inline = "Level1")
color_0_5 = input(#eff308, "", inline = "Level1")

show_0_618 = input(true, "", inline = "Level2")


value_0_618 = input(0.666, "", inline = "Level2")
color_0_618 = input(#eff308, "", inline = "Level2")

show_0_65 = input(true, "", inline = "Level2")


value_0_65 = input(0.707, "", inline = "Level2")
color_0_65 = input(#eff308, "", inline = "Level2")

show_0_786 = input(true, "", inline = "Level3")


value_0_786 = input(0.888, "", inline = "Level3")
color_0_786 = input(#f2f5f7, "", inline = "Level3")

show_1 = input(true, "", inline = "Level3")


value_1 = input(1, "", inline = "Level3")
color_1 = input(#f9fafe, "", inline = "Level3")

show_1_272 = input(true, "", inline = "Level4")


value_1_272 = input(1.272, "", inline = "Level4")
color_1_272 = input(#eef7ef, "", inline = "Level4")

show_1_414 = input(false, "", inline = "Level4")


value_1_414 = input(1.414, "", inline = "Level4")
color_1_414 = input(#f44336, "", inline = "Level4")

show_1_618 = input(false, "", inline = "Level5")


value_1_618 = input(1.618, "", inline = "Level5")
color_1_618 = input(#2962ff, "", inline = "Level5")
show_1_65 = input(false, "", inline = "Level5")
value_1_65 = input(1.65, "", inline = "Level5")
color_1_65 = input(#2962ff, "", inline = "Level5")

show_2_618 = input(false, "", inline = "Level6")


value_2_618 = input(2.618, "", inline = "Level6")
color_2_618 = input(#f44336, "", inline = "Level6")

show_2_65 = input(false, "", inline = "Level6")


value_2_65 = input(2.65, "", inline = "Level6")
color_2_65 = input(#f44336, "", inline = "Level6")

show_3_618 = input(false, "", inline = "Level7")


value_3_618 = input(3.618, "", inline = "Level7")
color_3_618 = input(#9c27b0, "", inline = "Level7")

show_3_65 = input(false, "", inline = "Level7")


value_3_65 = input(3.65, "", inline = "Level7")
color_3_65 = input(#9c27b0, "", inline = "Level7")

show_4_236 = input(false, "", inline = "Level8")


value_4_236 = input(4.236, "", inline = "Level8")
color_4_236 = input(#e91e63, "", inline = "Level8")

show_4_618 = input(false, "", inline = "Level8")


value_4_618 = input(4.618, "", inline = "Level8")
color_4_618 = input(#81c784, "", inline = "Level8")

show_neg_0_236 = input(true, "", inline = "Level9")


value_neg_0_236 = input(-0.272, "", inline = "Level9")
color_neg_0_236 = input(#36e4f4, "", inline = "Level9")

show_neg_0_382 = input(false, "", inline = "Level9")


value_neg_0_382 = input(-0.382, "", inline = "Level9")
color_neg_0_382 = input(#81c784, "", inline = "Level9")

show_neg_0_618 = input(false, "", inline = "Level10")


value_neg_0_618 = input(-0.618, "", inline = "Level10")
color_neg_0_618 = input(#009688, "", inline = "Level10")

show_neg_0_65 = input(false, "", inline = "Level10")


value_neg_0_65 = input(-0.65, "", inline = "Level10")
color_neg_0_65 = input(#009688, "", inline = "Level10")

lineId0 = processLevel(show_neg_0_65, value_neg_0_65, color_neg_0_65, line(na))


lineId1 = processLevel(show_neg_0_618, value_neg_0_618, color_neg_0_618, lineId0)
lineId2 = processLevel(show_neg_0_382, value_neg_0_382, color_neg_0_382, lineId1)
lineId3 = processLevel(show_neg_0_236, value_neg_0_236, color_neg_0_236, lineId2)
lineId4 = processLevel(show_0, value_0, color_0, lineId3)
lineId5 = processLevel(show_0_236, value_0_236, color_0_236, lineId4)
lineId6 = processLevel(show_0_382, value_0_382, color_0_382, lineId5)
lineId7 = processLevel(show_0_5, value_0_5, color_0_5, lineId6)
lineId8 = processLevel(show_0_618, value_0_618, color_0_618, lineId7)
lineId9 = processLevel(show_0_65, value_0_65, color_0_65, lineId8)
lineId10 = processLevel(show_0_786, value_0_786, color_0_786, lineId9)
lineId11 = processLevel(show_1, value_1, color_1, lineId10)
lineId12 = processLevel(show_1_272, value_1_272, color_1_272, lineId11)
lineId13 = processLevel(show_1_414, value_1_414, color_1_414, lineId12)
lineId14 = processLevel(show_1_618, value_1_618, color_1_618, lineId13)
lineId15 = processLevel(show_1_65, value_1_65, color_1_65, lineId14)
lineId16 = processLevel(show_2_618, value_2_618, color_2_618, lineId15)
lineId17 = processLevel(show_2_65, value_2_65, color_2_65, lineId16)
lineId18 = processLevel(show_3_618, value_3_618, color_3_618, lineId17)
lineId19 = processLevel(show_3_65, value_3_65, color_3_65, lineId18)
lineId20 = processLevel(show_4_236, value_4_236, color_4_236, lineId19)
lineId21 = processLevel(show_4_618, value_4_618, color_4_618, lineId20)

You might also like