Just looking for hopefully a simple mod to this script. I am looking for this tool to plot the bodies of the candles at the highs and the bodies of the candles at the lows instead of the upper and lower wicks as this is where the most volume is?
Code:
# Fibonacci Lines From Pivots
# Mobius
# V01.02.2013
# Other technical studies can be found on MyTrade: Mobius
declare Once_per_bar;
input numBars = 55; #hint numbars: Second Wave suggested 21, 34, 55, 89, 144
input showValues = no; #hint showValues: User choice
input showBarNumbers = no; #hint showBarNumbers: User choice
input TrendResistanceStart = 0; #hint TrendResistanceStart: User input value
input TrendResistanceEnd = 0; #hint TrendResistanceEnd: User input value
input TrendSupportStart = 0; #hint TrednSupportStart: User input value
input TrendSupportEnd = 0; #hint TrendSupportEnd: User input value
input BubbleOn = yes; #hint BubbleOn: User choice
# Study Definitions
def o = open;
def h = high;
def l = low;
def c = close;
def bar = BarNumber();
def yearstart = GetYear() * 10000 + 101;
def tradingDays = CountTradingDays(yearstart, GetYYYYMMDD());
def Coeff_1 = .236;
def Coeff_2 = .382;
def Coeff_3 = .500;
def Coeff_4 = .618;
def Coeff_5 = .786;
# First Wave Fibonacci Retracement
script Fibs {
input C0 = 0.000;
def o = open;
def h = high;
def l = low;
# Get highest and lowest on chart
def a = HighestAll(h);
def b = LowestAll(l);
# Get the bar numbers at the highest and lowest points
def barnumber = BarNumber();
def c = if h == a
then barnumber
else Double.NaN;
def d = if l == b
then barnumber
else Double.NaN;
def highnumber = CompoundValue(1, if IsNaN(c)
then highnumber[1]
else c, c);
def highnumberall = HighestAll(highnumber);
def lownumber = CompoundValue(1, if IsNaN(d)
then lownumber[1]
else d, d);
def lownumberall = LowestAll(lownumber);
# Determine Slope Delta
def upward = highnumberall > lownumberall;
def downward = highnumberall < lownumberall;
# Define X
def x = AbsValue(lownumberall - highnumberall );
# Get Slope for either direction
def slope = (a - b) / x;
def slopelow = (b - a) / x;
# Get Day
def day = GetDay();
def month = GetMonth();
def year = GetYear();
def lastDay = GetLastDay();
def lastmonth = GetLastMonth();
def lastyear = GetLastYear();
def isToday = If(day == lastDay and
month == lastmonth and
year == lastyear, 1, 0);
def istodaybarnumber = HighestAll(if isToday
then barnumber
else Double.NaN);
# Calculations for line between extremes
def line = b + (slope * (barnumber - lownumber));
def linelow = a + (slopelow * (barnumber - highnumber));
def currentlinelow = if barnumber <= lownumberall
then linelow
else Double.NaN;
def currentline = if barnumber <= highnumberall
then line
else Double.NaN;
def FibFan = if downward
then currentlinelow
else if upward
then currentline
else Double.NaN;
# Rise of line between Extremes
def range = a - b;
plot Fib1 = fold i = 1 to 100
with p = FibFan
while (downward and
barnumber >= highnumberall and
barnumber <= istodaybarnumber)
or
(upward and
barnumber >= lownumberall and
barnumber <= istodaybarnumber)
do if downward
then HighestAll((b + (range * C0)))
else if upward
then HighestAll(a - (range * C0))
else Double.NaN;
}
# Start Plot Sequence
input C0 = 0.000;
input C1 = .236;
input C2 = .382;
input C3 = .500;
input C4 = .618;
input C5 = .786;
input C6 = 1.000;
def TotalBars = HighestAll(bar);
def HHbar = if high == highestAll(high)
then bar
else HHbar[1];
def LLbar = if low == lowestAll(low)
then bar
else LLbar[1];
def firstBar = if HHbar > LLbar
then LLbar
else if HHbar < LLbar
then HHbar
else Double.NaN;
def BubbleLocation = bar == HighestAll(firstbar);
plot fib1 = Round(fibs(C0 = C0), 3);
fib1.SetDefaultColor(Color.Red);
AddChartBubble((if BubbleOn then BubbleLocation else double.nan), fib1
, (c0 * 100) + "% $" + fib1, color.gray, yes);
plot fib2 = Round(fibs(C0 = C1), 3);
fib2.SetDefaultColor(Color.Red);
AddChartBubble((if BubbleOn then BubbleLocation else double.nan), fib2
, (c1 * 100) + "% $" + fib2, color.gray, yes);
plot fib3 = Round(fibs(C0 = C2), 3);
fib3.SetDefaultColor(Color.Red);
AddChartBubble((if BubbleOn then BubbleLocation else double.nan), fib3
, concat( (c2 * 100), "%"), color.gray, yes);
plot fib4 = Round(fibs(C0 = C3), 3);
fib4.SetDefaultColor(Color.Red);
AddChartBubble((if BubbleOn then BubbleLocation else double.nan), fib4
, (c3 * 100) + "% $" + fib4, color.gray, yes);
plot fib5 = Round(fibs(C0 = C4), 3);
fib5.SetDefaultColor(Color.Red);
AddChartBubble((if BubbleOn then BubbleLocation else double.nan), fib5
, (c4 * 100) + "% $" + fib5 , color.gray, yes);
plot fib6 = Round(fibs(C0 = C5), 3);
fib6.SetDefaultColor(Color.Red);
AddChartBubble((if BubbleOn then BubbleLocation else double.nan), fib6
, (c5 * 100) + "% $" + fib6, color.gray, yes);
plot fib7 = Round(fibs(C0 = C6), 3);
fib7.SetDefaultColor(Color.Red);
AddChartBubble((if BubbleOn then BubbleLocation else double.nan), fib7
, (c6 * 100) + "% $" + fib7, color.gray, yes);
# Second Wave Fib Series
def UserSetResistance = TrendResistanceStart > 0 and
TrendResistanceEnd > 0;
def UserSetSupport = TrendSupportStart > 0 and
TrendSupportEnd > 0;
def PH;
def PL;
def isHigherThanNextBars = fold i = 1 to numBars + 1
with p = 1
while p
do h > GetValue(h, -i);
PH = if UserSetResistance and
( bar == TrendResistanceStart or
bar == TrendResistanceEnd )
then h
else if !UserSetResistance and
(bar > numBars and
h == Highest(h, numBars) and
isHigherThanNextBars)
then h
else Double.NaN;
def isLowerThanNextBars = fold j = 1 to numBars + 1
with q = 1
while q
do l < GetValue(low, -j);
PL = if UserSetSupport and
( bar == TrendSupportStart or
bar == TrendSupportEnd )
then l
else if !UserSetSupport and
(bar > numBars and
l == Lowest(l, numBars) and
isLowerThanNextBars)
then l
else Double.NaN;
def PHBar = if UserSetResistance
then TrendResistanceEnd
else if !IsNaN(PH)
then bar
else PHBar[1];
def PLBar = if UserSetSupport
then TrendSupportEnd
else if !IsNaN(PL)
then bar
else PLBar[1];
def PHL = if !IsNaN(PH)
then PH
else PHL[1];
def priorPHBar = if UserSetResistance
then TrendResistanceStart
else if PHL != PHL[1]
then PHBar[1]
else priorPHBar[1];
def PLL = if !IsNaN(PL)
then PL
else PLL[1];
def priorPLBar = if UserSetSupport
then TrendSupportStart
else if PLL != PLL[1]
then PLBar[1]
else priorPLBar[1];
def isFinalTwoHighPivots = bar >= HighestAll(priorPHBar);
def isFinalTwoLowPivots = bar >= HighestAll(priorPLBar);
def ResistanceFinishOffset = if isFinalTwoHighPivots
then bar - PHBar
else 0;
def ResistanceStartOffset = if isFinalTwoHighPivots
then bar - priorPHBar
else 0;
def ResistanceSlope = (GetValue(PH, ResistanceFinishOffset) -
GetValue(PH, ResistanceStartOffset)) /
(PHBar - priorPHBar);
def SupportFinishOffset = if isFinalTwoLowPivots
then bar - PLBar
else 0;
def SupportStartOffset = if isFinalTwoLowPivots
then bar - priorPLBar
else 0;
def SupportSlope = (GetValue(PL, SupportFinishOffset) -
GetValue(PL, SupportStartOffset)) /
(PLBar - priorPLBar);
def ResistanceExtend = if bar == HighestAll(PHBar)
then 1
else ResistanceExtend[1];
def SupportExtend = if bar == HighestAll(PLBar)
then 1
else SupportExtend[1];
plot pivotHigh = if isFinalTwoHighPivots
then PH
else Double.NaN;
def pivotHighLine = if PHL > 0 and
isFinalTwoHighPivots
then PHL
else double.NaN;
plot ResistanceLine = pivotHigh;
plot ResistanceExtension = if ResistanceExtend
then (bar - PHBar) * ResistanceSlope + PHL
else Double.NaN;
plot pivotLow = if isFinalTwoLowPivots
then PL
else Double.NaN;
def pivotLowLine = if PLL > 0 and
isFinalTwoLowPivots
then PLL
else double.NaN;
plot SupportLine = pivotLow;
plot SupportExtension = if SupportExtend
then (bar - PLBar) * SupportSlope + PLL
else Double.NaN;
plot BN = bar;
plot A_H = if isNaN(PivotHighline)
then PivotHighLine[1]
else HighestAll(PivotHighLine);
A_H.SetDefaultColor(Color.Yellow);
plot X_L = if isNaN(PivotLowLine)
then PivotLowLine[1]
else LowestAll(PivotLowLine);
X_L.SetDefaultColor(Color.Yellow);
def A = A_H;
def B = X_L;
def X = ( ((c - X_L) / (A_H - X_L))) + c;
plot SeventyEight = (((a - b) * Coeff_5) + B);
plot SixtyOne = (((a - B) * Coeff_4) + B);
plot Fifty = (a + B) * Coeff_3;
plot ThirtyEight = ((a - B) * Coeff_2) + B;
plot TwentyThree = ((a - B) * Coeff_1) + B;
pivotHigh.SetDefaultColor(Color.Yellow);
pivotHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
pivotHigh.SetHiding(!showValues);
pivotLow.SetDefaultColor(Color.Yellow);
pivotLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
pivotLow.SetHiding(!showValues);
ResistanceLine.EnableApproximation();
ResistanceLine.SetDefaultColor(GetColor(5));
ResistanceExtension.SetDefaultColor(GetColor(5));
SupportLine.EnableApproximation();
SupportLine.SetDefaultColor(GetColor(5));
SupportExtension.SetDefaultColor(GetColor(5));
BN.SetDefaultColor(GetColor(0));
BN.SetHiding(!showBarNumbers);
BN.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
SeventyEight.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
SeventyEight.SetDefaultColor(Color.Yellow);
SixtyOne.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
SixtyOne.SetDefaultColor(Color.Yellow);
Fifty.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Fifty.SetDefaultColor(Color.Yellow);
ThirtyEight.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ThirtyEight.SetDefaultColor(Color.Yellow);
TwentyThree.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TwentyThree.SetDefaultColor(Color.Yellow);
AddChartBubble(if BubbleOn then isNaN(close[10]) and !isNaN(close[11]) else double.nan,
A_H,
"Fib " + 1,
color.yellow,
yes);
AddChartBubble(if BubbleOn then isNaN(close[10]) and !isNaN(close[11]) else double.nan,
SeventyEight,
"Fib " + Coeff_5,
color.yellow,
yes);
AddChartBubble(if BubbleOn then isNaN(close[10]) and !isNaN(close[11]) else double.nan,
SixtyOne,
"Fib " + Coeff_4,
color.yellow,
yes);
AddChartBubble(if BubbleOn then isNaN(close[10]) and !isNaN(close[11]) else double.nan,
Fifty,
"Fib " + Coeff_3,
color.yellow,
yes);
AddChartBubble(if BubbleOn then isNaN(close[10]) and !isNaN(close[11]) else double.nan,
ThirtyEight,
"Fib " + Coeff_2,
color.yellow,
yes);
AddChartBubble(if BubbleOn then isNaN(close[10]) and !isNaN(close[11]) else double.nan,
TwentyThree,
"Fib " + Coeff_1,
color.yellow,
yes);
AddChartBubble(if BubbleOn then isNaN(close[10]) and !isNaN(close[11]) else double.nan,
X_L,
"Fib " + 0,
color.yellow,
yes);
# End Code
Last edited by a moderator: