top of page

Free indicators

Public·5 members

Peak Trough Analysis - mcdon030 released years ago

#################################### Peak_ Trough_analysis_Mcdon030_V3 10/12/2019 ######################################

### Resources:

## 1). interpretation of "Scientific Guide to Price Action and Pattern Trading" Author: Young Ho Seo

## 2). https://www.mql5.com/en/articles/1470

## 3). Semafor_3Level_ZZ

### TOS Script resources:

## 1). initial pivot from Mobius Pivot Array

## 2). folds from Dmonkey Examples && JQ's one note

## 3). Mobius Trend Pivots shared 2/4/2019

## 4). ZZtop JQ onenote Author unidentified

## 5). #StudyName: Dilbert_1st2nd3rdOrderPivotFibs_V4

## script guide:

## 1). Inputs:

## a. first logic cycles pivots to ZZ:

## b. HHLL script cycles higher highs until a lower low occurs and vice versa

## c. show 1rst,2nd and 3rd bubble show Double bottom, Double Top, Resistance, support and rocketRSI color

## d. countbetween counts pivots between higher pivots

## 2). fib relationships with higher to lower pivots

## 3). : lines 389-374

## a. fib projection initiates when 3rd order pivot equals 2nd order pivot

## b. projection order input is similiar to harmonic XABCD trading

## - twothree equals BC trend with fib levels CD

## - threefour equals AB trend with fib levels BC

## - fourfive equals XA trend with fib levels AB

## 4). support and resistance l lines 389-374

## 5). expand chart atleast 100 bars for projections

### issues and needed additions:

## a). needs trendlines from previous pivots

## b). i have a condensed version of a patternfinder(trangles, doubletops, doublebottoms, head and shoulders, wedge,etc) which paints required trendlines if needed, request..

## 5). updates

## a). logic correction works on any pivot or fractal

## b). choose which pivots or fractals to use- Scripts used: Mobius,mobius_fractal_boxes, BillWilliams : Mike Lapping, Robert Payne peak and valley,nube, mcdon030 and TSforum

## c). added previous support and resistance lines with projections

input n = 4;

input tol = .04; ## ratio tolerance

input trendmult = 1.618;

input show1rstzz = yes;

input show2ndzz = yes;

input show3rdzz = yes;

input show1rstbubble =no;

input show2ndbubble = yes;

input show3rdbubble =yes;

input showFibpivotbubble = no;

input showFibrelationbubble = no;

input showprojection = no;

input showHHLLcount = no;

input countbetween = no;

def bn = BarNumber();

def lbar = HighestAll( if IsNaN(close) then bn else 0);

script fib {

input v1 = 0;

input v2 = 0;

input v3 = 0;

input tol = 0;

def ratio = Round((AbsValue(v1 - v2) / AbsValue(v2 - v3)), 2);

## Standard numbers: 0-0.146-0.236-0.382-0.5-0.618-0.764-0.854-1.0-1.236-1.618-2.618-4. 236-6.854

### Pesavento numbers: 0-0.382-0.5-0.618-0.707-0.786-0.854-0.886-1.0-1.128-1.272-1. 414-1.618-2.0-2.414-2. 618-4.0

### Bryce gilmore: 0.25 - 0.382 - 0.5 - 0.618 - 0.667 - 0.786 - 1.0 - 1.272 - 1.618 - 1.732 - 1.75 - 2.0 - 2.236 - 2.5 - 2.618 - 3.0 - 3.33 - 4.236 - 6.854

def retrace = Between(ratio, (0.146 - tol), (0.146 + tol)) or Between(ratio, (.236 - tol), (.236 + tol)) or Between(ratio, (.382 - tol), (.382 + tol)) or

Between(ratio, (.50 - tol), (.50 + tol)) or Between(ratio, (.618 - tol), (.618 + tol)) or Between(ratio, (.667 - tol), (.667 + tol)) or Between(ratio, (.707 - tol), (.707 + tol)) or

Between(ratio, (.764 - tol), (.764 + tol)) or Between(ratio, (.786 - tol), (.786 + tol)) or Between(ratio, (.854 - tol), (.854 + tol)) or Between(ratio, (.886 - tol), (.886 + tol)) or

Between(ratio, (1 - tol), (1 + tol)) or Between(ratio, (1.236 - tol), (1.236 + tol)) or Between(ratio, (1.41 - tol), (1.414 + tol)) or Between(ratio, (1.618 - tol), (1.618 + tol)) or

Between(ratio, (1.732 - tol), (1.732 + tol)) or Between(ratio, (1.75 - tol), (1.75 + tol)) or Between(ratio, (2.00 - tol), (2.000 + tol)) or Between(ratio, (2.236 - tol), (2.236 + tol)) or

Between(ratio, (2.414 - tol), (2.414 + tol)) or Between(ratio, (2.50 - tol), (2.50 + tol)) or Between(ratio, (2.618 - tol), (2.618 + tol)) or Between(ratio, (3 - tol), (3 + tol)) or

Between(ratio, (3.33 - tol), (3.33 + tol)) or Between(ratio, (4 - tol), (4 + tol)) or Between(ratio, (4.236 - tol), (4.236 + tol)) or Between(ratio, (6.85 - tol), (6.85 + tol));

plot one = if IsNaN(0) then 0 else retrace ;

def getratio = if one then ratio else Double.NaN;

}

#### plot highest high trend until low trend and vice versa

