NexusFi: Find Your Edge


Home Menu

 





Static Autofib for yearly high and low..


Discussion in ThinkOrSwim

Updated
    1. trending_up 1,037 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread

Static Autofib for yearly high and low..

  #1 (permalink)
theasianwolf
hong kong
 
Posts: 7 since Mar 2018
Thanks Given: 0
Thanks Received: 1

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..

#hint: <b>Fibonacci Retracements</b>\nFibonacci retracements use horizontal lines to indicate areas of support or resistance at the key Fibonacci levels before it continues in the original direction. These levels are created by drawing a trendline between two extreme points and then dividing the vertical distance by the key Fibonacci ratios of: 23.6%, 38.2%, 50%, 61.8%, 78.6%, and 100%.


#hint Price: Price used in the alerts on crossing retracement lines. <b>(Default is Close)</b>
#hint onExpansion: Determines if the retracement lines are projected past the current bar into the right side expansion <b>(Default is Yes)</b>
#hint Extend_to_left: Determines if the retracement lines are extended to the left side of the chart. <b>(Default is No)</b>

#hint Coefficient0: Retracement Line 0: Retracement from the highest high to the lowest low.\n <b>(Default is 100%)</b>
#hint Coefficient_1: Retracement Line 1: Retracement from the highest high to the lowest low.\n <b>(Default is 78.6%)</b>
#hint Coefficient_2: Retracement Line 2: Retracement from the highest high to the lowest low.\n <b>(Default is 61.8%)</b>
#hint Coefficient_3: Retracement Line 3: Retracement from the highest high to the lowest low.\n <b>(Default is 50%)</b>
#hint Coefficient_4: Retracement Line 4: Retracement from the highest high to the lowest low.\n <b>(Default is 38.2%)</b>
#hint Coefficient_5: Retracement Line 5: Retracement from the highest high to the lowest low.\n <b>(Default is 23.6%)</b>
#hint Coefficient_6: Retracement Line 6: Retracement from the highest high to the lowest low.\n <b>(Default is 000%)</b>

#wizard input: Price
#wizard text: Inputs: Price:
#wizard input: onExpansion
#wizard text: onExpansion:
#wizard input: Extend_to_left
#wizard text: Extend_to_left:
#wizard input: Coefficient0
#wizard text: Coefficient0:
#wizard input: Coefficient_1
#wizard text: Coefficient_1:
#wizard input: Coefficient_2
#wizard text: Coefficient_2:
#wizard input: Coefficient_3
#wizard text: Coefficient_3:
#wizard input: Coefficient_4
#wizard text: Coefficient_4:
#wizard input: Coefficient_5
#wizard text: Coefficient_5:
#wizard input: Coefficient_6
#wizard text: Coefficient_6:

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, 252, period = agg);
def YearLow = Lowest(low, 252, period = agg);

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.AssignValueColor(Color.GRAY);
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);

plot Retracement1 = if downward and !onExpansion and !Extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then HighestAll((b + (range * coefficient_1))) else if upward and !Extend_to_left and !onExpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then HighestAll(a - (range * coefficient_1)) else if downward and onExpansion and !Extend_to_left and barnumber >= highnumberall then HighestAll((b + (range * coefficient_1))) else if upward and onExpansion and barnumber >= lownumberall and !Extend_to_left then HighestAll(a - (range * coefficient_1)) else if downward and !onExpansion and Extend_to_left and barnumber <= istodaybarnumber then HighestAll((b + (range * coefficient_1))) else if upward and Extend_to_left and !onExpansion and barnumber <= istodaybarnumber then HighestAll(a - (range * coefficient_1)) else if downward and onExpansion and Extend_to_left then HighestAll((b + (range * coefficient_1))) else if upward and onExpansion and Extend_to_left then HighestAll(a - (range * coefficient_1)) else Double.NaN;
Retracement1.AssignValueColor(Color.GRAY);
Retracement1.HideBubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement1, concat( "$", round(retracement1, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), Retracement1, Concat( (coefficient_1 * 100), "%"), Color.GRAY, yes);
AddChartBubble((upward and barnumber == lownumberall), Retracement1, Concat( (coefficient_1 * 30.0259), "%"), Color.GRAY, yes);

