Twiggs Money Flow Indicator for ThinkorSwim

germanburrito

Active member
I seen people talk about the Twiggs Money Flow but I could not find it any where, so here is a version of it.

Code:
declare lower;
input periods = 21;
input over_Bought = .20;
input over_Sold = -.20;


def C = close;

def H = high;

def L = low;

def V = volume;

def TRH = Max(H,C[1]);

def TRL = Min(L, C[1]);

def TR = TRH - TRL;

def ADV =((C-TRL)-(TRH-C))/ (If TR == 0 then 999999 else TR) * V;

plot NewCMF = if WildersAverage(V,periods) == 0 

              then 0

              else WildersAverage(ADV, periods) / WildersAverage(V, periods);  

plot ZeroLine = 0;

ZeroLine.SetDefaultColor(GetColor(5));                 

plot OverSold = over_Sold;
plot OverBought = over_Bought;

NewCMF.DefineColor("OverBought", GetColor(5));
NewCMF.DefineColor("Normal", GetColor(7));
NewCMF.DefineColor("OverSold", GetColor(1));
NewCMF.AssignValueColor(if  NewCMF > over_Bought then  NewCMF.color("OverBought") else if  NewCMF < over_Sold then  NewCMF.color("OverSold") else  NewCMF.color("Normal"));
 
Last edited by a moderator:
Hello German,

I added a moving average to the CMF as a signal, also added a cloud

Code:
###################

declare lower;
input periods = 21;
Input LengthA = 5;
input over_Bought = .20;
input over_Sold = -.20;


def C = close;

def H = high;

def L = low;

def V = volume;

def TRH = Max(H,C[1]);

def TRL = Min(L, C[1]);

def TR = TRH - TRL;

def ADV =((C-TRL)-(TRH-C))/ (If TR == 0 then 999999 else TR) * V;

plot NewCMF = if WildersAverage(V,periods) == 0 

              then 0

              else WildersAverage(ADV, periods) / WildersAverage(V, periods); 
Plot NewCMFA = ExpAverage(NewCMF,LengthA); 
NewCMFA.SetDefaultColor(Color.Yellow);
plot ZeroLine = 0;
AddCloud(NewCMF,Zeroline,Color.Green,Color.Red);
ZeroLine.SetDefaultColor(color.gray);                 

plot OverSold = over_Sold;
OverSold.SetDefaultColor(Color.Orange);
OverSold.SetPaintingStrategy(PaintingStrategy.Dashes);
plot OverBought = over_Bought;
OverBought.SetDefaultColor(Color.Orange);
OverBought.SetPaintingStrategy(PaintingStrategy.Dashes);

NewCMF.DefineColor("OverBought", GetColor(5));
NewCMF.DefineColor("Normal", GetColor(7));
NewCMF.DefineColor("OverSold", GetColor(1));
NewCMF.AssignValueColor(if  NewCMF > over_Bought then  NewCMF.color("OverBought") else if  NewCMF < over_Sold then  NewCMF.color("OverSold") else  NewCMF.color("Normal"));
NewCMF.SetLineweight(3);

I have created your money flow indicator into a binary signal w 3 MTF. The triangles are Cyan if the MF is Bullish, Red when overbought, Magenta when Bearish and Green when oversold

Here is the code

Code:
##############
Declare Lower;
DefineGlobalColor("Bullish", Color.Cyan);
DefineGlobalColor("Bearish", Color.Magenta);
DefineGlobalColor("OverSold", Color.Green);
DefineGlobalColor("OverBought", Color.Red);
DefineGlobalColor("Normal", Color.Gray);

input agg1 = AggregationPeriod.FIVE_MIN;
input agg2 = AggregationPeriod.Thirty_MIN;
input agg3 = AggregationPeriod. Hour;
input periods = 21;
Input LengthA = 5;
input over_Bought = .20;
input over_Sold = -.20;
input show_dots=yes;
input DotSize = 3;