script HHLL {

input pivotl = 0.0;

input pivoth = 0.0;

def bn = BarNumber();

def lbar = HighestAll(if IsNaN(close) then 0 else bn);

def pivothv = if pivoth then high else pivothv[1];

def pivotlv = if pivotl then low else pivotlv[1];

def maxl = if pivotl && pivotlv < pivotlv[1] then maxl[1] + 1 else if pivotl && pivotlv > pivotlv[1] then 0 else maxl[1];

def maxh = if pivoth && pivothv > pivothv[1] then maxh[1] + 1 else if pivoth && pivothv < pivothv[1] then 0 else maxh[1];

def maxhseta = if maxh && pivoth then high else Double.NaN;

def maxlseta = if maxl && pivotl then low else Double.NaN;

def maxhsetb = if IsNaN(maxhseta) then 0 else maxhseta;

def maxlsetb = if IsNaN( maxlseta ) then 0 else maxlseta ;

def maxl2 = CompoundValue(1, if maxhsetb or bn == 1 then 0 else if maxlsetb then maxl2[1] + 1 else maxl2[1], 0);

def maxh2 = CompoundValue(1, if maxlsetb or bn == 1 then 0 else if maxhsetb then maxh2[1] + 1 else maxh2[1], 0);

def maxl_ = if maxlsetb && maxl2 then 1 else Double.NaN;

def maxh_ = if maxhsetb && maxh2 then 1 else Double.NaN;

def maxhreset = if IsNaN(maxh_) then 0 else maxh ;

def maxlreset = if IsNaN(maxl_) then 0 else maxl ;

def maxlf = fold dig = 1 to lbar with dag = Double.NaN while IsNaN(dag) do if GetValue(maxlreset, -dig) then dig else Double.NaN;

def maxhf = fold die = 1 to lbar with dae = Double.NaN while IsNaN(dae) do if GetValue(maxhreset, -die) then die else Double.NaN;

def maxlbn = CompoundValue(1, if maxlreset then bn else maxlbn[1], bn);

def maxhbn = CompoundValue(1, if maxhreset then bn else maxhbn[1], bn);

def maxbbb = HighestAll(Max(HighestAll(maxlbn), HighestAll( maxhbn)));

def stopmaxx = bn == maxbbb;

def maxhresetv = if maxhreset then high else maxhresetv [1] ;

def maxlresetv = if maxlreset then low else maxlresetv [1] ;

def maxloffset = if maxhreset[1] then low else if low < maxloffset[1] && maxl2 > maxl2[1] then low else if maxhreset then Double.NaN else if low <= maxloffset[1] && maxl2 > maxl2[1] then low else maxloffset[1] ;

def maxhoffset = if maxlreset[1] then high else if high > maxhoffset[1] && maxh2 > maxh2[1] then high else if maxlreset then Double.NaN else if high >= maxhoffset[1] && maxh2 > maxh2[1] then high else maxhoffset[1];

def maxloffsetloc = if !maxhreset && maxlreset && maxlresetv <= GetValue(maxloffset[1], -maxhf) && Max(maxl2, 1) then 1 else Double.NaN;

def maxhoffsetloc = if !maxlreset && maxhreset && maxhresetv >= GetValue(maxhoffset[1], -maxlf) && Max(maxh2, 1) then 1 else Double.NaN;

def maxlta = if IsNaN(close) then 0 else !IsNaN(maxloffsetloc) or (maxl && stopmaxx && HighestAll(maxlbn) == maxbbb);

def maxhta = if IsNaN(close) then 0 else !IsNaN(maxhoffsetloc) or (maxh && stopmaxx&& HighestAll(maxhbn) == maxbbb);

def maxlt3 = if IsNaN(close) then 0 else !IsNaN(maxloffsetloc);

def maxht3 = if IsNaN(close) then 0 else !IsNaN(maxhoffsetloc);

def maxltb = if IsNaN(maxlta) then 0 else (maxlta) ;

def maxhtb = if IsNaN(maxhta) then 0 else (maxhta) ;

plot maxhtc = if IsNaN(maxhtb) then 0 else ( maxhtb) ;

plot maxltc = if IsNaN(maxhtb ) then 0 else (maxltb);

}

############## mobius

def hh = fold i = 1 to n with p = 1 while p do high > GetValue(high, -i);

def PivotHm = if (bn > n and high == Highest(high, n) and hh) then high else Double.NaN;

def ll = fold jk = 1 to n with q = 1 while q do low < GetValue(low, -jk);

def PivotLm = if (bn > n and low == Lowest(low, n) and ll) then low else Double.NaN;

## mobius fractal boxes

def sequenceCount = n;

def maxSideLength = sequenceCount + 10;

def upRightSide = fold i1 = 1 to maxSideLength + 1 with count1 while count1 != sequenceCount and count1 != -1 do

if GetValue(high, -i1, -maxSideLength) > high or (GetValue(high, -i1, -maxSideLength) == high and count1 == 0) then -1

else if GetValue(high, -i1, -maxSideLength) < high then count1 + 1 else count1;

def upLeftSide = fold i2 = 1 to maxSideLength + 1 with count2 while count2 != sequenceCount and count2 != -1 do

if GetValue(high, i2, maxSideLength) > high or (GetValue(high, i2, maxSideLength) == high and count2 >= 1) then -1

else if GetValue(high, i2, maxSideLength) < high then count2 + 1 else count2;

def downRightSide = fold i3 = 1 to maxSideLength + 1 with count3 while count3 != sequenceCount and count3 != -1 do

if GetValue(low, -i3, -maxSideLength) < low or (GetValue(low, -i3, -maxSideLength) == low and count3 == 0) then -1

else if GetValue(high, -i3, -maxSideLength) > low then count3 + 1 else count3;

def downLeftSide = fold i4 = 1 to maxSideLength + 1 with count4 while count4 != sequenceCount and count4 != -1 do

if GetValue(low, i4, maxSideLength) < low or (GetValue(low, i4, maxSideLength) == low and count4 >= 1) then -1

else if GetValue(low, i4, maxSideLength) > low then count4 + 1 else count4;

def UpFractalts = if upRightSide == sequenceCount and upLeftSide == sequenceCount then high else Double.NaN;

def DownFractalts = if downRightSide == sequenceCount and downLeftSide == sequenceCount then low else Double.NaN;

# Bill Williams fractal indicator

# written by Mike Lapping

def isupfractal;

def isdownfractal;

rec hicount = If (high == high[1], hicount[1] + 1, 0);

rec hivalid = If ((hicount[1] == 0 and hicount == 1 and high > high[2] and high > high[3]) or (hicount[1] and hicount and hivalid[1] )

or (hicount[2] and hivalid[2] and high == high[2] and high > high[1]), 1, 0) ;

rec locount = If (low == low[1], locount[1] + 1, 0);

rec lovalid = If ((locount[1] == 0 and locount == 1 and low < low[2] and low < low[3])

or (locount[1] and locount and lovalid[1] )

or (locount[2] and lovalid[2] and low == low[2] and low < low[1]), 1, 0) ;

isupfractal = If(((hicount and hivalid) or (high > high[1] and high > high[2])) and high > high[-1] and high > high[-2], high, 0);

isdownfractal = If(((locount and lovalid) or (low < low[1] and low < low[2])) and low < low[-1] and low < low[-2], low, 0);

def upfractal = If( isupfractal, isupfractal, Double.NaN);

def downfractal = If( isdownfractal, isdownfractal, Double.NaN);

############## Robert Payne

def peak = high >= Highest(high[1], n) and high >= Highest(high[-n], n);

def valley = low <= Lowest(low[1], n) and low <= Lowest(low[-n], n);

############## mcdon

def hhh = ( fold ij = 1 to n with pk = 1 while pk do high == GetValue(Highest(high, n), -ij) && high == Highest(high, n));

def lll = ( fold jj = 1 to n with qk = 1 while qk do low == GetValue(Lowest(low, n) , -jj) && low == Lowest(low, n) );

# Substitue for Williams Fractal Pattern

# tSL for Sree

# Nube 4.2.19

def nan = Double.NaN;

def hpBar = if !GetMaxValueOffset(high , n + 1) && GetMaxValueOffset(high, n + 1)[-n] == n then bn else nan;

def lpBar = if !GetMinValueOffset(low, n + 1) && GetMinValueOffset(low, n + 1)[-n] == n then bn else nan;


##https://usethinkscript.com/threads/trend-reversal-indicator-with-signals-for-thinkorswim.183/page-32#post-23354

