Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 19

// ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄

▄▄▄▄▄▄▄▄▄▄
//▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌ ▐░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌
▐░░░░░░░░░░▌
//▐░█▀▀▀▀▀▀▀▀▀ ▀▀▀▀█░█▀▀▀▀ ▐░▌ ▐░▌ ▐░█▀▀▀▀▀▀▀█░▌ ▀▀▀▀█░█▀▀▀▀
▐░█▀▀▀▀▀▀▀█░▌
//▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌
▐░▌
//▐░█▄▄▄▄▄▄▄▄▄ ▐░▌ ▐░▌ ▐░▌ ▐░█▄▄▄▄▄▄▄█░▌ ▐░▌ ▐░▌
▐░▌
//▐░░░░░░░░░░░▌ ▐░▌ ▐░▌ ▐░▌ ▐░░░░░░░░░░░▌ ▐░▌ ▐░▌
▐░▌
// ▀▀▀▀▀▀▀▀▀█░▌ ▐░▌ ▐░▌ ▐░▌ ▐░█▀▀▀▀▀▀▀▀▀ ▐░▌ ▐░▌
▐░▌
// ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌
▐░▌
// ▄▄▄▄▄▄▄▄▄█░▌ ▄ ▐░▌ ▄ ▐░█▄▄▄▄▄▄▄█░▌ ▄ ▐░▌ ▄ ▄▄▄▄█░█▄▄▄▄ ▄
▐░█▄▄▄▄▄▄▄█░▌▄
//▐░░░░░░░░░░░▌▐░▌ ▐░▌▐░▌ ▐░░░░░░░░░░░▌▐░▌▐░▌▐░▌
▐░░░░░░░░░░░▌▐░▌▐░░░░░░░░░░▌▐░▌
// ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀
▀▀▀▀▀▀▀▀▀▀ ▀
//
// ▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄

//▐░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░▌
▐░▌
//▐░█▀▀▀▀▀▀▀█░▌▀▀▀▀█░█▀▀▀▀ ▀▀▀▀█░█▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌ ▀▀▀▀█░█▀▀▀▀
▐░▌░▌ ▐░▌
//▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌
▐░▌▐░▌ ▐░▌
//▐░█▄▄▄▄▄▄▄█░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌
▐░▌ ▐░▌
//▐░░░░░░░░░░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌
▐░▌ ▐░▌
//▐░█▀▀▀▀▀▀▀█░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌
▐░▌ ▐░▌
//▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌
▐░▌▐░▌
//▐░█▄▄▄▄▄▄▄█░▌▄▄▄▄█░█▄▄▄▄ ▐░▌ ▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄█░▌ ▄▄▄▄█░█▄▄▄▄ ▐░▌
▐░▐░▌
//▐░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌
▐░░▌
// ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀
▀▀

//
// S.UPER T.REND U.LTIMATE P.ROJECT I.NTELLIGENT D.ESIGN
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
at https://mozilla.org/MPL/2.0/
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0
International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// Over 1000 indicator were referenced, credit goes to EACH AND EVERY CREATOR ON
TRADINGVIEW. It is impossible to list everyone. Thus, everyone gets credit.
// Extra Credit to: PVSRA, plasmapug, KIVANC, Quantvue, Lux algo; // orginal
combination of luxalgo Fibonacci Toolkit + Elliott Wave + Trendlines with Breaks:
modified by Stupid_Bitcoin 2024
// The summary of this code is work done by @ Stupid_Bitcoin 2024 and beyond.
// S.T.U.P.I.D. Donations ~ paypal ~ djyourstory@gmail.com
// A Market Maker and Casino are identical. They do not change the game.
// They understand your indicator, or your mind-set will keep changing.
// The Human Brain can not make a security call to the asset, but AI can.
// A majority of popular indicators are old, regardless of ratings.
// Many of these indicators can not upgrade into Version 5 of Pine Script.
// Before indicator design the 13 TEMA, 66 DEMA, created a tested trading
foundation.

// What is S.T.U.P.I.D.? AI reviewed and reported on every trading view indicator


video published to YouTube.
// Next, AI parsed most major YouTube stock/crypto channels into a key-word
language model.
// Human brains analyzed the AI results using Six Sigma.
// Six Sigma is priority based risk management to reduce errors.
// Next, We added Hoffman IRBs', Nikola Tesla Math, Game Theory.
// What is Robert J. Hoffman Award Winning Wick retracement? He can explain it to
you.
// His method merged with PVSRA to increase in profitability.
// PVSRA is a 200% fixed volume trigger with 4 stages of color.
// S.T.U.P.I.D. Vector candles are the result of PVSRA improvement. They use 12
triggers, plus color compression.
// Next, retail traders can not control paraxial errors. They make approximations
to a chart, which produce false signals.
// Removing data sources, like influences producing paraxial errors, increased
winning trade experiences.
// Next, the methodology considers the bad habits of retail traders.
// Next, a Game Theory model emerged. It uses the OODA loop, platonic dice theory,
and blackjack basic strategy.
// Example 1, alter Fibonacci numbers with Tesla values. The result in gaming and
trading, is more winning experiences.
// Example 2, entry/exit on rounded dollar values of 333 or 666, result in more
winning trades than 250/500/750.
// Proper numbers (generally are):
1,3,5,6,9,11,13,18,21,22,24,26,33,36,39,44,48,52,63,66,77,88,96,99,111,144,163,188,
199,222,333,369,396,444,555,639,666,693,777,888,936,963,993,996,999
// Six Sigma reallocates all prior data for development of 100 indicators.
// Each indicator was tested using Bitcoin.
// Development back tested over 3000 variations of code sequencing.
// Development defined edge cases using game theory. Six Sigma again filtered the
indicator data.
// Two-thirds of the indicators built, got eliminated. Out of 100 indicators the
top 33 remain.

