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

horserider

Well-known member
VIP
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.
 

ThinkingVan

New member
VIP
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!
 

SleepyZ

Well-known member
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);
 
Solution

ThinkingVan

New member
VIP
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.

 

SleepyZ

Well-known member
Hey Sleepy
Thanks for taking time to develop the code. The stand-only works perfectly. The 1st one had some issues.


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);
 

Similar threads

Top