Wednesday, December 28, 2011

ThinkScript Included: Money Flow Index In A Chart Label

The Money Flow Index (MFI) is a momentum indicator illustrating the strength of money flowing into and out of a security measured on a 0-100 scale. It is also a good over-bought/sold indicator. MFI values over 80 are considered to be over-bought. Likewise, MFI values under 20 are considered to be over-sold. Great! But I don't want to do technical analysis on it and, thus, I wouldn't ordinarily have it on my chart because it consumes precious real-estate at the bottom of my chart, scrunching up the price bars. However, like Average True Range, I am mostly interested in the most recent value of the indicator, so I have written a chart-label study that presents a most-recent view of MFI in compactified form. Here's the picture of this study in action:

SPY With Money Flow Label In Upper Left Corner
The chart label presents the current value of the Money Flow Index followed by my trend indicator. The trend indication is the last two characters, in this case, ^^ (two up-carrots.) What that means is that the MFI has had two successive moves up. If there had been a down move in the MFI two days ago then a v (alas, there is no down-carrot in ASCII) would have appeared in the first position. Also, the grey coloration of the label means that the indicator is in the midrange area. If the MFI is below 20 then the label turns red and green for overbought when the MFI is above 80. Finally, if MFI has just crossed above oversold or crossed below overbought then the chart label is colored Orange.

Here's a picture of an equity displaying this cross-over signal:


FSLR with a Cross Above Oversold Event in the Money Flow label.

Here's the code:
###################################
# sdi_flow: Display Money Flow Index as chart label
#hint: Displays the MoneyFlowIndex as a color-coded chart label. Red=oversold, Grey=midrange, Green=overbought and Orange=crossover. rev: 1.0 http://www.smalldoginvestor.com/
# author: allen everhart
# date: 12DEC2011
# 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.
declare UPPER ;
input length = 14 ;
input overBought = 80 ;
input overSold = 20 ;

def bar = round(moneyFlowIndex(20,80,length,1),2) ;
def dir = bar-bar[1] ;

AddChartLabel(1,
  concat(concat(concat("FLO:", bar),
    if dir[1]>0 then "^" else if dir[1]<0 then"v" else "="),
    if dir>0 then "^" else if dir<0 then"v" else "="),
    if bar>overBought then color.GREEN
    else if bar<overSold then color.RED
    else if bar[1]>overBought then color.ORANGE
    else if bar[1]<oversold then color.ORANGE
    else color.GRAY
);

######################### 

No comments:

Post a Comment