Chaikin Money Flow Index Indicator

WayneG

New member
VIP
I'm modifying the standard Chaikin Money Flow Index according to it interpretation rules. The area between -0.05 to 0.05, the gray area, is considered to be a no mans land because of false signals. In the code I've written, see below, I am having trouble getting the red not to fill the gray to +0.5. I've tried several variation from different example, but I'm just no catching the hank of it.

Code:
declare lower;
input length = 21;
input upperLine = 1;
input lowerLine = -1;
input pgrayline = 0.05;
input ngrayline = -0.05;
def tmp_var =
if high == low then
  volume
else
  (close - low - (high - close)) / (high - low) * volume
;

def sum_close = Sum(tmp_var, length);
def total = Sum(volume, length);

plot CMF =
if total == 0 then
  0
else
  sum_close / total
;
CMF.SetDefaultColor(Color.BLACK);

plot ThirtyLine = .30;
ThirtyLine.SetDefaultColor(GetColor(5));

plot TwentyLine = -.20;
TwentyLine.SetDefaultColor(GetColor(5));

plot ngray = ngrayline;
ngray.SetDefaultColor(Color.GRAY);

plot pgray = pgrayline;
pgray.SetDefaultColor(Color.GRAY);


plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(5));


def BullPrice = ChaikinMoneyFlow(21);

def BearPrice = -chaikinMoneyFlow(21);
#
#THE NEXT TO LINES OF CODE ARE PROBLEM
#
AddCloud(BullPrice, 0.05 ,color.green, Color.red);
#AddCloud(BearPrice, -0.05, Color.red, Color.red);
#
#
#

AddCloud(ngrayline, pgrayline, Color.GRAY, Color.GRAY);

AddLabel( 1, "Short < -0.05 Long > 0.05 Gray area Choppy", Color.BLACK);

#end code

Thanks for you help,
Wayne
 

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

Messy but may do.

Code:
plot ngray = .05;
ngray.SetDefaultColor(Color.GRAY);

plot pgray = -.05;
pgray.SetDefaultColor(Color.GRAY);

#
#THE NEXT TO LINES OF CODE ARE PROBLEM
#
AddCloud(cmf, ngray, color.green, Color.pink);
AddCloud(cmf, pgray, color.pink, Color.pink);
#
#

AddCloud(ngray, pgray, Color.DARK_RED, Color.DARK_RED);

AddLabel( 1, "Short < -0.05 Long > 0.05 Gray area Choppy", Color.BLACK);

#end code
 
Try this:

Code:
#THE NEXT TO LINES OF CODE ARE PROBLEM

plot uppercmf = if cmf > .05 then cmf else double.nan;
uppercmf.hide();
plot lowercmf = if cmf < -.05 then cmf else double.nan;
lowercmf.hide();
AddCloud(uppercmf, pgray ,color.green, Color.green);
AddCloud(lowercmf, ngray, Color.red, Color.red);
#
#
#

AddCloud(ngrayline, pgrayline, Color.GRAY, Color.GRAY);

AddLabel( 1, "Short < -0.05 Long > 0.05 Gray area Choppy", Color.BLACK);

#end code

You lose some shading on the edges when it dips above/below the .05/-.05 levels.
 
ChaikinMoneyFlow is helpful in finding strength or weakness in stocks or sectors. The following link will give you a visual impression of that.

https://stockcharts.com/freecharts/...,XLK,XLI,XLB,XLE,XLP,XLV,XLU,XLF,XLRE|B|C20|1

Can you please help in building a watchlist in thinkorswim platform that will display the parameters helpful in identifying the trend (hypothetical example given below)

symbol CMF

AAPL 0.3 ( bullish 10 bars)
MSFT 0.2 ( bullish 8 bars)
AMD 0.8 (bullish 3 bars)
NVDA 0.9 (bullish 1 bar)
AMZN -0.9 (bearish 1 bar)

I have the following thinkscript designed to show the CMF value with RED colour for bearish and green colour for bullish signal. I need help in counting the "bars ago" or number of bars.

plot CMF = ChaikinMoneyFlow();
AssignBackgroundColor(if CMF > 0 then Color.DARK_GREEN else if CMF < 0 then Color.DARK_RED else Color.Dark_ORANGE);
 
I left out the words bullish and bearish to conserve space since the colors and the CMF value already indicate the direction.

Ruby:
def CMF = ChaikinMoneyFlow();

def bullCount = if CMF > 0 then if IsNaN(bullCount[1]) then 1 else bullCount[1] + 1 else 0;
def bearCount = if CMF < 0 then if IsNaN(bearCount[1]) then 1 else bearCount[1] + 1 else 0;
def count = Max(bullCount, bearCount);

AddLabel(yes, Round(CMF, 1) + " (" + count + " bars)");

AssignBackgroundColor(
  if CMF > 0 then Color.DARK_GREEN
  else if CMF < 0 then Color.DARK_RED
  else Color.DARK_ORANGE
);
 
Hey all, can someone make a label code for Chaikin Money Flow? I've tried, but failed. I'm not that good with coding.
Basic Label: If it passes zeroline going up, color.GREEN or UPTICK... If it passes zeroline going down, color.RED or UPTICK... Text- CMF: Numerical Value
Thanks in advance. I appreciate it!
 
