Friday, June 10, 2011

sdi_autofib

AutoFib shows you the Fibonacci retrace lines between the high/low on your chart so you don't have to draw these for every equity. The basic concept of this thinkScript was sent to me from a friend. I added a little of my own Kung-fu: choice of where to display the lines. In my version you can have the fib lines display on the right extension area (sideline) of the chart, which is where I prefer to see them, or overlaying the price bars in main chart, or both. Here's a picture of what I'm talking about:


SPY with autofib.
 So SPY has just completed a retrace to 23.6% below the high. This is considered a shallow retrace in the world of Fibonacci's. A more normal retracement would be to 38.2% below the high, a level around 123 and not seen since last November.


Here's the code for this study:

#########################
# sdi_autofib - show fib-retracements between chart high/low
# source: smalldoginvestor.blogspot.com
# author: allen everhart
# date: Aug 15, 2010
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale.
# Help me get the word out about my blog by keeping this header
# in place.
#hint: sdi_autofib shows the fibinacci retracement levels between the high/low of the chart. rev:1.2.1
# rev. 1.2: version info in hint. sidebar selection.
# rev. 1.2.1 refactored sidebar to sideline

#hint sideline: Yes displays the levels only on the right extension otherwise only on the main chart.
input sideline = no;


def f11 = 0.236;
def f12 = 0.382;
def f13 = 0.50;
def f14 = 0.618;
def f15 = 0.786;
def hh = HighestAll(high);
def ll = LowestAll(low);
plot H =
  if isnaN(close) && sideline then
    hh
  else if !isnaN(close) && !sideline then
    hh
  else
    double.NaN
;
plot L =
  if isnaN(close) && sideline then
    ll 
  else if !isnaN(close) && !sideline then
    ll
  else
    double.NaN
;
plot P236 =
  if isnaN(close) && sideline then
    hh - ((hh - ll) * f11)
  else if !isnaN(close) && !sideline then
    hh - ((hh - ll) * f11)
  else
    double.NaN
;
plot P382 =
  if isnaN(close) && sideline then
    hh - ((hh - ll) * f12)
  else if !isnaN(close) && !sideline then
    hh - ((hh - ll) * f12)
  else
    double.NaN
;
plot P50 =
  if isnaN(close) && sideline then
    hh - ((hh - ll) * f13)
  else if !isnaN(close) && !sideline then
    hh - ((hh - ll) * f13)
  else
    double.NaN
;
plot P618 =
  if isnaN(close) && sideline then
    hh - ((hh - ll) * f14)
  else if !isnaN(close) && !sideline then
    hh - ((hh - ll) * f14)
  else
    double.NaN
;
plot P781 =
  if isnaN(close) && sideline then
    hh - ((hh - ll) * f15)
  else if !isnaN(close) && !sideline then
    hh - ((hh - ll) * f15)
  else
    double.NaN
;

p236.SetDefaultColor(Color.lIGHT_GRAY);
p382.SetDefaultColor(Color.lIGHT_GRAY);
p50.SetDefaultColor(Color.ORANGE);
p618.SetDefaultColor(Color.lIGHT_GRAY);
p781.SetDefaultColor(Color.lIGHT_GRAY);
H.SetDefaultColor(Color.MAGENTA);
L.SetDefaultColor(Color.MAGENTA);
p236.SetStyle(Curve.LONG_DASH);
p382.SetStyle(Curve.LONG_DASH);
p50.SetStyle(Curve.LONG_DASH);
p618.SetStyle(Curve.LONG_DASH);
p781.SetStyle(Curve.LONG_DASH);
H.SetStyle(Curve.SHORT_DASH);
L.SetStyle(Curve.SHORT_DASH);
H.SetLineWeight(2);
L.SetLineWeight(2);
p50.SetLineWeight(2);
############################################### 

No comments:

Post a Comment