def lastBar = HighestAll(if !IsNaN(close) then bn else 0);

def offset = Min(n - 1, lastBar - bn);

def pHigh = high == Highest(high, n) and high == GetValue(Highest(high, n), -offset);

def pLow = low == Lowest(low,n) and low == GetValue(Lowest(low,n), -offset);

def PivotHa;

def PivotLa;

input choose = { Mobius,Mobius_Fr_Box, ML_BWilliams, RP, default Mcdon,nube,TSforum};

switch (choose ) {

case Mobius:

PivotHa = if IsNaN(PivotHm ) then 0 else PivotHm ;

PivotLa = if IsNaN(PivotLm ) then 0 else PivotLm ;

case Mobius_Fr_Box:

PivotHa = if IsNaN(upfractalts) then 0 else upfractalts;

PivotLa = if IsNaN(downfractalts ) then 0 else downfractalts ;

case ML_BWilliams:

PivotHa = if IsNaN(upfractal) then 0 else upfractal;

PivotLa = if IsNaN(downfractal ) then 0 else downfractal ;

case RP:

PivotHa = if IsNaN(peak) then 0 else peak ;

PivotLa = if IsNaN(valley ) then 0 else valley;

case Mcdon:

PivotHa = if IsNaN(hhh) then 0 else hhh ;

PivotLa = if IsNaN(lll) then 0 else lll;

case nube:

PivotHa = if IsNaN(hpBar) then 0 else hpBar ;

PivotLa = if IsNaN(lpBar) then 0 else lpBar;

case TSforum:

PivotHa = if IsNaN(pHigh) then 0 else pHigh ;

PivotLa = if IsNaN(pLow) then 0 else pLow;

}

script F {

input value = close ;

def bn = BarNumber();

def lbar = HighestAll(if IsNaN(close) then 0 else bn);

plot xd = fold di = 1 to lbar with da = Double.NaN while IsNaN(da) do if GetValue(value, -di) then di else Double.NaN;

}

script paint {

input v1 = 0.0 ;

input v2 = 0.0;

def bn = BarNumber();

def lv1bar = HighestAll(if v1 then bn else 0);

def lv2bar = HighestAll(if v2 then bn else 0);

def lbar = HighestAll(if IsNaN(close) then 0 else bn);

plot va1 = if bn >= lv1bar then 0 else fold id = 1 to lbar with t = 0 while t == 0 do if GetValue(v1, -id) then id else 0;

plot va2 = if bn >= lv2bar then 0 else fold sd = 1 to lbar with x = 0 while x == 0 do if GetValue(v2, -sd) then sd else 0;

plot fva1 = GetValue(high, -va1);

plot fva2 = GetValue(low, -va2);

}

##################### begin rotation logic

def pivothabn = if PivotHa then bn else pivothabn[1];

def pivotlabn = if PivotLa then bn else pivotlabn[1];

def pivotcount = CompoundValue(1, if PivotHa[1] then pivotcount[1] + 1 else if PivotLa[1] then pivotcount[1] + 1 else pivotcount[1], 1);

### logic correction 1). When pivot low and high occur simotaneiously use prevbars for correction

def pivothb = bn >= 2 && ( (PivotHa && PivotLa && (pivothabn[1] < pivotlabn[1])) or (PivotHa && !PivotLa && pivothabn >= n)) ;

def pivotlb = bn >= 2 && ( (PivotLa && PivotHa && (pivotlabn[1] < pivothabn[1])) or (PivotLa && !PivotHa && pivotlabn >= n));

#### logic correction 2). frankly i don't know why this is needed but it is.

def pivothc = pivothb && Max(pivothabn, pivotcount[1] + 1) && !pivotlb ;

def pivotlc = pivotlb && Max(pivotlabn , pivotcount[1] + 1) && !pivothb;

def pivothvalue = if pivothc then high else pivothvalue[1] ;

def pivotlvalue = if pivotlc then low else pivotlvalue[1] ;

### logic correction 3). same method as logic correction 1 but further finds missing pivots to create zz

def pivothbBN = if pivothb then bn else pivothbBN[1];

def pivotlbBN = if pivotlb then bn else pivotlbBN[1];

def pivotmax = Max(pivothbBN, pivotlbBN);

def pivothcorrection = if pivotlc[1] then high else if high > pivothcorrection[1] then high else if high >= pivothcorrection [1] && high> pivotlvalue[1]then high else pivothcorrection[1];

def pivotlcorrection = if pivothc[1] then low else if low < pivotlcorrection[1] then low else if low <= pivotlcorrection[1] && low< pivothvalue[1] then low else pivotlcorrection[1];

def pivothcorrectionloc = if (pivotlbBN[1]== pivotmax) && !pivothc && !pivotlc && pivothcorrection<>pivothcorrection[1] && high == GetValue(pivothcorrection[1], -f(pivotlc)) then 1 else Double.NaN;

def pivotlcorrectionloc = if (pivothbBN[1]== pivotmax) && !pivothc && !pivotlc && pivotlcorrection<>pivotlcorrection[1] && low == GetValue(pivotlcorrection[1], -f(pivothc)) then 1 else Double.NaN;

### logic correction 4). either original pivot script or correction

def pivothd = ( (pivothc or !IsNaN(pivothcorrectionloc)));

def pivotld = ( ( pivotlc or !IsNaN(pivotlcorrectionloc)));

### logic correction 5). error correction for the correction logic as it would occur immediatly after, such as two pivot highs instead pivot high then pivot low

def pivothe = pivothd != pivothd[1] && ( (pivothc or !IsNaN(pivothcorrectionloc)));

def pivotle = pivotld != pivotld[1] && ( ( pivotlc or !IsNaN(pivotlcorrectionloc)));

### logic correction 6). same method as correction 1. i don't know why it's needed, but it is

def pivothdBN = CompoundValue(1, if pivothd then bn else pivothdBN[1], bn);

def pivotldBN = CompoundValue(1, if pivotld then bn else pivotldBN[1], bn);

def pivotlsavelastPivotHbn = if pivothe then pivotldBN else pivotlsavelastPivotHbn[1];

def pivotHsavelastPivotLbn = if pivotle then pivothdBN else pivotHsavelastPivotLbn[1];

def PivotH = pivotlsavelastPivotHbn <>pivotlsavelastPivotHbn [1] && pivothd != pivothd[1] && (( pivothc or !IsNaN(pivothcorrectionloc)));

def PivotL = pivotHsavelastPivotLbn <> pivotHsavelastPivotLbn[1] && pivotld != pivotld[1] && ( ( pivotlc or !IsNaN(pivotlcorrectionloc)));

#### 1rst order pivots

def pivotcal = CompoundValue(1, if pivoth then pivotcal [1] + 1 else if pivotl then pivotcal [1] + 1 else pivotcal[1], 1);

#### 2nd order pivots

def pivothv = if pivoth then high else pivothv[1];