Def AC = Close(Period = Agg1);
Def BC = Close(Period = Agg2);
Def CC = Close(Period = Agg3);
Def AH = High(Period = Agg1);
Def BH = High(Period = Agg2);
Def CH = High(Period = Agg3);
Def AL = Low(Period = Agg1);
Def BL = Low(Period = Agg2);
Def CL = Low(Period = Agg3);
Def AV = Volume(Period = Agg1);
Def BV = Volume(Period = Agg2);
Def CV = Volume(Period = Agg3);

def ATRH = Max(AH,AC[1]);
def BTRH = Max(BH,BC[1]);
def CTRH = Max(CH,CC[1]);
def ATRL = Min(AL, AC[1]);
def BTRL = Min(BL, BC[1]);
def CTRL = Min(CL, CC[1]);

def TRa = ATRH - ATRL;
def TRb = BTRH - BTRL;
def TRc = CTRH - CTRL;

def AADV =((AC-ATRL)-(ATRH-AC))/ (If TRa == 0 then 999999 else TRa) * AV;
def BADV =((BC-BTRL)-(BTRH-BC))/ (If TRb == 0 then 999999 else TRb) * BV;
def CADV =((CC-CTRL)-(CTRH-CC))/ (If TRc == 0 then 999999 else TRc) * CV;

Def ANewCMF = if WildersAverage(AV,periods) == 0 
              then 0
              else WildersAverage(AADV, periods) / WildersAverage(AV, periods); 
Def BNewCMF = if WildersAverage(BV,periods) == 0 
              then 0
              else WildersAverage(BADV, periods) / WildersAverage(BV, periods); 
Def CNewCMF = if WildersAverage(CV,periods) == 0 
              then 0
              else WildersAverage(CADV, periods) / WildersAverage(CV, periods); 

Def ANewCMFA = ExpAverage(ANewCMF,LengthA);
Def BNewCMFA = ExpAverage(BNewCMF,LengthA); 
Def CNewCMFA = ExpAverage(CNewCMF,LengthA); 
Def ZeroLine = 0;
plot ANewCMF_Dot = if IsNaN(AC) then Double.NaN else 1;
ANewCMF_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
ANewCMF_Dot.SetLineWeight(DotSize);
ANewCMF_Dot.AssignValueColor(if ANewCMF> Over_Bought && ANewCMF >ANewCMFA then GlobalColor("OverBought") else  if ANewCMF< Over_Sold && ANewCMF <ANewCMFA then GlobalColor("OverSold") else  if ANewCMF> ZeroLine then GlobalColor("Bullish") else If ANewCMF< ZeroLine then GlobalColor("Bearish") else GlobalColor(“Normal”));
plot BNewCMF_Dot = if IsNaN(BC) then Double.NaN else 2;
BNewCMF_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
BNewCMF_Dot.SetLineWeight(DotSize);
BNewCMF_Dot.AssignValueColor(if BNewCMF> Over_Bought && BNewCMF >BNewCMFA then GlobalColor("OverBought") else  if BNewCMF< Over_Sold && BNewCMF <BNewCMFA then GlobalColor("OverSold") else  if BNewCMF> ZeroLine then GlobalColor("Bullish") else If BNewCMF< ZeroLine then GlobalColor("Bearish") else GlobalColor(“Normal”));
plot CNewCMF_Dot = if IsNaN(CC) then Double.NaN else 3;
CNewCMF_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
CNewCMF_Dot.SetLineWeight(DotSize);
CNewCMF_Dot.AssignValueColor(if CNewCMF> Over_Bought && CNewCMF >CNewCMFA then GlobalColor("OverBought") else  if CNewCMF< Over_Sold && CNewCMF <CNewCMFA then GlobalColor("OverSold") else  if CNewCMF> ZeroLine then GlobalColor("Bullish") else If CNewCMF< ZeroLine then GlobalColor("Bearish") else GlobalColor(“Normal”));
 
@zeek You couldn't post an image?

