Static Autofib for yearly high and low..


Tags:
Category:
0
0

Hi guys,

Anyone able to help for this..

Am trying to create a script that will plot the yearly Fibonacci levels on your chart no matter what timeframe you are on..

input price = close;
input high = high;
input low = low;
input onExpansion = Yes;
input Extend_to_left = no;
input Coefficient0 = .00;
input coefficient_1 = .786;
input Coefficient_2 = .618;
input Coefficient_3 = .50;
input Coefficient_4 = .382;
input Coefficient_5 = .236;
input Coefficient_6 = 1.000;

def agg = AggregationPeriod.DAY;
def YearHigh = highest(high(period = “Day”)[1], 252);
def YearLow = lowest(low(period = “Day”)[1], 252);

def a = HighestAll(YearHigh);
def b = LowestAll(YearLow);
def barnumber = BarNumber();
def c = if YearHigh == a then barnumber else Double.NaN;
def d = if YearLow == b then barnumber else Double.NaN;
rec highnumber = CompoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = HighestAll(highnumber);
rec lownumber = CompoundValue(1, if IsNaN(d) then lownumber[1] else d, d);
def lownumberall = LowestAll(lownumber);

def upward = highnumberall > lownumberall;
def downward = highnumberall < lownumberall;

def x = AbsValue(lownumberall – highnumberall );

def slope = (a – b) / x;
def slopelow = (b – a) / x;

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);

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;

plot FibFan = if downward then currentlinelow else if upward then currentline else Double.NaN;
FibFan.SetStyle(Curve.SHORT_DASH);
FibFan.AssignValueColor(Color.RED);
FibFan.HideBubble();

def range = a – b;

plot Retracement0 = if downward and !onExpansion and !Extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then HighestAll((b + (range * Coefficient0))) else if upward and !Extend_to_left and !onExpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then HighestAll(a – (range * Coefficient0)) else if downward and onExpansion and !Extend_to_left and barnumber >= highnumberall then HighestAll((b + (range * Coefficient0))) else if upward and onExpansion and barnumber >= lownumberall and !Extend_to_left then HighestAll(a – (range * Coefficient0)) else if downward and !onExpansion and Extend_to_left and barnumber <= istodaybarnumber then HighestAll((b + (range * Coefficient0))) else if upward and Extend_to_left and !onExpansion and barnumber <= istodaybarnumber then HighestAll(a – (range * Coefficient0)) else if downward and onExpansion and Extend_to_left then HighestAll((b + (range * Coefficient0))) else if upward and onExpansion and Extend_to_left then HighestAll(a – (range * Coefficient0)) else Double.NaN;

Retracement0.HideBubble();
#AddChartBubble((barnumber == istodaybarnumber +10), retracement0, concat( “$”, round(retracement0, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), Retracement0, Concat( (Coefficient0 * 100), “%”), Color.RED, yes);
AddChartBubble((upward and barnumber == lownumberall), Retracement0, Concat( (Coefficient0 * 1), “100%”), Color.RED, yes);

I WAS NOT ABLE TO POST FULL CODE HERE SI ATTACHING A TEXT FILE WITH FULL CODE

Sorry a newbie in coding..
Can anyone guide me in the correct direction?

Attachments:
Marked as spam
Posted by (Questions: 4, Answers: 7)
Asked on January 20, 2019 12:01 pm
161 views
0
Private answer

The solution to this is likely far beyond the scope of the free assistance we provide here in the Q&A forum. My general rule of thumb is that if I don’t have a solution in 15 minutes, the request is beyond that scope. Judging from the number of lines of code this may take hours to unravel.

If interested, you are welcome to submit this as a custom project request. You can view our rates and other details here: https://www.hahn-tech.com/about/

 

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on January 21, 2019 9:18 am