plot Retracement2 = if downward and !onExpansion and !Extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then HighestAll((b + (range * Coefficient_2))) else if upward and !Extend_to_left and !onExpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then HighestAll(a - (range * Coefficient_2)) else if downward and onExpansion and !Extend_to_left and barnumber >= highnumberall then HighestAll((b + (range * Coefficient_2))) else if upward and onExpansion and barnumber >= lownumberall and !Extend_to_left then HighestAll(a - (range * Coefficient_2)) else if downward and !onExpansion and Extend_to_left and barnumber <= istodaybarnumber then HighestAll((b + (range * Coefficient_2))) else if upward and Extend_to_left and !onExpansion and barnumber <= istodaybarnumber then HighestAll(a - (range * Coefficient_2)) else if downward and onExpansion and Extend_to_left then HighestAll((b + (range * Coefficient_2))) else if upward and onExpansion and Extend_to_left then HighestAll(a - (range * Coefficient_2)) else Double.NaN;
Retracement2.AssignValueColor(Color.GRAY);
Retracement2.HideBubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement2, concat( "$", round(retracement2, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), Retracement2, Concat( (Coefficient_2 * 100), "%"), Color.GRAY, yes);
AddChartBubble((upward and barnumber == lownumberall), Retracement2, Concat( (Coefficient_2 * 61.815), "%"), Color.GRAY, yes);


plot Retracement3 = if downward and !onExpansion and !Extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then HighestAll((b + (range * Coefficient_3))) else if upward and !Extend_to_left and !onExpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then HighestAll(a - (range * Coefficient_3)) else if downward and onExpansion and !Extend_to_left and barnumber >= highnumberall then HighestAll((b + (range * Coefficient_3))) else if upward and onExpansion and barnumber >= lownumberall and !Extend_to_left then HighestAll(a - (range * Coefficient_3)) else if downward and !onExpansion and Extend_to_left and barnumber <= istodaybarnumber then HighestAll((b + (range * Coefficient_3))) else if upward and Extend_to_left and !onExpansion and barnumber <= istodaybarnumber then HighestAll(a - (range * Coefficient_3)) else if downward and onExpansion and Extend_to_left then HighestAll((b + (range * Coefficient_3))) else if upward and onExpansion and Extend_to_left then HighestAll(a - (range * Coefficient_3)) else Double.NaN;
Retracement3.AssignValueColor(Color.BLUE);
Retracement3.HideBubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement3, concat( "$", round(retracement3, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), Retracement3, Concat( (Coefficient_3 * 100), "%"), Color.BLUE, yes);
AddChartBubble((upward and barnumber == lownumberall), Retracement3, Concat( (Coefficient_3 * 100), "%"), Color.BLUE, yes);


plot Retracement4 = if downward and !onExpansion and !Extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then HighestAll((b + (range * Coefficient_4))) else if upward and !Extend_to_left and !onExpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then HighestAll(a - (range * Coefficient_4)) else if downward and onExpansion and !Extend_to_left and barnumber >= highnumberall then HighestAll((b + (range * Coefficient_4))) else if upward and onExpansion and barnumber >= lownumberall and !Extend_to_left then HighestAll(a - (range * Coefficient_4)) else if downward and !onExpansion and Extend_to_left and barnumber <= istodaybarnumber then HighestAll((b + (range * Coefficient_4))) else if upward and Extend_to_left and !onExpansion and barnumber <= istodaybarnumber then HighestAll(a - (range * Coefficient_4)) else if downward and onExpansion and Extend_to_left then HighestAll((b + (range * Coefficient_4))) else if upward and onExpansion and Extend_to_left then HighestAll(a - (range * Coefficient_4)) else Double.NaN;
Retracement4.AssignValueColor(Color.YELLOW);
Retracement4.HideBubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement4, concat( "$", round(retracement4, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), Retracement4, Concat( (Coefficient_4 * 100), "%"), Color.YELLOW, yes);
AddChartBubble((upward and barnumber == lownumberall), Retracement4, Concat( (Coefficient_4 * 161.8), "%"), Color.YELLOW, yes);