g2z5u4r.png
 
Hello German,

I added a moving average to the CMF as a signal, also added a cloud

Code:
###################

declare lower;
input periods = 21;
Input LengthA = 5;
input over_Bought = .20;
input over_Sold = -.20;


def C = close;

def H = high;

def L = low;

def V = volume;

def TRH = Max(H,C[1]);

def TRL = Min(L, C[1]);

def TR = TRH - TRL;

def ADV =((C-TRL)-(TRH-C))/ (If TR == 0 then 999999 else TR) * V;

plot NewCMF = if WildersAverage(V,periods) == 0

              then 0

              else WildersAverage(ADV, periods) / WildersAverage(V, periods);
Plot NewCMFA = ExpAverage(NewCMF,LengthA);
NewCMFA.SetDefaultColor(Color.Yellow);
plot ZeroLine = 0;
AddCloud(NewCMF,Zeroline,Color.Green,Color.Red);
ZeroLine.SetDefaultColor(color.gray);                

plot OverSold = over_Sold;
OverSold.SetDefaultColor(Color.Orange);
OverSold.SetPaintingStrategy(PaintingStrategy.Dashes);
plot OverBought = over_Bought;
OverBought.SetDefaultColor(Color.Orange);
OverBought.SetPaintingStrategy(PaintingStrategy.Dashes);

NewCMF.DefineColor("OverBought", GetColor(5));
NewCMF.DefineColor("Normal", GetColor(7));
NewCMF.DefineColor("OverSold", GetColor(1));
NewCMF.AssignValueColor(if  NewCMF > over_Bought then  NewCMF.color("OverBought") else if  NewCMF < over_Sold then  NewCMF.color("OverSold") else  NewCMF.color("Normal"));
NewCMF.SetLineweight(3);

I have created your money flow indicator into a binary signal w 3 MTF. The triangles are Cyan if the MF is Bullish, Red when overbought, Magenta when Bearish and Green when oversold

Here is the code

Code:
##############
Declare Lower;
DefineGlobalColor("Bullish", Color.Cyan);
DefineGlobalColor("Bearish", Color.Magenta);
DefineGlobalColor("OverSold", Color.Green);
DefineGlobalColor("OverBought", Color.Red);
DefineGlobalColor("Normal", Color.Gray);

input agg1 = AggregationPeriod.FIVE_MIN;
input agg2 = AggregationPeriod.Thirty_MIN;
input agg3 = AggregationPeriod. Hour;
input periods = 21;
Input LengthA = 5;
input over_Bought = .20;
input over_Sold = -.20;
input show_dots=yes;
input DotSize = 3;

Def AC = Close(Period = Agg1);
Def BC = Close(Period = Agg2);
Def CC = Close(Period = Agg3);
Def AH = High(Period = Agg1);
Def BH = High(Period = Agg2);
Def CH = High(Period = Agg3);
Def AL = Low(Period = Agg1);
Def BL = Low(Period = Agg2);
Def CL = Low(Period = Agg3);
Def AV = Volume(Period = Agg1);
Def BV = Volume(Period = Agg2);
Def CV = Volume(Period = Agg3);

def ATRH = Max(AH,AC[1]);
def BTRH = Max(BH,BC[1]);
def CTRH = Max(CH,CC[1]);
def ATRL = Min(AL, AC[1]);
def BTRL = Min(BL, BC[1]);
def CTRL = Min(CL, CC[1]);

def TRa = ATRH - ATRL;
def TRb = BTRH - BTRL;
def TRc = CTRH - CTRL;

def AADV =((AC-ATRL)-(ATRH-AC))/ (If TRa == 0 then 999999 else TRa) * AV;
def BADV =((BC-BTRL)-(BTRH-BC))/ (If TRb == 0 then 999999 else TRb) * BV;
def CADV =((CC-CTRL)-(CTRH-CC))/ (If TRc == 0 then 999999 else TRc) * CV;

Def ANewCMF = if WildersAverage(AV,periods) == 0
              then 0
              else WildersAverage(AADV, periods) / WildersAverage(AV, periods);
Def BNewCMF = if WildersAverage(BV,periods) == 0
              then 0
              else WildersAverage(BADV, periods) / WildersAverage(BV, periods);
Def CNewCMF = if WildersAverage(CV,periods) == 0
              then 0
              else WildersAverage(CADV, periods) / WildersAverage(CV, periods);

Def ANewCMFA = ExpAverage(ANewCMF,LengthA);
Def BNewCMFA = ExpAverage(BNewCMF,LengthA);
Def CNewCMFA = ExpAverage(CNewCMF,LengthA);
Def ZeroLine = 0;
plot ANewCMF_Dot = if IsNaN(AC) then Double.NaN else 1;
ANewCMF_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
ANewCMF_Dot.SetLineWeight(DotSize);
ANewCMF_Dot.AssignValueColor(if ANewCMF> Over_Bought && ANewCMF >ANewCMFA then GlobalColor("OverBought") else  if ANewCMF< Over_Sold && ANewCMF <ANewCMFA then GlobalColor("OverSold") else  if ANewCMF> ZeroLine then GlobalColor("Bullish") else If ANewCMF< ZeroLine then GlobalColor("Bearish") else GlobalColor(“Normal”));
plot BNewCMF_Dot = if IsNaN(BC) then Double.NaN else 2;
BNewCMF_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
BNewCMF_Dot.SetLineWeight(DotSize);
BNewCMF_Dot.AssignValueColor(if BNewCMF> Over_Bought && BNewCMF >BNewCMFA then GlobalColor("OverBought") else  if BNewCMF< Over_Sold && BNewCMF <BNewCMFA then GlobalColor("OverSold") else  if BNewCMF> ZeroLine then GlobalColor("Bullish") else If BNewCMF< ZeroLine then GlobalColor("Bearish") else GlobalColor(“Normal”));
plot CNewCMF_Dot = if IsNaN(CC) then Double.NaN else 3;
CNewCMF_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
CNewCMF_Dot.SetLineWeight(DotSize);
CNewCMF_Dot.AssignValueColor(if CNewCMF> Over_Bought && CNewCMF >CNewCMFA then GlobalColor("OverBought") else  if CNewCMF< Over_Sold && CNewCMF <CNewCMFA then GlobalColor("OverSold") else  if CNewCMF> ZeroLine then GlobalColor("Bullish") else If CNewCMF< ZeroLine then GlobalColor("Bearish") else GlobalColor(“Normal”));
Henry when I put this into TOS nothing shows up, any ideas?
 
Henry when I put this into TOS nothing shows up, any ideas?
You need to align your timeframes when using the SECOND script in the post you quoted.
The indicator looks at 5min, 30min, and Hourly aggregations.

The timeframe of your chart MUST BE lower than the aggregations in the study.
Therefore, if using the defaults, this study can only be used on charts set with 4min and below timeframes.

You can change the default aggregations in chart settings.
When adjusting the timeframe settings, keep in mind that the timeframes in the script must be HIGHER than what you have your chart set at.
 
Hello German,

I added a moving average to the CMF as a signal, also added a cloud

Code:
###################

declare lower;
input periods = 21;
Input LengthA = 5;

[/QUOTE]
Hi! What does Input LengthA mean? what happens when you make it higher or lower? Thank you!

Paul
 
Last edited by a moderator:
Hi! What does Input LengthA mean? what happens when you make it higher or lower? Thank you!

Paul
LengthA smoothes out the plot. Smoothing factors typically do not get any higher than 5, but you can try lower.
Recommend you put it on your chart. Nothing beats personal experience ;) The only way you will know what works best for you is to play with the settings and see how the indicator line up w/ your strategy and with your other indicators. To determine if this indicator brings value, analyze it over different timeframes, across history and with multiple instruments.
 

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
456 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