def pivotlv = if pivotl then low else pivotlv[1];

def prvFrH1 = if pivothv<> pivothv[1] then pivothv[1] else prvFrH1[1];

def FrHbn = CompoundValue(1, if pivoth then bn else FrHbn[1], bn);

def FrHbn1 = if FrHbn <> FrHbn[1] then FrHbn[1] else FrHbn1[1];

def prvFrL1 = if pivotlv <> pivotlv[1] then pivotlv[1] else prvFrL1[1];

def Frlbn = CompoundValue(1, if pivotl then bn else Frlbn[1], bn);

def FrLbn1 = if Frlbn <> Frlbn[1] then Frlbn[1] else FrLbn1[1];

#### 3rd order pivots

def pivoth2nd = hhll(pivotl,pivoth).maxhtc ;

def pivotl2nd = hhll(pivotl,pivoth).maxltc;

def pivotcal2nd = CompoundValue(1, if pivoth2nd then pivotcal2nd [1] + 1 else if pivotl2nd then pivotcal2nd[1] + 1 else pivotcal2nd[1], 1);

def pivoth2ndc = CompoundValue(1, if pivoth2nd[1] then 1 else pivoth2ndc[1] + 1, 1);

def pivotl2ndc = CompoundValue(1, if pivotl2nd [1] then 1 else pivotl2ndc[1] + 1, 1);

def pivoth2ndv = if pivoth2nd then high else pivoth2ndv[1];

def pivotl2ndv = if pivotl2nd then low else pivotl2ndv[1];

def prvFr2dnH1 = if pivoth2ndv <> pivoth2ndv[1] then pivoth2ndv[1] else prvFr2dnH1[1];

def prvFr2dnH2 = if prvFr2dnH1 <> prvFr2dnH1[1] then prvFr2dnH1[1] else prvFr2dnH2[1];

def prvFr2dnL1 = if pivoth2ndv <> pivoth2ndv[1] then pivoth2ndv[1] else prvFr2dnL1 [1];

def prvFr2dnL2 = if prvFr2dnL1 <> prvFr2dnL1[1] then prvFr2dnL1[1] else prvFr2dnL2 [1];

def FrH2ndbn = CompoundValue(1, if pivoth2nd then bn else FrH2ndbn[1], bn);

def FrH2nd2bn = GetValue(bn, pivoth2ndc[1]);

def Frl2ndbn = CompoundValue(1, if pivotl2nd then bn else Frl2ndbn[1], bn);

def Frl2nd2bn = GetValue(bn, pivotl2ndc);

def pivoth3rd = hhll(pivotl2nd,pivoth2nd).maxht3;

def pivotl3rd = hhll(pivotl2nd,pivoth2nd).maxlt3;

def pivotcal3rd = CompoundValue(1, if pivoth3rd then pivotcal3rd [1] + 1 else if pivotl3rd then pivotcal3rd[1] + 1 else pivotcal3rd[1], 1);

def pivoth3rdv = if pivoth3rd then high else pivoth3rdv[1];

def pivotl3rdv = if pivotl3rd then low else pivotl3rdv[1];

def prvFrH3rd1 = if pivoth3rdv <> pivoth3rdv[1] then pivoth3rdv[1] else prvFrH3rd1[1];

def prvFrL3rd1 = if pivotl3rdv <> pivotl3rdv[1] then pivotl3rdv[1] else prvFrL3rd1[1];

def FrlH3rdbn = CompoundValue(1, if pivoth3rd then bn else FrlH3rdbn[1], bn);

def Frll3rdbn = CompoundValue(1, if pivotl3rd then bn else Frll3rdbn[1], bn);

def zz1rst = if (IsNaN(pivotl) or IsNaN(pivoth)) then Double.NaN else if pivotl and low then (paint(pivoth , pivotl).fva1 - low) / (paint(pivotl, pivoth ).va2)

else if pivoth and high then ((paint(pivoth , pivotl).fva2 - high) / (paint(pivoth, pivotl).va2)) else zz1rst[1];

def line1rst = if pivotl then low else if pivoth then high else line1rst[1] + zz1rst;

def zz2nd = if pivotl2nd and low then (paint(pivoth2nd , pivotl2nd ).fva1 - low) / (paint( pivotl2nd, pivoth2nd ).va2)

else if pivoth2nd and high then ((paint(pivoth2nd , pivotl2nd).fva2 - high) / (paint(pivoth2nd , pivotl2nd).va2)) else zz2nd[1];

def line2nd = if pivotl2nd then low else if pivoth2nd then high else line2nd[1] + zz2nd;

def zz3rd = if (IsNaN(pivotl3rd) or IsNaN(pivoth3rd)) then Double.NaN else if pivotl3rd and low then (paint(pivoth3rd, pivotl3rd).fva1 - low) / (paint(pivotl3rd, pivoth3rd).va2)

else if pivoth3rd and high then ((paint(pivoth3rd, pivotl3rd ).fva2 - high) / (paint(pivoth3rd, pivotl3rd).va2)) else zz3rd[1];

def line3rd = if pivotl3rd then low else if pivoth3rd then high else line3rd[1] + zz3rd;

plot zz1rstline = if pivotcal <= 1 then Double.NaN else if show1rstzz then line1rst else Double.NaN;

zz1rstline.SetDefaultColor(Color.WHITE);

zz1rstline.SetStyle(Curve.SHORT_DASH);

zz1rstline.SetLineWeight(2);

plot zz2ndline = if pivotcal2nd <= 1 then Double.NaN else if show2ndzz then line2nd else Double.NaN;

zz2ndline.SetDefaultColor(Color.WHITE);

zz2ndline.SetStyle(Curve.SHORT_DASH);

zz2ndline.SetLineWeight(2);

plot zz3rdline = if pivotcal3rd <= 1 then Double.NaN else if show3rdzz then line3rd else Double.NaN;

zz3rdline.SetDefaultColor(Color.CYAN);

zz3rdline.SetStyle(Curve.SHORT_DASH);

zz3rdline.SetLineWeight(3);

plot pivoth1rst = if pivoth then high else Double.NaN;

pivoth1rst.SetPaintingStrategy(PaintingStrategy.POINTS);

pivoth1rst.SetDefaultColor(Color.LIGHT_GREEN);

pivoth1rst.SetLineWeight(2);

plot pivotl1rst = if pivotl then low else Double.NaN;

pivotl1rst.SetPaintingStrategy(PaintingStrategy.POINTS);

pivotl1rst.SetDefaultColor(Color.LIGHT_RED);

pivotl1rst.SetLineWeight(2);

plot pivoth2nd_ = if pivoth2nd then high else Double.NaN;

pivoth2nd_.SetPaintingStrategy(PaintingStrategy.POINTS);

pivoth2nd_.SetDefaultColor(Color.GREEN);

pivoth2nd_.SetLineWeight(4);

plot pivotl2nd_ = if pivotl2nd then low else Double.NaN;

