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

def TRL = Min(L, C);

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:
• wtf_dude

#### henry1224

##### Active member
VIP
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);

def TRL = Min(L, C);

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;
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);
def BTRH = Max(BH,BC);
def CTRH = Max(CH,CC);
def ATRL = Min(AL, AC);
def BTRL = Min(BL, BC);
def CTRL = Min(CL, CC);

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

##### Active member
2019 Donor
An image of the indicator would be nice • mourningwood4521

#### germanburrito

##### Active member
thank you so much @henry1224, cant wait to try it.

#### MerryDay

##### Well-known member
VIP
@zeek You couldn't post an image? #### MatthewTherrien

##### Member
@henry1224 Thank you for your contribution - I like it and it is testing well when I use it with a 20EMA strategy

• germanburrito

#### jorge50505

##### New member
VIP
like this indicator for scalping thank youuu