// About S.T.U.P.I.D. Vector Candles


// Vector Candles enhance the old PVSRA, using six sigma.
// Price action is the candle. Volume explains how price action happens.
// Support and Resistance are not target points, they are broad areas.
// Color plays a critical role, reducing the number of charts to consult.
// It prevents eye strain, reduces mental mathematics, and presents 1000s of data
points.
// Over 12 stages of buying and selling volume are shown using color, and the
absence of color.
// Vector candle can encode the wick with volume data, based on color.
// Color Compression lookback is used to verify vector candle recovery.
// During recovery or the absence of volume, the color is absent from the candle
body.
// Chart data using vector colors will reflect these same values.
// Vector candles will display trigger volume on multi-stage candle sweeps.
// S.T.U.P.I.D. Disclaimer
// Game Theory proves the psychology of printing winning results will attract
criminals. It IS NOT suggested for indicator design.
// However, at the same time private use of printing winning rates on chart, will
expose that win rates vary by exchange.
// For example, "Exchange A" on every time frame posts better than an 80% win
rate.
// On the same asset and time frames "Exchange B" is 3% to 6% lower win rate, who
might claim to have "lower fees" than Exchange A.
// Private use of AI enhances scam detection and can catch criminals who exploit
the markets.
// However, errors may be present, pine script has limitations, I am not perfect,
everything is random, and each individual uses trading data differently.

// Information contained in (Super Trend Ultimate Project Intelligent Design) or


S.T.U.P.I.D does not constitute financial advice or a solicitation to buy or sell
any securities of any type.
// Open Source code, or its publisher, does not accept liability for any loss or
damage, including without limitation any loss of profit, which may arise directly
or indirectly from the use of
// or reliance on such information. All investments involve risk. Investors are
fully responsible for all decisions they make.
// My open source code is for educational purposes.
// © Stupid_Bitcoin

//@version=5
indicator("Lux Ultra 📈 Fibonacci Tool", overlay=true, max_lines_count=500,
max_labels_count=500, max_boxes_count = 500, max_bars_back=5000)

//----------Daily Look Back Vector Candle Color Compression----------// // DO NOT


EDIT
import TradingView/ta/6
lookback = input.int(3, 'Days for Color Compression Lookback')
extLev = input.int(188, 'Color Compression Extreme', inline = '1')
extCol = input.color(color.rgb(15, 15, 15, 100), '', inline = '1')
highLev = input.int(144, 'Color Compression High', inline = '2')
highCol = input.color(color.rgb(15, 15, 15, 95), '', inline = '2')
avgLev = input.int(88, 'Color Compression Average', inline = '3')
avgCol = input.color(color.rgb(15, 15, 15, 90), '', inline = '3')
lightLev = input.int(44, 'Color Compression Light', inline = '4')
lightCol = input.color(color.rgb(15, 15, 15, 95), '', inline = '4')
dryCol = input.color(color.rgb(15, 15, 15, 100), 'Color Compression Dry')
vlength = 9
avrg = ta.vwma(volume, vlength)
vold0 = volume > avrg * 1.88 and close < open
vold1 = volume > avrg * 1.44 and volume <= avrg * 1.87 and close < open
vold2 = volume > avrg * 1.22 and volume <= avrg * 1.43 and close < open
vold3 = volume >= avrg * 0.90 and volume <= avrg * 1.21 and close < open
vold4 = volume < avrg * 0.60 and volume <= avrg * 0.89 and close < open
vold5 = volume < avrg * 0.30 and close < open

volu0 = volume > avrg * 1.88 and close > open,


volu1 = volume > avrg * 1.44 and volume <= avrg * 1.87 and close > open
volu2 = volume > avrg * 1.44 and volume <= avrg * 1.43 and close > open
volu3 = volume >= avrg * 0.90 and volume <= avrg * 1.21 and close > open
volu4 = volume < avrg * 0.60 and volume <= avrg * 0.89 and close > open
volu5 = volume < avrg * 0.30 and close < open
cold0 = color.rgb(200, 0, 255, 11)
cold1 = color.rgb(180, 0, 255, 22)
cold2 = color.rgb(160, 0, 255, 33)
cold3 = color.rgb(140, 0, 255, 44)
cold4 = color.rgb(120, 0, 255, 55)
cold5 = color.rgb(100, 0, 255, 66)

colu0 = color.rgb(0, 255, 200, 11)


colu1 = color.rgb(0, 225, 160, 22)
colu2 = color.rgb(0, 205, 140, 33)
colu3 = color.rgb(0, 195, 120, 44)
colu4 = color.rgb(0, 185, 100, 55)
colu5 = color.rgb(0, 175, 100, 66)
color_1 = vold0 ? cold0 : vold1 ? cold1 : vold2 ? cold2 : vold3 ? cold3 : vold4 ?
cold4 : vold5 ? cold5 : volu0 ? colu0 : volu1 ? colu1 : volu2 ? colu2 : volu3 ?
colu3 : volu4 ? colu4 : volu5 ? colu5 : na

plotcandle(open, high, low, close, title=' Vector Candle', color=(open < close) ?
color_1 : color_1, wickcolor=color_1, bordercolor=color_1, editable = false)

//----------VCLB data----------//
[currentVolume, pastVolume, ratio] = ta.relativeVolume(lookback, 'D', true)
ratio := math.round(ratio*100,0)
//----------VCLB conditions----------//
ratioCol = ratio >= extLev ? extCol : ratio >= highLev ? highCol : ratio >=
avgLev ? avgCol : ratio >= lightLev ? lightCol : dryCol
ratioWickCol = ratio >= ratio[1] ? colu0 :cold0
//----------VCLB plots----------//
plotcandle(open,high,low,close,color=ratioCol,wickcolor=ratioWickCol,
bordercolor=ratioCol, editable = false)
//

//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
i_hi = input.string('high' , title= '' , group='source
[high - low]', inline='hl', options=['high', 'close', 'max open/close'])
i_lo = input.string('low' , title= '' , group='source
[high - low]', inline='hl', options=['low' , 'close', 'min open/close'])

s1 = input.bool (true , title= '' , group='ZigZag'


, inline= '1' )
len1 = input.int ( 4 , title= ' 1 Length', group='ZigZag'
, inline= '1', minval =1 )
col1 = input.color (color.rgb(255, 208, 0, 75) , title= '' ,
group='ZigZag' , inline= '1'
)
s2 = input.bool (true , title= '' , group='ZigZag'
, inline= '2' )
len2 = input.int ( 8 , title= ' 2 Length', group='ZigZag'
, inline= '2', minval =1 )
col2 = input.color (color.rgb(255, 208, 0, 75) , title= '' ,
group='ZigZag' , inline= '2'
)
s3 = input.bool (true , title= '' , group='ZigZag'
, inline= '3' )
len3 = input.int (16 , title= ' 3 Length', group='ZigZag'
, inline= '3', minval =1 )
col3 = input.color (color.rgb(255, 208, 0, 75) , title= '' ,
group='ZigZag' , inline= '3'
)

i_500 = input.float (0.500 , title=' level 1', group='Fibonacci


values' , minval =0, maxval =1, step =0.01 )
i_618 = input.float (0.618 , title=' level 2', group='Fibonacci
values' , minval =0, maxval =1, step =0.01 )
i_764 = input.float (0.764 , title=' level 3', group='Fibonacci
values' , minval =0, maxval =1, step =0.01 )
i_854 = input.float (0.854 , title=' level 4', group='Fibonacci
values' , minval =0, maxval =1, step =0.01 )

shZZ = input.bool (false , title= '' , group='show ZZ'


, inline='zz' )

//-----------------------------------------------------------------------------}
//User Defined Types
//-----------------------------------------------------------------------------{
type ZZ
int [] d
int [] x
float[] y
line [] l

type Ewave
line l1
line l2
line l3
line l4
line l5
label b1
label b2
label b3
label b4
label b5
//
bool on
bool br //= na
//
int dir
//
line lA
line lB
line lC
label bA
label bB
label bC
//
bool next = false
//
label lb
box bx

type fibL
line wave1_0_500
line wave1_0_618
line wave1_0_764
line wave1_0_854
line wave1_pole_
linefill l_fill_
bool _break_ //= na

//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
hi = i_hi == 'high' ? high : i_hi == 'close' ? close : math.max(open, close)
lo = i_lo == 'low' ? low : i_hi == 'close' ? close : math.min(open, close)

in_out(aZZ, d, x1, y1, x2, y2, col) =>


aZZ.d.unshift(d), aZZ.x.unshift(x2), aZZ.y.unshift(y2), aZZ.d.pop(),
aZZ.x.pop(), aZZ.y.pop()
if shZZ
aZZ.l.unshift(line.new(x1, y1, x2, y2, color= col)), aZZ.l.pop().delete()

method isSame(Ewave gEW, _1x, _2x, _3x, _4x) =>


t1 = _1x == gEW.l1.get_x1()
t2 = _2x == gEW.l2.get_x1()
t3 = _3x == gEW.l3.get_x1()
t4 = _4x == gEW.l4.get_x1()
t1 and t2 and t3 and t4

method isSame2(Ewave gEW, _1x, _2x, _3x) =>


t1 = _1x == gEW.l3.get_x2()
t2 = _2x == gEW.l4.get_x2()
t3 = _3x == gEW.l5.get_x2()
t1 and t2 and t3

method dot(Ewave gEW) =>


gEW.l1.set_style(line.style_dotted)
gEW.l2.set_style(line.style_dotted)
gEW.l3.set_style(line.style_dotted)
gEW.l4.set_style(line.style_dotted)
gEW.l5.set_style(line.style_dotted)
gEW.b1.set_textcolor (color(na))
gEW.b2.set_textcolor (color(na))
gEW.b3.set_textcolor (color(na))
gEW.b4.set_textcolor (color(na))
gEW.b5.set_textcolor (color(na))
gEW.on := false

method dash(Ewave gEW) =>


gEW.lA.set_style(line.style_dashed)
gEW.lB.set_style(line.style_dashed)
gEW.lC.set_style(line.style_dashed)
gEW.bA.set_textcolor (color(na))
gEW.bB.set_textcolor (color(na))
gEW.bC.set_textcolor (color(na))
gEW.bx.set_bgcolor (color(na))
gEW.bx.set_border_color (color(na))

method sol_dot(fibL nFibL, sol_dot, col) =>


style =
sol_dot == 'dot' ?
line.style_dotted :
sol_dot == 'sol' ?
line.style_solid :
line.style_dashed
nFibL.wave1_0_500.set_style(style)
nFibL.wave1_0_618.set_style(style)
nFibL.wave1_0_764.set_style(style)
nFibL.wave1_0_854.set_style(style)
nFibL.l_fill_.set_color(col)

method set(fibL nFibL, int x1, int x2, float max_500, float max_618, float max_764,
float max_854, float y2) =>
nFibL.wave1_0_500.set_xy1(x1, max_500)
nFibL.wave1_0_500.set_xy2(x2, max_500)
nFibL.wave1_0_618.set_xy1(x1, max_618)
nFibL.wave1_0_618.set_xy2(x2, max_618)
nFibL.wave1_0_764.set_xy1(x1, max_764)
nFibL.wave1_0_764.set_xy2(x2, max_764)
nFibL.wave1_0_854.set_xy1(x1, max_854)
nFibL.wave1_0_854.set_xy2(x2, max_854)
nFibL.wave1_pole_.set_xy1(x1, y2 )
nFibL.wave1_pole_.set_xy2(x1, max_854)
nFibL.l_fill_.get_line1().set_xy1(x1, max_764)
nFibL.l_fill_.get_line1().set_xy2(x2, max_764)
nFibL.l_fill_.get_line2().set_xy1(x1, max_854)
nFibL.l_fill_.get_line2().set_xy2(x2, max_854)

method setNa(fibL nFibL) =>


nFibL.wave1_0_500.set_xy1(na, na)
nFibL.wave1_0_500.set_xy2(na, na)
nFibL.wave1_0_618.set_xy1(na, na)
nFibL.wave1_0_618.set_xy2(na, na)
nFibL.wave1_0_764.set_xy1(na, na)
nFibL.wave1_0_764.set_xy2(na, na)
nFibL.wave1_0_854.set_xy1(na, na)
nFibL.wave1_0_854.set_xy2(na, na)
nFibL.wave1_pole_.set_xy1(na, na)
nFibL.wave1_pole_.set_xy2(na, na)
nFibL.l_fill_.set_color(color(na))

draw(enabled, left, col, n) =>


//
max_bars_back(time, 2000)
var int dir = na, var int x1= na, var float y1 = na, var int x2 = na, var float
y2 = na, var Ewave gEW = na
var int last_0x = na , var float last_0y = na , var int last_6x = na
, var float last_6y = na
//
if enabled
var fibL nFibL = fibL.new(
wave1_0_500 = line.new(na, na, na, na, color= color.new(col, 50), style=
line.style_solid ),
wave1_0_618 = line.new(na, na, na, na, color= color.new(col, 38), style=
line.style_solid ),
wave1_0_764 = line.new(na, na, na, na, color= color.new(col, 24), style=
line.style_solid ),
wave1_0_854 = line.new(na, na, na, na, color= color.new(col, 15), style=
line.style_solid ),
wave1_pole_ = line.new(na, na, na, na, color= color.new(col, 50), style=
line.style_dashed),
l_fill_ = linefill.new(
line.new(na, na, na, na, color= color(na))
, line.new(na, na, na, na, color= color(na))
, color= color(na))
, _break_ = na
)
//
var ZZ aZZ = ZZ.new(array.new < int > ()
, array.new < int > ()
, array.new < float > ()
, array.new < line > () )
var Ewave[] aEW = array.new < Ewave > ()
//
if barstate.isfirst
aEW.unshift(Ewave.new())
for i = 0 to 10
aZZ.d.unshift(0)
aZZ.x.unshift(0)
aZZ.y.unshift(0)
aZZ.l.unshift(shZZ ? line.new(na, na, na, na) : na)
//
sz = aZZ.d.size( )
x2 := bar_index -1
ph = ta.pivothigh(hi, left, 1)
pl = ta.pivotlow (lo, left, 1)
t = n == 2 ? '\n\n' : n == 1 ? '\n' : ''
//
// when a new Pivot High is found
if not na(ph)
gEW := aEW.get (0)
dir := aZZ.d.get (0)
x1 := aZZ.x.get (0)
y1 := aZZ.y.get (0)
y2 := nz(hi[1])
//
if dir < 1 // if previous point was a pl, add, and change direction (
1)
in_out(aZZ, 1, x1, y1, x2, y2, col)
else
if dir == 1 and ph > y1
aZZ.x.set(0, x2), aZZ.y.set(0, y2)
if shZZ
aZZ.l.get(0).set_xy2(x2, y2)
//
_6x = x2, _6y = y2
_5x = aZZ.x.get(1), _5y = aZZ.y.get(1)
_4x = aZZ.x.get(2), _4y = aZZ.y.get(2)
_3x = aZZ.x.get(3), _3y = aZZ.y.get(3)
_2x = aZZ.x.get(4), _2y = aZZ.y.get(4)
_1x = aZZ.x.get(5), _1y = aZZ.y.get(5)
//
// –––––––––––––––––––––[ 12345 ]–––––––––––––––––––––
_W5 = _6y - _5y
_W3 = _4y - _3y
_W1 = _2y - _1y
min = math.min(_W1, _W3, _W5)
isWave =
_W3 != min and
_6y > _4y and
_3y > _1y and
_5y > _2y
//
same = gEW.isSame(_1x, _2x, _3x, _4x)
if isWave
if same
gEW.l5.set_xy2(_6x, _6y)
gEW.b5.set_xy (_6x, _6y)
else
tx = ''
if _2x == aEW.get(0).b5.get_x()
tx := '(5) (1)'
aEW.get(0).b5.set_text('')
else
tx := '(1)'
//
wave = Ewave.new(
l1 = line.new (_1x, _1y, _2x, _2y ,
color=col , style= line.style_solid ),
l2 = line.new (_2x, _2y, _3x, _3y ,
color=col , style= line.style_solid ),
l3 = line.new (_3x, _3y, _4x, _4y ,
color=col , style= line.style_solid ),
l4 = line.new (_4x, _4y, _5x, _5y ,
color=col , style= line.style_solid ),
l5 = line.new (_5x, _5y, _6x, _6y ,
color=col , style= line.style_solid ),
b1 = label.new(_2x, _2y, text= tx + t, textcolor=col,
color= color(na), style=label.style_label_down),
b2 = label.new(_3x, _3y, text= t + '(2)', textcolor=col,
color= color(na), style=label.style_label_up ),
b3 = label.new(_4x, _4y, text= '(3)' + t, textcolor=col,
color= color(na), style=label.style_label_down),
b4 = label.new(_5x, _5y, text= t + '(4)', textcolor=col,
color= color(na), style=label.style_label_up ),
b5 = label.new(_6x, _6y, text= '(5)' + t, textcolor=col,
color= color(na), style=label.style_label_down),
on = true
,
br = false
,
dir = 1
)
aEW.unshift(wave)
nFibL._break_ := false
alert('New EW Motive Bullish Pattern found' ,
alert.freq_once_per_bar_close)
//
if not isWave
if same and gEW.on == true
gEW.dot()
alert('Invalidated EW Motive Bullish Pattern',
alert.freq_once_per_bar_close)
//
// –––––––––––––––––––––[ ABC ]–––––––––––––––––––––
getEW = aEW.get(0)
last_0x := getEW.l1.get_x1(), last_0y := getEW.l1.get_y1()
last_6x := getEW.l5.get_x2(), last_6y := getEW.l5.get_y2()
diff = math.abs(last_6y - last_0y)
//
if getEW.dir == -1
getX = getEW.l5.get_x2()
getY = getEW.l5.get_y2()
isSame2 = getEW.isSame2 (_1x, _2x, _3x)
isValid =
_3x == getX and
_6y < getY + (diff * i_854) and
_4y < getY + (diff * i_854) and
_5y > getY
//
if isValid
width = _6x - _2x // –––[ width (4) - (c) ]–––
if isSame2 and getEW.bA.get_x() > _3x
getEW.lC.set_xy1(_5x, _5y), getEW.lC.set_xy2(_6x, _6y),
getEW.bC.set_xy(_6x, _6y), getEW.bx.set_lefttop(_6x, _6y), getEW.bx.set_right(_6x +
width)
else
getEW.lA := line.new (_3x, _3y, _4x, _4y, color=col),
getEW.bA := label.new(_4x, _4y, text= '(a)' + t, textcolor=col, color= color(na),
style=label.style_label_down)
getEW.lB := line.new (_4x, _4y, _5x, _5y, color=col),
getEW.bB := label.new(_5x, _5y, text= t + '(b)', textcolor=col, color= color(na),
style=label.style_label_up )
getEW.lC := line.new (_5x, _5y, _6x, _6y, color=col),
getEW.bC := label.new(_6x, _6y, text= '(c)' + t, textcolor=col, color= color(na),
style=label.style_label_down)
getEW.bx := box.new (_6x, _6y, _6x + width, _4y,
bgcolor=color.new(col, 93), border_color=color.new(col, 65))
alert('New EW Corrective Bullish Pattern found' ,
alert.freq_once_per_bar_close)
else
if isSame2 and getEW.bA.get_x() > _3x
getEW.dash()
alert('Invalidated EW Corrective Bullish Pattern',
alert.freq_once_per_bar_close)
//
// –––––––––––––––––––––[ new (1) ? ]–––––––––––––––––––––
if getEW.dir == 1
if _5x == getEW.bC.get_x() and
_6y > getEW.b5.get_y() and
getEW.next == false
getEW.next := true
getEW.lb := label.new(_6x, _6y, style=label.style_circle,
color=color.new(col, 65), yloc=yloc.abovebar, size=size.tiny)
alert('Possible new start of EW Motive Bullish Wave',
alert.freq_once_per_bar_close)
//
// when a new Pivot Low is found
if not na(pl)
gEW := aEW.get (0)
dir := aZZ.d.get (0)
x1 := aZZ.x.get (0)
y1 := aZZ.y.get (0)
y2 := nz(lo[1])
//
if dir > -1 // if previous point was a ph, add, and change direction
(-1)
in_out(aZZ, -1, x1, y1, x2, y2, col)
else
if dir == -1 and pl < y1
aZZ.x.set(0, x2), aZZ.y.set(0, y2)
if shZZ
aZZ.l.get(0).set_xy2(x2, y2)
//
_6x = x2, _6y = y2
_5x = aZZ.x.get(1), _5y = aZZ.y.get(1)
_4x = aZZ.x.get(2), _4y = aZZ.y.get(2)
_3x = aZZ.x.get(3), _3y = aZZ.y.get(3)
_2x = aZZ.x.get(4), _2y = aZZ.y.get(4)
_1x = aZZ.x.get(5), _1y = aZZ.y.get(5)
//
// –––––––––––––––––––––[ 12345 ]–––––––––––––––––––––
_W5 = _5y - _6y
_W3 = _3y - _4y
_W1 = _1y - _2y
min = math.min(_W1, _W3, _W5)
isWave =
_W3 != min and
_4y > _6y and
_1y > _3y and
_2y > _5y
//
same = isSame(gEW, _1x, _2x, _3x, _4x)
if isWave
if same
gEW.l5.set_xy2(_6x, _6y)
gEW.b5.set_xy (_6x, _6y)
else
tx = ''
if _2x == aEW.get(0).b5.get_x()
tx := '(5) (1)'
aEW.get(0).b5.set_text('')
else
tx := '(1)'
//
wave = Ewave.new(
l1 = line.new (_1x, _1y, _2x, _2y ,
color=col , style= line.style_solid ),
l2 = line.new (_2x, _2y, _3x, _3y ,
color=col , style= line.style_solid ),
l3 = line.new (_3x, _3y, _4x, _4y ,
color=col , style= line.style_solid ),
l4 = line.new (_4x, _4y, _5x, _5y ,
color=col , style= line.style_solid ),
l5 = line.new (_5x, _5y, _6x, _6y ,
color=col , style= line.style_solid ),
b1 = label.new(_2x, _2y, text= t + tx, textcolor=col,
color= color(na), style=label.style_label_up ),
b2 = label.new(_3x, _3y, text= '(2)' + t, textcolor=col,
color= color(na), style=label.style_label_down),
b3 = label.new(_4x, _4y, text= t + '(3)', textcolor=col,
color= color(na), style=label.style_label_up ),
b4 = label.new(_5x, _5y, text= '(4)' + t, textcolor=col,
color= color(na), style=label.style_label_down),
b5 = label.new(_6x, _6y, text= t + '(5)', textcolor=col,
color= color(na), style=label.style_label_up ),
on = true
,
br = false
,
dir =-1
)
aEW.unshift(wave)
nFibL._break_ := false
alert('New EW Motive Bearish Pattern found' ,
alert.freq_once_per_bar_close)
//
if not isWave
if same and gEW.on == true
gEW.dot()
alert('Invalidated EW Motive Bearish Pattern',
alert.freq_once_per_bar_close)
//
// –––––––––––––––––––––[ ABC ]–––––––––––––––––––––
getEW = aEW.get(0)
last_0x := getEW.l1.get_x1(), last_0y := getEW.l1.get_y1()
last_6x := getEW.l5.get_x2(), last_6y := getEW.l5.get_y2()
diff = math.abs(last_6y - last_0y)
//
if getEW.dir == 1
getX = getEW.l5.get_x2()
getY = getEW.l5.get_y2()
isSame2 = getEW.isSame2 (_1x, _2x, _3x)
isValid =
_3x == getX and
_6y > getY - (diff * i_854) and
_4y > getY - (diff * i_854) and
_5y < getY
//
if isValid
width = _6x - _2x // –––[ width (4) - (c) ]–––
if isSame2 and getEW.bA.get_x() > _3x
getEW.lC.set_xy1(_5x, _5y), getEW.lC.set_xy2(_6x, _6y),
getEW.bC.set_xy(_6x, _6y), getEW.bx.set_lefttop(_6x, _6y), getEW.bx.set_right(_6x +
width)
else
getEW.lA := line.new (_3x, _3y, _4x, _4y, color=col),
getEW.bA := label.new(_4x, _4y, text= t + '(a)', textcolor=col, color= color(na),
style=label.style_label_up )
getEW.lB := line.new (_4x, _4y, _5x, _5y, color=col),
getEW.bB := label.new(_5x, _5y, text= '(b)' + t, textcolor=col, color= color(na),
style=label.style_label_down)
getEW.lC := line.new (_5x, _5y, _6x, _6y, color=col),
getEW.bC := label.new(_6x, _6y, text= t + '(c)', textcolor=col, color= color(na),
style=label.style_label_up )
getEW.bx := box.new (_6x, _6y, _6x + width, _4y,
bgcolor=color.new(col, 93), border_color=color.new(col, 65))
alert('New EW Corrective Bearish Pattern found' ,
alert.freq_once_per_bar_close)
else
if isSame2 and getEW.bA.get_x() > _3x
getEW.dash()
alert('Invalidated EW Corrective Bullish Pattern',
alert.freq_once_per_bar_close)
//
// –––[ check (only once) for a possible new (1) after an impulsive AND
corrective wave ]–––
if getEW.dir == -1
if _5x == getEW.bC.get_x() and
_6y < getEW.b5.get_y() and
getEW.next == false
getEW.next := true
getEW.lb := label.new(_6x, _6y, style=label.style_circle,
color=color.new(col, 65), yloc=yloc.belowbar, size=size.tiny)
alert('Possible new start of EW Motive Bearish Wave',
alert.freq_once_per_bar_close)

//
if barstate.islast
// –––[ get last 2 EW's ]–––
getEW = aEW.get(0)
if aEW.size() > 1
getEW1 = aEW.get(1)
last_0x := getEW.l1.get_x1(), last_0y := getEW.l1.get_y1()
last_6x := getEW.l5.get_x2(), last_6y := getEW.l5.get_y2()
//
diff = math.abs(last_6y - last_0y) // –––[ max/min difference ]–––
_500 = diff * i_500
_618 = diff * i_618
_764 = diff * i_764
_854 = diff * i_854
bull = getEW.dir == 1
// –––[ if EW is not valid or an ABC has developed -> remove
fibonacci lines ]–––
if getEW.on == false or getEW.bC.get_x() > getEW.b5.get_x()
nFibL.setNa()
else
// –––[ get.on == true ~ valid EW ]–––
max_500 = last_6y + ((bull ? -1 : 1) * _500)
max_618 = last_6y + ((bull ? -1 : 1) * _618)
max_764 = last_6y + ((bull ? -1 : 1) * _764)
max_854 = last_6y + ((bull ? -1 : 1) * _854)
//
nFibL.set(last_6x, bar_index + 10, max_500, max_618, max_764,
max_854, last_6y)
// –––[ if (2) label overlap with (C) label ]–––
if getEW.b2.get_x() == getEW1.bC.get_x()
getEW.b1.set_textcolor(color(na))
getEW.b2.set_textcolor(color(na))
strB = getEW1.bB.get_text()
strC = getEW1.bC.get_text()
strB_ = str.replace(strB, "(b)", "(b) (1)", 0)
strC_ = str.replace(strC, "(c)", "(c) (2)", 0)
getEW1.bB.set_text(strB_)
getEW1.bC.set_text(strC_)
//
// –––[ check if fib limits are broken ]–––
getP_854 = nFibL.wave1_0_854.get_y1()
for i = 0 to bar_index - nFibL.wave1_0_854.get_x1()
if getEW.dir == -1
if high[i] > getP_854
nFibL._break_ := true
break
else
if low [i] < getP_854
nFibL._break_ := true
break
//–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
–––––––––––
switch nFibL._break_
true => nFibL.sol_dot('dot', color.new(color.red , 95))
false => nFibL.sol_dot('sol', color.new(color.lime, 95))
=>
nFibL.wave1_0_500.set_xy1(na, na)
nFibL.wave1_0_500.set_xy2(na, na)
nFibL.wave1_0_618.set_xy1(na, na)
nFibL.wave1_0_618.set_xy2(na, na)
nFibL.wave1_0_764.set_xy1(na, na)
nFibL.wave1_0_764.set_xy2(na, na)
nFibL.wave1_0_854.set_xy1(na, na)
nFibL.wave1_0_854.set_xy2(na, na)
nFibL.wave1_pole_.set_xy1(na, na)
nFibL.wave1_pole_.set_xy2(na, na)
nFibL.l_fill_.set_color(color(na))

if aEW.size() > 15
pop = aEW.pop()
pop.l1.delete(), pop.b1.delete()
pop.l2.delete(), pop.b2.delete()
pop.l3.delete(), pop.b3.delete()
pop.l4.delete(), pop.b4.delete()
pop.l5.delete(), pop.b5.delete()
pop.lA.delete(), pop.bA.delete()
pop.lB.delete(), pop.bB.delete()
pop.lC.delete(), pop.bC.delete()
pop.lb.delete(), pop.bx.delete()
//----------------------------------

//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
draw(s1, len1, col1, 0)
draw(s2, len2, col2, 1)
draw(s3, len3, col3, 2)

//-----------------------------------------------------------------------------}
//Settings
//-----------------------------------------------------------------------------{
length = input.int(13, 'Swing Detection Lookback')
mult = input.float(1., 'Slope', minval = 0, step = .1)
calcMethod = input.string('Atr', 'Slope Calculation Method', options =
['Atr','Stdev','Linreg'])
backpaint = input(true, tooltip = 'Backpainting offset displayed elements in the
past. Disable backpainting to see real time information returned by the
indicator.')

//Style
upCss = input.color(color.rgb(110, 44, 176, 70), 'Up Trendline Color', group =
'Style')
dnCss = input.color(color.rgb(41, 153, 142, 70), 'Down Trendline Color', group =
'Style')
showExt = input(true, 'Show Extended Lines')

//-----------------------------------------------------------------------------}
//Calculations
//-----------------------------------------------------------------------------{
var upper = 0.
var lower = 0.
var slope_ph = 0.
var slope_pl = 0.

var offset = backpaint ? length : 0

n = bar_index
src = close

ph = ta.pivothigh(length, length)
pl = ta.pivotlow(length, length)

//Slope Calculation Method


slope = switch calcMethod
'Atr' => ta.atr(length) / length * mult
'Stdev' => ta.stdev(src,length) / length * mult
'Linreg' => math.abs(ta.sma(src * n, length) - ta.sma(src, length) * ta.sma(n,
length)) / ta.variance(n, length) / 2 * mult

//Get slopes and calculate trendlines


slope_ph := ph ? slope : slope_ph
slope_pl := pl ? slope : slope_pl

upper := ph ? ph : upper - slope_ph


lower := pl ? pl : lower + slope_pl

var upos = 0
var dnos = 0
upos := ph ? 0 : close > upper - slope_ph * length ? 1 : upos
dnos := pl ? 0 : close < lower + slope_pl * length ? 1 : dnos

//-----------------------------------------------------------------------------}
//Extended Lines
//-----------------------------------------------------------------------------{
var uptl = line.new(na,na,na,na, color = upCss, style = line.style_dashed, extend
= extend.right)
var dntl = line.new(na,na,na,na, color = dnCss, style = line.style_dashed, extend
= extend.right)

if ph and showExt
uptl.set_xy1(n-offset, backpaint ? ph : upper - slope_ph * length)
uptl.set_xy2(n-offset+1, backpaint ? ph - slope : upper - slope_ph *
(length+1))

if pl and showExt
dntl.set_xy1(n-offset, backpaint ? pl : lower + slope_pl * length)
dntl.set_xy2(n-offset+1, backpaint ? pl + slope : lower + slope_pl *
(length+1))

//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
plot(backpaint ? upper : upper - slope_ph * length, 'Upper', color = ph ? na :
upCss, offset = -offset)
plot(backpaint ? lower : lower + slope_pl * length, 'Lower', color = pl ? na :
dnCss, offset = -offset)

//Breakouts
plotshape(upos > upos[1] ? low : na, "Upper Break"
, shape.labelup
, location.absolute
, upCss
, text = "B"
, textcolor = color.rgb(41, 153, 142, 50)
, size = size.tiny)

plotshape(dnos > dnos[1] ? high : na, "Lower Break"


, shape.labeldown
, location.absolute
, dnCss
, text = "B"
, textcolor = color.rgb(110, 44, 176, 50)
, size = size.tiny)

//-----------------------------------------------------------------------------}
//Alerts
//-----------------------------------------------------------------------------{
alertcondition(upos > upos[1], 'Upward Breakout', 'Price broke the down-trendline
upward')
alertcondition(dnos > dnos[1], 'Downward Breakout', 'Price broke the up-trendline
downward')

//-----------------------------------------------------------------------------}

//

// Fibonacci Toolkit
mode =
input.string('Retracements','Fibonacci',options=['Retracements','Arcs','Circles','F
an','Timezone','Spiral'])
ext = input(false,'Extend Reatracements')
start = input.time(0,'Start',confirm=true)
end = input.time(0,'End',confirm=true)
src3 = input(hlc3)
//----
fib_a = input(true,'Fib A',inline='inline1',group='Fibonacci')
fib_a_lvl = input(0.236,'',inline='inline1',group='Fibonacci')
fib_a_col = input(color.rgb(255, 0, 0, 50),'',inline='inline1',group='Fibonacci')

fib_b = input(true,'Fib B',inline='inline2',group='Fibonacci')


fib_b_lvl = input(0.382,'',inline='inline2',group='Fibonacci')
fib_b_col = input(color.rgb(255, 99, 1, 50),'',inline='inline2',group='Fibonacci')

fib_c = input(true,'Fib C',inline='inline3',group='Fibonacci')


fib_c_lvl = input(0.5,'',inline='inline3',group='Fibonacci')
fib_c_col = input(color.rgb(170, 255, 0, 50),'',inline='inline3',group='Fibonacci')

fib_d = input(true,'Fib D',inline='inline4',group='Fibonacci')


fib_d_lvl = input(0.618,'',inline='inline4',group='Fibonacci')
fib_d_col = input(color.rgb(0, 213, 255, 50),'',inline='inline4',group='Fibonacci')

fib_e = input(true,'Fib E',inline='inline5',group='Fibonacci')


fib_e_lvl = input(0.786,'',inline='inline5',group='Fibonacci')
fib_e_col = input(color.rgb(202, 1, 252, 50),'',inline='inline5',group='Fibonacci')

fib_f = input(true,'Fib F',inline='inline6',group='Fibonacci')


fib_f_lvl = input(1.,'',inline='inline6',group='Fibonacci')
fib_f_col = input(color.rgb(255, 0, 85, 50),'',inline='inline6',group='Fibonacci')

connecting_line = input(true,'Line',inline='inline7',group='Fibonacci')
line_col = input(color.rgb(120, 123, 134),'',inline='inline7',group='Fibonacci')
//----
var fib = array.new_float(0)
var fib_col = array.new_color(0)
if barstate.isfirst
if fib_a
array.push(fib,fib_a_lvl)
array.push(fib_col,fib_a_col)
if fib_b
array.push(fib,fib_b_lvl)
array.push(fib_col,fib_b_col)
if fib_c
array.push(fib,fib_c_lvl)
array.push(fib_col,fib_c_col)
if fib_d
array.push(fib,fib_d_lvl)
array.push(fib_col,fib_d_col)
if fib_e
array.push(fib,fib_e_lvl)
array.push(fib_col,fib_e_col)
if fib_f
array.push(fib,fib_f_lvl)
array.push(fib_col,fib_f_col)
//----
n3 = bar_index
dt = time-time[1]

start_n = ta.valuewhen(time == start,n,0)


end_n = ta.valuewhen(time == end,n,0)

start_y = ta.valuewhen(time == start,src3,0)


end_y = ta.valuewhen(time == end,src3,0)

diff_n = end_n - start_n


diff_y = start_y - end_y
//----
if n3 == math.max(start_n,end_n)
a = 0
b = 1
sum = 0

s2 = math.sqrt(2)

if connecting_line
line.new(start_n,start_y,end_n,end_y,color=line_col)

if mode == 'Spiral'
int prev_x = na
float prev_y = na
for i = 0 to 499
t = i/499*7*math.pi
k = math.log(math.phi)/(math.pi/2)
r = (math.exp(t*k) - 1)/math.exp(5*math.pi*k)
x = r*math.cos(t)*diff_n
y = end_y + r*math.sin(t)*(start_y - end_y)*math.sign(end - start)
line.new(prev_x,prev_y,end-
math.round(x)*dt,y,xloc=xloc.bar_time,color=#ff5d00)

prev_x := end-math.round(x)*dt
prev_y := y
else
for i = 0 to array.size(fib)-1
if mode == 'Retracements'
lvl = end_y + array.get(fib,i)*diff_y
line.new(start_n,lvl,end_n,lvl,color=array.get(fib_col,i))

if ext
start_ext = math.max(start_n,end_n)

line.new(start_ext,lvl,start_ext+1,lvl,color=array.get(fib_col,i),extend=extend.rig
ht,style=line.style_dashed)

sty = label.style_label_right

label.new(math.min(start_n,end_n),lvl,str.tostring(array.get(fib,i)),color=#0000000
0,

style=sty,textcolor=array.get(fib_col,i),textalign=text.align_center,size=size.smal
l)

if mode == 'Arcs'
int prev_x = na
float prev_y = na
for j = -90 to 90 by 5
x = end_n +
diff_n*s2*array.get(fib,i)*math.sin(math.toradians(j))
y = end_y +
math.cos(math.toradians(j))*(diff_y*array.get(fib,i)*s2)

line.new(prev_x,prev_y,math.round(x),y,color=array.get(fib_col,i))

prev_x := math.round(x)
prev_y := y

label.new(prev_x,end_y,str.tostring(array.get(fib,i)),color=#00000000,

style=label.style_label_up,textcolor=array.get(fib_col,i),textalign=text.align_cent
er,size=size.small)

if mode == 'Circles'
int prev_x = na
float prev_y = na
for j = 0 to 360 by 5
x = end_n +
diff_n*s2*array.get(fib,i)*math.sin(math.toradians(j))
y = end_y +
math.cos(math.toradians(j))*(diff_y*array.get(fib,i)*s2)

line.new(prev_x,prev_y,math.round(x),y,color=array.get(fib_col,i))

prev_x := math.round(x)
prev_y := y

sty = end_n > start_n ? label.style_label_left :


label.style_label_right

x = diff_n*s2*array.get(fib,i)*math.sin(math.toradians(90))

label.new(end_n+math.round(x),end_y,str.tostring(array.get(fib,i)),color=#00000000,

style=sty,textcolor=array.get(fib_col,i),textalign=text.align_right,size=size.small
)

if mode == 'Fan'
int prev_x = na
float prev_y = na
get_fib = array.get(fib,i)

extend = start_n < end_n ? extend.right : extend.left


line.new(start_n,start_y,math.round(get_fib*start_n+(1-
get_fib)*end_n),end_y,
color=array.get(fib_col,i),extend=extend)
line.new(start_n,start_y,end_n,math.round(get_fib*start_y+(1-
get_fib)*end_y),
color=array.get(fib_col,i),extend=extend)

if mode == 'Timezone'
line.new(start + (end-start)*sum,high,start + (end-
start)*sum,low,xloc.bar_time,extend=extend.both,color=array.get(fib_col,i))
sum := a + b
a := b
b := sum
//
//

You might also like