plot Retracement5 = if downward and !onExpansion and !Extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then HighestAll((b + (range * Coefficient_5))) else if upward and !Extend_to_left and !onExpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then HighestAll(a - (range * Coefficient_5)) else if downward and onExpansion and !Extend_to_left and barnumber >= highnumberall then HighestAll((b + (range * Coefficient_5))) else if upward and onExpansion and barnumber >= lownumberall and !Extend_to_left then HighestAll(a - (range * Coefficient_5)) else if downward and !onExpansion and Extend_to_left and barnumber <= istodaybarnumber then HighestAll((b + (range * Coefficient_5))) else if upward and Extend_to_left and !onExpansion and barnumber <= istodaybarnumber then HighestAll(a - (range * Coefficient_5)) else if downward and onExpansion and Extend_to_left then HighestAll((b + (range * Coefficient_5))) else if upward and onExpansion and Extend_to_left then HighestAll(a - (range * Coefficient_5)) else Double.NaN;
Retracement5.AssignValueColor(Color.GRAY);
Retracement5.HideBubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement5, concat( "$", round(retracement5, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), Retracement5, Concat( (Coefficient_5 * 100), "%"), Color.GRAY, yes);
AddChartBubble((upward and barnumber == lownumberall), Retracement5, Concat( (Coefficient_5 * 333.1), "%"), Color.GRAY, yes);


plot Retracement6 = if downward and !onExpansion and !Extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then HighestAll((b + (range * Coefficient_6))) else if upward and !Extend_to_left and !onExpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then HighestAll(a - (range * Coefficient_6)) else if downward and onExpansion and !Extend_to_left and barnumber >= highnumberall then HighestAll((b + (range * Coefficient_6))) else if upward and onExpansion and barnumber >= lownumberall and !Extend_to_left then HighestAll(a - (range * Coefficient_6)) else if downward and !onExpansion and Extend_to_left and barnumber <= istodaybarnumber then HighestAll((b + (range * Coefficient_6))) else if upward and Extend_to_left and !onExpansion and barnumber <= istodaybarnumber then HighestAll(a - (range * Coefficient_6)) else if downward and onExpansion and Extend_to_left then HighestAll((b + (range * Coefficient_6))) else if upward and onExpansion and Extend_to_left then HighestAll(a - (range * Coefficient_6)) else Double.NaN;
Retracement6.AssignValueColor(Color.GRAY);
Retracement6.HideBubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement6, concat( "$", round(retracement6, 2)), color.red, yes);

AddChartBubble((downward and barnumber == highnumberall), Retracement6, Concat( (Coefficient_6 * 100), "%"), Color.RED, yes);
AddChartBubble((upward and barnumber == lownumberall), Retracement6, Concat( (Coefficient_6 * 0), "%"), Color.RED, yes);


Alert((price crosses below Retracement0) , "Price crosses below Retracement Line 0");
Alert((price crosses above Retracement0) , "Price crosses above Retracement Line 0");
Alert((price crosses below Retracement1) , "Price crosses below Retracement Line 1");
Alert((price crosses above Retracement1) , "Price crosses above Retracement Line 1");
Alert((price crosses below Retracement2) , "Price crosses below Retracement Line 2");
Alert((price crosses above Retracement2) , "Price crosses above Retracement Line 2");
Alert((price crosses below Retracement3) , "Price crosses below Retracement Line 3");
Alert((price crosses above Retracement3) , "Price crosses above Retracement Line 3");
Alert((price crosses below Retracement4) , "Price crosses below Retracement Line 4");
Alert((price crosses above Retracement4) , "Price crosses above Retracement Line 4");
Alert((price crosses below Retracement5) , "Price crosses below Retracement Line 5");
Alert((price crosses above Retracement5) , "Price crosses above Retracement Line 5");
Alert((price crosses below Retracement6) , "Price crosses below Retracement Line 6");
Alert((price crosses above Retracement6) , "Price crosses above Retracement Line 6");


So far it doesn’t plot the fib from yearly high or Low.. I think it’s my aggregation period that is wrong..

Sorry a newbie in coding..

Can anyone guide me in the correct direction?

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trend Direction Force Index (TDFI)
Platforms and Indicators
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
What broker to use for trading palladium futures
Commodities
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
  #2 (permalink)
theasianwolf
hong kong
 
Posts: 7 since Mar 2018
Thanks Given: 0
Thanks Received: 1

Anyone able to help?

Reply With Quote




Last Updated on May 18, 2018


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts