multiple fib fans

Mercury

New member
Using the code below I would like to know how I can incorperate the fib fan drawing from when an indicator value is one, drawn to the next time the indicators value is one. Right now the code is drawing only one fan from the lowest point to the highest point. Idealy would create multiple fib fans between each time the condition is met.

Code:
input price = close;

input high = high;

input low = low;

input onExpansion = Yes;

input Coefficient1 = .382;

input Coefficient_2 = .5;

input Coefficient_3 = .618;

def a = HighestAll(high);

def b = LowestAll(low);

def barnumber = barNumber();

def c = if high == a then barnumber else double.nan;

def d = if low == 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 low382 =  b + ((b - a) * Coefficient1);

def low5 =  b + ((b - a) * Coefficient_2);

def low618 = b + ((b - a) * Coefficient_3);

 

def high382 =  a - ((a - b) * Coefficient1);

def high5 =  a - ((a - b) * Coefficient_2);

def high618 = a - ((a - b) * Coefficient_3);

 

def x = AbsValue(lownumberall - highnumberall );

 

def slope = (a - b) / x;

def slope382 = (high382 - b) / x;

def slope5 = (high5 - b) / x;

def slope618 = (high618 - b) / x;

 

def slopelow = (b - a) / x;

def slopelow382 = (low382 - b) / x;

def slopelow5 = (low5 - b) / x;

def slopelow618 = (low618 - b) / 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 line382 = b + (slope382 * (barnumber - lownumber));

def line5 = b + (slope5 * (barnumber - lownumber));

def line618 = b + (slope618 * (barnumber - lownumber));

 

def linelow = a + (slopelow * (barnumber - highnumber));

def line382low = a + (slopelow382 * (barnumber - highnumber));

def line5low = a + (slopelow5 * (barnumber - highnumber));

def line618low = a + (slopelow618 * (barnumber - highnumber));

 

def currentlinelow = if barnumber <= istodaybarnumber then linelow else double.nan;

def currentline382low = if barnumber <= istodaybarnumber then line382low else double.nan;

def currentline5low = if barnumber <= istodaybarnumber then line5low else double.nan;

def currentline618low = if barnumber <= istodaybarnumber then line618low else double.nan;

 

def currentline = if barnumber <= istodaybarnumber then line else double.nan;

def currentline382 = if barnumber <= istodaybarnumber then line382 else double.nan;

def currentline5 = if barnumber <= istodaybarnumber then line5 else double.nan;

def currentline618 = if barnumber <= istodaybarnumber then line618 else double.nan;

 

Plot FibFan =  if  downward and onExpansion then linelow else if downward then currentlinelow else if upward and onExpansion then line else if upward then currentline else double.nan;

FibFan.SetStyle(Curve.SHORT_DASH);

FibFan.AssignValueColor(color.red);

 

Plot "Coefficient 1" =  if (downward and onExpansion) then line382low else if downward then currentline382low else if upward and onExpansion then line382 else if upward then currentline382 else double.nan;

"Coefficient 1".SetStyle(Curve.Firm);

"Coefficient 1".AssignValueColor(color.red);

Plot "Coefficient 2" = if downward and onExpansion then line5low else if downward then currentline5low else if upward and onExpansion then line5 else if upward then currentline5 else double.nan;

"Coefficient 2".AssignValueColor(color.red);

"Coefficient 2".SetStyle(Curve.Firm);

Plot "Coefficient 3" =  if downward and onExpansion then line618low else if downward then currentline618low else if upward and onExpansion then line618 else if upward then currentline618  else double.nan;

"Coefficient 3".AssignValueColor(color.red);

"Coefficient 3".SetStyle(Curve.Firm);

alert((price crosses below "Coefficient 1") , "Price crosses below Coefficient 1");

alert((price crosses below "Coefficient 2") , "Price crosses below Coefficient 2");

alert((price crosses below "Coefficient 3") , "Price crosses below Coefficient 3");

alert((price crosses above "Coefficient 1") , "Price crosses above Coefficient 1");

alert((price crosses above "Coefficient 2") , "Price crosses above Coefficient 2");

alert((price crosses above "Coefficient 3") , "Price crosses above Coefficient 3");
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
342 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top