pivotl2nd_ .SetPaintingStrategy(PaintingStrategy.POINTS);

pivotl2nd_ .SetDefaultColor(Color.RED);

pivotl2nd_ .SetLineWeight(4);

plot pivoth3rd_ = if pivoth3rd then high else Double.NaN;

pivoth3rd_.SetPaintingStrategy(PaintingStrategy.POINTS);

pivoth3rd_.SetDefaultColor(Color.CYAN);

pivoth3rd_.SetLineWeight(5);

plot pivotl3rd_ = if pivotl3rd then low else Double.NaN;

pivotl3rd_ .SetPaintingStrategy(PaintingStrategy.POINTS);

pivotl3rd_ .SetDefaultColor(Color.CYAN);

pivotl3rd_ .SetLineWeight(5);

AddChartBubble(show1rstbubble && pivoth1rst,high,if between(pivothv,pivothv[1]*.999,pivothv[1]*1.001) then "DT" else

if between(pivothv,prvFrl1 *.999,prvFrl1 *1.001) then "RS" else

if pivothv>pivothv[1]*1.001 then "hh" else "lh",if RocketRSI(10, 8) > 1.5 then Color.ORANGE else Color.GRAY);

AddChartBubble(show1rstbubble and pivotl1rst,low,if between(pivotlv,pivotlv[1]*.999,pivotlv[1]*1.001) then "DB" else

if between(pivotlv,prvFrH1 *.999,prvFrH1*1.001) then "SP" else

if pivotlv<pivotlv[1]*.999 then "ll" else "hl", if RocketRSI(10, 8) < -1.5 then Color.ORANGE else Color.GRAY);

AddChartBubble(show2ndbubble and pivoth2nd_, high,if between(pivoth2ndv,pivoth2ndv[1]*.999,pivoth2ndv[1]*1.001) then "DT" else

if between(pivoth2ndv,prvFr2dnl1*.999,prvFr2dnl1*1.01) then "RS" else

if pivoth2ndv>pivoth2ndv[1]*1.01 then "HH" else "LH", if RocketRSI(10, 8) > 1.5 then Color.light_green else Color.GREEN);

AddChartBubble(show2ndbubble and pivotl2nd_,low,if between(pivotl2ndv,pivotl2ndv[1]*.999,pivotl2ndv[1]*1.001) then "DB" else

if between(pivotl2ndv,prvFr2dnH1*.999,prvFr2dnH1*1.001) then "SP" else

if pivotl2ndv<pivotl2ndv[1]*.999 then "LL" else "HL", if RocketRSI(10, 8) < -1.5 then Color.light_green else Color.GREEN);

AddChartBubble(show3rdbubble and pivoth3rd_,high,if between(pivoth3rdv,pivoth3rdv[1]*.99,pivoth3rdv[1]*1.001) then "DT" else

if between(pivoth3rdv, prvFrL3rd1*.999, prvFrL3rd1*1.001) then "RS" else

if pivoth3rdv>pivoth3rdv[1]*1.01 then "HH" else "LH", if RocketRSI(10, 8) > 1.5 then Color.magenta else Color.CYAN);

AddChartBubble(show3rdbubble and pivotl3rd_, low ,if between(pivotl3rdv,pivotl3rdv[1]*.999,pivotl3rdv[1]*1.001) then "DB" else

if between(pivotl3rdv,prvFrH3rd1*.999,prvFrH3rd1*1.001) then "SP" else

if pivotl3rdv<pivotl3rdv[1]*1.001 then "LL" else "HL", if RocketRSI(10, 8) < -1.5 then Color.magenta else Color.CYAN);

#### count between higher fractals

def countreset1rst = (pivoth or pivotl);

def countreset1rst_ = if IsNaN(countreset1rst) then 0 else countreset1rst;

def countreset2nd = (pivoth2nd or pivotl2nd);

def countreset2nd_ = if IsNaN(countreset2nd) then 0 else countreset2nd ;

def countbetween2nd = CompoundValue(1, if countreset2nd_ then 0 else if (pivoth or pivotl) then countbetween2nd[1] + 1 else if countbetween2nd[1]>=3 && countreset2nd_[2] then 0 else countbetween2nd[1], 0);

def countreset3rd = (pivotl3rd or pivoth3rd);

def countreset3rd_ = if IsNaN(countreset3rd) then 0 else countreset3rd;

def countbetween3rd = CompoundValue(1, if countreset3rd_ then 0 else if (pivoth or pivotl) then countbetween3rd [1] + 1 else countbetween3rd [1], 0);

def countreset2nd3rd = (pivotl3rd or pivoth3rd);

def countreset2nd3rd_ = if IsNaN(countreset3rd) then 0 else countreset3rd;

def countbetween2nd3rd = CompoundValue(1, if countreset2nd3rd_ then 0 else if (pivoth2nd_ or pivotl2nd_) then countbetween2nd3rd[1] + 1 else countbetween2nd3rd[1], 0);

AddChartBubble(countbetween and pivoth && countbetween2nd , high, countbetween2nd, Color.light_green);

AddChartBubble(countbetween and pivotl && countbetween2nd , low, countbetween2nd, Color.light_green);

AddChartBubble(countbetween and pivoth2nd_ && countbetween2nd3rd, high, countbetween2nd3rd, Color.ORANGE);

AddChartBubble(countbetween and pivotl2nd_ && countbetween2nd3rd, low, countbetween2nd3rd, Color.ORANGE);

############################### 1). first order fib

def bearfibpivot_ = if IsNaN(close) then 0 else ( pivoth && fib(pivothv, pivotlv , prvFrH1 , tol) );

def bullfibpivot_ = if IsNaN(close) then 0 else (pivotl && fib(pivotlv , pivothv, prvFrL1, tol ));

plot befibfractal = if bearfibpivot_ then high else Double.NaN;

befibfractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);

befibfractal.SetDefaultColor(Color.YELLOW);

befibfractal.SetLineWeight(5);

plot bufibfractal = if bullfibpivot_ then low else Double.NaN;

bufibfractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

bufibfractal.SetDefaultColor(Color.YELLOW);

bufibfractal.SetLineWeight(5);

AddChartBubble(showFibpivotbubble and befibfractal, high, "fib:" + fib(pivothv, pivotlv, prvFrH1, tol).ratio, Color.LIGHT_RED);

AddChartBubble(showFibpivotbubble and bufibfractal, low, "fib: " + fib(pivotlv, pivothv, prvFrL1, tol).ratio, Color.LIGHT_GREEN);

############################### 2). first order fib relation to 2nd order

def maxvalue = if FrH2ndbn > Frl2ndbn then pivoth2ndv else pivotl2ndv;

def maxvalue2 = if maxvalue == pivotl2ndv then pivoth2ndv else pivotl2ndv ;

def bearfibpivot2_ = if IsNaN(close) then 0 else (pivoth && fib(pivothv, maxvalue , maxvalue2, tol)) ;