Hey all, can someone make a label code for Chaikin Money Flow? I've tried, but failed. I'm not that good with coding.
Basic Label: If it passes zeroline going up, color.GREEN or UPTICK... If it passes zeroline going down, color.RED or UPTICK... Text- CMF: Numerical Value
Thanks in advance. I appreciate it!
Here are 2 versions based upon your criteria. The first one will only show the color to green/red at the bar where the cross occurred, and white when there is not a cross. The second one will not only show the cross color, it will maintain that color until a cross in the opposite direction.

Add the label codes that you choose to the bottom of a copy of the TOS Chaikin Money Flow Indicator

Code:
#1 cross bar
addlabel(1,"CMF",if cmf crosses above 0 then color.green else if cmf crosses below 0 then color.red else color.white);
#2 aboe/below zero
addlabel(1,"CMF",if cmf > 0 then color.green else color.red);

Here is a stand alone version that you could use to display the labels in the upper price panel.

Ruby:
def cmf = reference chaikinMoneyFlow().cmf;

#1 cross bar
addlabel(1,"CMF",if cmf crosses above 0 then color.green else if cmf crosses below 0 then color.red else color.white);
#2 aboe/below zero
addlabel(1,"CMF",if cmf > 0 then color.green else color.red);
 
Here are 2 versions based upon your criteria. The first one will only show the color to green/red at the bar where the cross occurred, and white when there is not a cross. The second one will not only show the cross color, it will maintain that color until a cross in the opposite direction.

Add the label codes that you choose to the bottom of a copy of the TOS Chaikin Money Flow Indicator



Here is a stand alone version that you could use to display the labels in the upper price panel.
Hey Sleepy
Thanks for taking time to develop the code. The stand-only works perfectly. The 1st one had some issues.

https%3A//i.imgur.com/6UbSHpd.png[/img]']
6UbSHpd.png
 
Hey Sleepy
Thanks for taking time to develop the code. The stand-only works perfectly. The 1st one had some issues.

https%3A//i.imgur.com/6UbSHpd.png[/img]']
6UbSHpd.png

Both sets of code worked. The first set had to be added to the TOS version of Chaikin Money flow. See original post.

Here is the first code added to the TOS version

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2021
#

declare lower;
input length = 21;

def tmp_var =
if high == low then
  volume
else
  (close - low - (high - close)) / (high - low) * volume
;

def sum_close = sum(tmp_var, length);
def total = sum(volume, length);

plot CMF =
if total == 0 then
  0
else
  sum_close / total
;
CMF.SetDefaultColor(GetColor(1));

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(5));

#1 cross bar
addlabel(1,"CMF",if cmf crosses above 0 then color.green else if cmf crosses below 0 then color.red else color.white);
#2 aboe/below zero
addlabel(1,"CMF",if cmf > 0 then color.green else color.red);
 
Mobius version of the Chaiken Oscillator
# Chaikin Oscillator with signal lines
# Mobius
# V01.20138

declare lower;

input longLength = 10;
input shortLength = 3;

def h = high;
def l = low;
def c = close;
def v = volume;
def CLV = if h != l then ((c - l) - (h - c)) / (h - l) else 1;
def AccDist = totalSum(v * CLV);
plot COSC = ExpAverage(AccDist, shortLength) - ExpAverage(AccDist, longLength);
plot ZeroLine = 0;
plot avgLongCOSC = Average(COSC, longLength);
plot avgShortCOSC = Average(COSC, shortLength);
COSC.SetDefaultColor(GetColor(1));
ZeroLine.SetDefaultColor(GetColor(5));
plot ArrowUP = if(COSC < 0 and avgShortCOSC crosses above avgLongCOSC, avgShortCOSC, double.nan);
ArrowUp.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
ArrowUP.SetLineWeight(3);
ArrowUP.SetDefaultColor(Color.Green);
plot ArrowDN = if(COSC > 0 and avgShortCOSC crosses below avgLongCOSC, avgShortCOSC, double.nan);
ArrowDN.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
ArrowDN.SetLineWeight(3);
ArrowDN.SetDefaultColor(Color.RED);
AddCloud(avgLongCOSC, avgShortCOSC, color.red, color.green);
# End Code
 
Hi MerryDay and thanks for the post! I am 95% code illiterate, could you briefly cover the criteria of the Mobius version of the Chaikin Oscillator? Of course it has the arrows for directional bias but it helps to thoroughly understand the indicator. What makes it different? Are the differences better than the original? etc.
 
Hi MerryDay and thanks for the post! I am 95% code illiterate, could you briefly cover the criteria of the Mobius version of the Chaikin Oscillator? Of course it has the arrows for directional bias but it helps to thoroughly understand the indicator. What makes it different? Are the differences better than the original? etc.
I wouldn't think that there are any huge "differences". Chaiken has a standard definition across all versions written.
Most of the customizations of standard indicators on this forum are formatting and coloring variations that assist some members get a better read on their charts.

Put them both on your chart. See if the variations in formatting help you.
To determine if this indicator brings value, analyze it over different timeframes, across history and with multiple instruments.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
445 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