def bullfibpivot2_ = if IsNaN(close) then 0 else (pivotl && fib(pivotlv, maxvalue , maxvalue2, tol));

plot befibfractal2 = if bearfibpivot2_ then high else Double.NaN;

befibfractal2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);

befibfractal2.SetDefaultColor(Color.CYAN);

befibfractal2.SetLineWeight(5);

plot bufibfractal2 = if bullfibpivot2_ then low else Double.NaN;

bufibfractal2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

bufibfractal2.SetDefaultColor(Color.CYAN);

bufibfractal2.SetLineWeight(5);

AddChartBubble(showFibrelationbubble and befibfractal2, high, "2ndfib:" + fib(pivothv, maxvalue , maxvalue2, tol).ratio, Color.CYAN);

AddChartBubble(showFibrelationbubble and bufibfractal2, low, "2ndfib: " + fib(pivotlv, maxvalue , maxvalue2, tol).ratio, Color.CYAN);

def maxlvalue = if FrlH3rdbn > Frll3rdbn then pivoth3rdv else pivotl3rdv;

def maxlvalue2 = if maxlvalue == pivotl3rdv then pivoth3rdv else pivotl3rdv ;

############################### 3). first order fib relation to 3rd order

def lbearfibpivot2_ = if IsNaN(close) then 0 else (pivoth && fib(pivothv, maxlvalue , maxlvalue2, tol)) ;

def lbullfibpivot2_ = if IsNaN(close) then 0 else (pivotl && fib(pivotlv , maxlvalue , maxlvalue2, tol));

plot belfibfractal2 = if lbearfibpivot2_ then high else Double.NaN;

belfibfractal2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);

belfibfractal2.SetDefaultColor(Color.ORANGE);

belfibfractal2.SetLineWeight(5);

plot bulfibfractal2 = if lbullfibpivot2_ then low else Double.NaN;

bulfibfractal2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

bulfibfractal2.SetDefaultColor(Color.ORANGE);

bulfibfractal2.SetLineWeight(5);

AddChartBubble(showFibrelationbubble and belfibfractal2, high, "3rdfib:" + fib(pivothv, maxlvalue , maxlvalue2, tol).ratio, Color.CYAN);

AddChartBubble(showFibrelationbubble and bulfibfractal2, low, "3rdfib: " + fib(pivotlv, maxlvalue , maxlvalue2, tol).ratio, Color.CYAN);

############################### 1). 2nd order fib relationship

def mbearfibpivot_ = if IsNaN(close) then 0 else (pivoth2nd && fib(prvFr2dnH1, prvFr2dnL1, prvFr2dnH2 , tol)) ;

def mbullfibpivot_ = if IsNaN(close) then 0 else (pivotl2nd && fib(prvFr2dnL1, prvFr2dnH1, prvFr2dnL2, tol));

plot mbefibfractal = if mbearfibpivot_ then high else Double.NaN;

mbefibfractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);

mbefibfractal.SetDefaultColor(Color.YELLOW);

mbefibfractal.SetLineWeight(5);

plot mbufribfractal = if mbullfibpivot_ then low else Double.NaN;

mbufribfractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

mbufribfractal.SetDefaultColor(Color.YELLOW);

mbufribfractal.SetLineWeight(5);

AddChartBubble(showFibpivotbubble and mbefibfractal, high, "fib: " + fib(pivoth2ndv, pivotl2ndv, prvFrH3rd1 , tol).ratio, Color.LIGHT_RED);

AddChartBubble(showFibpivotbubble and mbufribfractal, low, "fib: " + fib(pivotl2ndv, pivoth2ndv, prvFr2dnL1, tol).ratio, Color.LIGHT_GREEN);

############################### 1). 2nd order fib relation to 3rd order

def mlbearfibpivot2_ = if IsNaN(close) then 0 else ( pivoth2nd && fib(pivoth2ndv, maxlvalue , maxlvalue2, tol));

def mlbullfibpivot2_ = if IsNaN(close) then 0 else (pivotl2nd && fib(pivotl2ndv, maxlvalue , maxlvalue2, tol));

plot mbelfibfractal2 = if mlbearfibpivot2_ then high else Double.NaN;

mbelfibfractal2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);

mbelfibfractal2.SetDefaultColor(Color.ORANGE);

mbelfibfractal2.SetLineWeight(5);

plot mbulfibfractal2 = if mlbullfibpivot2_ then low else Double.NaN;

mbulfibfractal2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

mbulfibfractal2.SetDefaultColor(Color.ORANGE);

mbulfibfractal2.SetLineWeight(5);

AddChartBubble(showFibrelationbubble and mbelfibfractal2, high, "3rdfib:" + fib(pivoth2ndv, maxlvalue , maxlvalue2, tol).ratio, Color.CYAN);

AddChartBubble(showFibrelationbubble and mbulfibfractal2, low, "3rdfib: " + fib(pivotl2ndv, maxlvalue , maxlvalue2, tol).ratio, Color.CYAN);

############################### 2).3rd order fib relationship

def lbearfibpivot_ = if IsNaN(close) then 0 else (pivoth3rd && fib(pivoth3rdv, pivotl3rdv, prvFrH3rd1, tol));

def lbullfibpivot_ = if IsNaN(close) then 0 else (pivotl3rd && fib(pivotl3rdv, pivoth3rdv, prvFrL3rd1, tol));

plot lbefibfractal = if lbearfibpivot_ then high else Double.NaN;

lbefibfractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);

lbefibfractal.SetDefaultColor(Color.YELLOW);

lbefibfractal.SetLineWeight(5);

plot lbufribfractal = if lbullfibpivot_ then low else Double.NaN;

lbufribfractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

lbufribfractal.SetDefaultColor(Color.YELLOW);

lbufribfractal.SetLineWeight(5);

AddChartBubble(showFibpivotbubble and lbefibfractal, high, "fib: " + fib(pivoth3rdv, pivotl3rdv, prvFrH3rd1, tol).ratio, Color.LIGHT_RED);

AddChartBubble(showFibpivotbubble and lbufribfractal, low, "fib: " + fib(pivotl3rdv, pivoth3rdv, prvFrL3rd1, tol).ratio, Color.LIGHT_GREEN);

## higher highs and lower lows

def fr1lowconsect = if pivotl && pivotlv<pivotlv[1] then fr1lowconsect[1]+1 else if pivotl && pivotlv>pivotlv[1] then 0 else fr1lowconsect[1];

def fr1highconsect = if pivoth && pivothv>pivothv[1] then fr1highconsect[1]+1 else if pivoth && pivothv<pivothv[1] then 0 else fr1highconsect[1];

def fr1lowconsect2 = if pivotl && pivotl2ndv<pivotl2ndv[1] then fr1lowconsect2[1]+1 else if pivotl && pivotl2ndv>pivotl2ndv[1] then 0 else fr1lowconsect2[1];

def fr1highconsect2 = if pivoth && pivoth2ndv>pivoth2ndv[1] then fr1highconsect2[1]+1 else if pivoth && pivoth2ndv<pivoth2ndv[1] then 0 else fr1highconsect2[1];

AddChartBubble(showHHLLcount && pivoth1rst && fr1highconsect ,high,fr1highconsect, Color.white);

AddChartBubble(showHHLLcount and pivotl1rst&& fr1lowconsect,low,fr1lowconsect, Color.white);

AddChartBubble(showHHLLcount && pivoth2nd_ && fr1highconsect2,high,fr1highconsect2, Color.ORANGE);

AddChartBubble(showHHLLcount and pivotl2nd_ && fr1lowconsect2,low,fr1lowconsect2, Color.ORANGE);

def highbar;

def lowbar;

def creset;

def pivotH32;

def pivotl32;

input selectprojvalues = { third, default second};

switch (selectprojvalues) {

case third:

highbar = FrlH3rdbn;

lowbar =Frll3rdbn;

creset=countreset2nd3rd_;

pivotH32=pivoth3rd;

pivotl32 =pivotl3rd;

case second:

highbar = FrH2ndbn;

lowbar =Frl2ndbn;

creset= countreset2nd_;

pivotH32= pivoth2nd;

pivotl32 = pivotl2nd;

}

def minbb = Min(HighestAll(highbar), HighestAll(lowbar));

def maxbb= Max(HighestAll(highbar), HighestAll(lowbar));

def stopmax = bn ==maxbb;

def stopmax_ = if IsNaN(close) then 0 else stopmax;

def stopmin = bn == minbb;

def stopmin_ = if IsNaN(close) then 0 else stopmin;

def countbetween3rdbar = CompoundValue(1, if creset then bn else countbetween3rdbar [1], bn);

def countbetween3rdbar2 = CompoundValue(1, if countbetween3rdbar > countbetween3rdbar[1] then countbetween3rdbar[1] else countbetween3rdbar2[1], bn);

def countbetween3rdbar3 = CompoundValue(1, if countbetween3rdbar2 > countbetween3rdbar2[1] then countbetween3rdbar2[1] else countbetween3rdbar3[1], bn);

def countbetween3rdbar4 = CompoundValue(1, if countbetween3rdbar3 > countbetween3rdbar3[1] then countbetween3rdbar3[1] else countbetween3rdbar4[1], bn);

def countbetween3rdbar5 = CompoundValue(1, if countbetween3rdbar4 > countbetween3rdbar4[1] then countbetween3rdbar4[1] else countbetween3rdbar5[1], bn);

def countbetween3rdv = CompoundValue(1, if creset && pivotH32 then high else if creset && pivotl32 then low else countbetween3rdv [1], 1);

def countbetween3rdv2 = CompoundValue(1, if countbetween3rdv <> countbetween3rdv[1] then countbetween3rdv[1] else countbetween3rdv2[1], 1);

def countbetween3rdv3 = CompoundValue(1, if countbetween3rdv2 <> countbetween3rdv2[1] then countbetween3rdv2[1] else countbetween3rdv3[1], 1);

def countbetween3rdv4 = CompoundValue(1, if countbetween3rdv3 <> countbetween3rdv3[1] then countbetween3rdv3[1] else countbetween3rdv4[1], 1);

def countbetween3rdv5 = CompoundValue(1, if countbetween3rdv4 <> countbetween3rdv4[1] then countbetween3rdv4[1] else countbetween3rdv5[1], 1);

def lowl ;

def highl ;

def Xratio;

def Yratio;

input projectionOrder = {twothree, threefour, default fourfive};

switch (projectionOrder ) {

case twothree:

lowl = if countbetween3rdv && pivotl32 then low else if countbetween3rdv && pivotH32 then high-AbsValue(countbetween3rdv2 - countbetween3rdv3) else lowl[1];

highl = if countbetween3rdv && pivotH32 then high else if countbetween3rdv && pivotl32 then low+AbsValue(countbetween3rdv2- countbetween3rdv3) else highl[1];

Xratio = absvalue(lowl- highl);

Yratio = AbsValue(countbetween3rdbar2 - countbetween3rdbar3 );

case threefour:

lowl = if countbetween3rdv && pivotl32 then low else if countbetween3rdv && pivotH32 then high-AbsValue(countbetween3rdv3 - countbetween3rdv4) else lowl[1];

highl = if countbetween3rdv && pivotH32 then high else if countbetween3rdv && pivotl32 then low+AbsValue(countbetween3rdv3- countbetween3rdv4) else highl[1];

Xratio = absvalue(lowl- highl);

Yratio = AbsValue(countbetween3rdbar3 - countbetween3rdbar4 );

case fourfive:

lowl = if countbetween3rdv && pivotl32 then low else if countbetween3rdv && pivotH32 then high-AbsValue(countbetween3rdv4- countbetween3rdv5) else lowl[1];

highl = if countbetween3rdv && pivotH32 then high else if countbetween3rdv && pivotl32 then low+AbsValue(countbetween3rdv4- countbetween3rdv5) else highl[1];

Xratio = absvalue(lowl- highl);

Yratio = AbsValue(countbetween3rdbar4 - countbetween3rdbar5 );

}

def change = Xratio / Yratio;

def maxcount = CompoundValue(1, if stopmax_ then 0 else maxcount[1] + 1, 0);

def Revmax = CompoundValue(1, if stopmax_ then (change) else Revmax[1], Double.NaN);

##def stop = maxcount>0 && stopmax>=0 && (( close[1] crosses above highl ) or (close[1] crosses below lowl) or (maxcount > (yratio *trendmult)));

def dnline = CompoundValue(1, if stopmax_ && minbb== highbar then countbetween3rdv else if maxcount > (yratio *trendmult) then Double.NaN else ( dnline[1] + Revmax ), Double.NaN);

def dnlinel = CompoundValue(1, if stopmax_ && minbb == lowbar then countbetween3rdv else if maxcount > (yratio *trendmult) then Double.NaN else (dnlinel[1] - Revmax) , Double.NaN);

def activepro = if showprojection==no then double.nan else stopmax >= 0 && minbb == lowbar;

plot dnlineProj = if activepro then dnlinel else dnline ;

dnlineProj.SetDefaultColor(Color.CYAN);

dnlineProj.SetLineWeight(2);

dnlineProj.SetStyle(Curve.SHORT_DASH);

plot hiline = if dnlineProj then highl

else double.nan;

hiline.SetDefaultColor(color.red);

plot loline = if dnlineProj then lowl

else double.nan;

loline.SetDefaultColor(color.cyan);

def range3rd = absvalue(loline - hiline) ;

plot fib146 = if activepro then hiline - (range3rd *0.146) else loline +(range3rd *0.146) ;

fib146.SetDefaultColor(Color.GREEN);

AddChartBubble( showprojection and !isNaN(fib146[1]) and isNaN(fib146[-1]),fib146,"fib146" ,color.cyan);

plot fib236 = if activepro then hiline - (range3rd *0.236) else loline +(range3rd *0.236) ;

fib236.SetDefaultColor(Color.GREEN);

AddChartBubble( showprojection and !isnan(fib236[1]) && isnan(fib236[-1]),fib236,"fib236" ,color.cyan);

plot fib382 = if activepro then hiline - (range3rd *0.382) else loline +(range3rd *0.382) ;

fib382.SetDefaultColor(Color.GREEN);

AddChartBubble( showprojection and !isNaN(fib382[1]) and isNaN(fib382[-1]),fib382,"fib382" ,color.cyan);

plot fib50= if activepro then hiline - (range3rd *0.50) else loline +(range3rd *0.50) ;

fib50.SetDefaultColor(Color.GREEN);

AddChartBubble( showprojection and !isNaN(fib50[1]) and isNaN(fib50[-1]),fib50,"fib50" ,color.cyan);

plot fib618 = if activepro then hiline - (range3rd *0.618) else loline +(range3rd *0.618) ;

fib618.SetDefaultColor(Color.GREEN);

plot mid382 = if between(dnlineProj,fib382,fib618) or between(dnlineProj,fib618,fib382) then fib382 else double.nan;

mid382.SetDefaultColor(Color.blue);

plot mid618 = if between(dnlineProj,fib382,fib618) or between(dnlineProj,fib618,fib382) then fib618 else double.nan;

mid618.SetDefaultColor(Color.blue);

addcloud(mid382 ,mid618,color.green,color.green);

addcloud(fib382 ,fib618,color.cyan,color.cyan);

AddChartBubble( showprojection and !isNaN(fib618[1]) and isNaN(fib618[-1]),fib618,"fib618" ,color.cyan);

plot fib786= if activepro then hiline - (range3rd *0.786) else loline +(range3rd *0.786) ;

fib786.SetDefaultColor(Color.GREEN);

AddChartBubble( showprojection and !isNaN(fib786[1]) and isNaN(fib786[-1]),fib786,"fib786" ,color.cyan);

plot fib886= if activepro then hiline - (range3rd *0.886) else loline +(range3rd *0.886) ;

fib886.SetDefaultColor(Color.GREEN);

AddChartBubble( showprojection and !isNaN(fib886[1]) and isNaN(fib886[-1]),fib886,"fib886" ,color.cyan);

plot fib1= if activepro then hiline - (range3rd *1) else loline +(range3rd *1) ;

fib1.SetDefaultColor(Color.GREEN);

AddChartBubble( showprojection and !isNaN(fib1[1]) and isNaN(fib1[-1]),fib1,"fib1" ,color.cyan);

plot fib1236= if activepro then hiline - (range3rd *1.236) else loline +(range3rd *1.236) ;

fib1236.SetDefaultColor(Color.GREEN);

AddChartBubble( showprojection and !isNaN(fib1236[1]) and isNaN(fib1236[-1]),fib1236,"fib1236" ,color.cyan);

plot fib1618= if activepro then hiline - (range3rd *1.618) else loline +(range3rd *1.618) ;

fib1618.SetDefaultColor(Color.GREEN);

AddChartBubble( showprojection and !isNaN(fib1618[1]) and isNaN(fib1618[-1]),fib1618,"fib1618" ,color.cyan);

addcloud(fib1236,fib1236,color.light_red,color.light_red);

script paintS {

input pat = 0.0;

input v1 = 0.0;

input v2 = 0.0;

input paint1 =0.0;

input paint2 =0.0;

def p1 = if isnan(pat) then 0 else v1 && pat;

def p2 =if isnan(close) then 0 else v2 && GetValue(p1, -paint1 );

plot p3= if isnan(close) then 0 else v1 && GetValue(p2, -paint2 );

}

def bullSRa = if stopmax and pivotl then 1 else double.nan;

def bearSRa = if stopmax and pivoth then 1 else double.nan;

def bullSR = if isnan(close) then 0 else !isnan(bullSRa) ;

def bearSR = if isnan(close) then 0 else !isnan(bearSRa) ;

def bullSR_ = paintS(bullSR,pivotl,pivoth,paint(pivotl,high).va1,paint(pivoth,low).va1);

def bearSR_ = paintS(bearSR,pivoth,pivotl,paint(pivoth,low).va1,paint(pivotl,high).va1);

def bullstart = if isnan(close) then 0 else bullSR_ && showprojection==yes;

def bearstart = if isnan(close) then 0 else bearSR_&& showprojection==yes;

def bullstruct1 = compoundvalue(1, if bullstart then 1 else if !isNaN(dnlineProj[1]) and isNaN(dnlineProj[-1]) then double.nan else if pivoth[1] or pivotl[1] then bullstruct1[1] + 1 else bullstruct1[1],double.nan);

def bearstruct1 = compoundvalue(1,if bearstart then 1 else if !isNaN(dnlineProj[1]) and isNaN(dnlineProj[-1]) then double.nan else if pivoth[1] or pivotl [1] then bearstruct1[1] + 1 else bearstruct1[1],double.nan);

def bup1 = if bullstruct1 == 1 and pivotl then low else bup1[1];

def bup2 = if bullstruct1 == 2 and pivoth then high else bup2[1];

def bep1 = if bearstruct1 == 1 and pivoth then high else bep1[1];

def bep2 = if bearstruct1 == 2 and pivotl then low else bep2[1];

plot usupport = if bullstruct1 then bup1 else double.nan;

usupport.SetDefaultColor(Color.CYAN);

usupport.SetLineWeight(2);

usupport.SetStyle(Curve.SHORT_DASH);

plot uresistance = if bullstruct1 then bup2 else double.nan;

uresistance.SetDefaultColor(Color.CYAN);

uresistance.SetLineWeight(2);

uresistance.SetStyle(Curve.SHORT_DASH);

plot esupport = if bearstruct1 then bep1 else double.nan;

esupport.SetDefaultColor(Color.CYAN);

esupport.SetLineWeight(2);

esupport.SetStyle(Curve.SHORT_DASH);

plot eresistance = if bearstruct1 then bep2 else double.nan;

eresistance.SetDefaultColor(Color.CYAN);

eresistance.SetLineWeight(2);

eresistance.SetStyle(Curve.SHORT_DASH);

addcloud(usupport,uresistance ,color.gray,color.gray);

addcloud(esupport,eresistance ,color.gray,color.gray);

AddLabel(yes, " PivotSelection: ( " + choose

+" ) ProjectSelecton: ( " + selectprojvalues

+" ) Projectvalues: ( " + projectionOrder

+" ) 1rstPcount: ( " + pivotcal

+" ) 2ndPcount: ( " + pivotcal2nd

+" ) 3rdPcount: ( " + pivotcal3rd +")"

, Color.WHITE);

39 Views
Brain with financial data analysis.

Inquiries at :

tel#: (843) 321-8514

Important Risk Notice: Trading involves substantial risk of loss. This is educational content only—not advice. Full details here  ------------>  

Proceed only if you're prepared.

bottom of page