Moxie Indicator for ThinkorSwim

madpuri

Member
I did some digging on the moxie and found a person on trading view that has successfully mimicked the moxie indicator. It does line up with the videos of the real thing. Some of you here are amazing coders and may be able to convert this to thinkscript. I am still trying to decipher what is going on in the code beyond the first few lines...lol

https://www.tradingview.com/script/mssQsys9-Moxie-Arrows-Salty/
cheers
 
Last edited by a moderator:

New Indicator: Buy the Dip

Check out our Buy the Dip indicator and see how it can help you find profitable swing trading ideas. Scanner, watchlist columns, and add-ons are included.

Download the indicator

here you go @madpuri .

Fe5p4R1.png


Ruby:
#START OF Moxie Salty Port for ThinkOrSwim
#
#CHANGELOG
# 2020.10.02 V1.0 @diazlaz Initial Port Release
#                 Request @madpuri
#
#CREDITS
# markmiotke
#
#LINK
# https://www.tradingview.com/script/mssQsys9-Moxie-Arrows-Salty/
#
#USAGE
#

declare lower;

def AP = GetAggregationPeriod();

def ap1;
if (ap == aggregationPeriod.MIN){ap1=AggregationPeriod.five_Min; }
else if (ap == AggregationPeriod.three_MIN){ ap1=AggregationPeriod.five_Min;}
else if (ap == AggregationPeriod.five_Min) {ap1=AggregationPeriod.fifteen_Min;}
else if (ap == AggregationPeriod.fifteen_Min) {ap1=AggregationPeriod.thirty_min;}
else if (ap == AggregationPeriod.thirty_Min) {ap1= AggregationPeriod.hour;}
else if (ap == AggregationPeriod.hour) {ap1=AggregationPeriod.DAY;}
else if (ap == AggregationPeriod.TWO_HOURS) {ap1=AggregationPeriod.DAY;}
else if (ap == AggregationPeriod.FOUR_HOURS) {ap1=AggregationPeriod.DAY;}
else if (ap == AggregationPeriod.DAY) {ap1=AggregationPeriod.WEEK;}
else if (ap == AggregationPeriod.WEEK) {ap1=AggregationPeriod.MONTH;}
else {ap1=AggregationPeriod.DAY;}

script Moxie {
    input priceC = close;
    def vc1 = ExpAverage(priceC , 12) - ExpAverage(priceC , 26);
    def va1 = ExpAverage(vc1, 9);
    plot sData = (vc1 - va1) * 3;
}

def price = close(period = ap1);
def s2 = Moxie(price);

plot ZeroLine = 0;
plot pMoxie = s2;
pMoxie.SetLineWeight(2);
pMoxie.DefineColor("Positive and Up", Color.GREEN);
pMoxie.DefineColor("Positive and Down", Color.DARK_GREEN);
pMoxie.DefineColor("Negative and Down", Color.RED);
pMoxie.DefineColor("Negative and Up", Color.DARK_RED);
pMoxie.AssignValueColor(if pMoxie >= 0 then if pMoxie > pMoxie[1] then pMoxie.color("Positive and Up") else pMoxie.color("Positive and Down") else if pMoxie < pMoxie[1] then pMoxie.color("Negative and Down") else pMoxie.color("Negative and Up"));

AddCloud(ZeroLine,pMoxie,COLOR.RED,COLOR.GREEN);

#END OF Moxie Salty Port for ThinkOrSwim
 
here you go @madpuri .

Fe5p4R1.png


Ruby:
#START OF Moxie Salty Port for ThinkOrSwim
#
#CHANGELOG
# 2020.10.02 V1.0 @diazlaz Initial Port Release
#                 Request @madpuri
#
#CREDITS
# markmiotke
#
#LINK
# https://www.tradingview.com/script/mssQsys9-Moxie-Arrows-Salty/
#
#USAGE
#

declare lower;

def AP = GetAggregationPeriod();

def ap1;
if (ap == aggregationPeriod.MIN){ap1=AggregationPeriod.five_Min; }
else if (ap == AggregationPeriod.three_MIN){ ap1=AggregationPeriod.five_Min;}
else if (ap == AggregationPeriod.five_Min) {ap1=AggregationPeriod.fifteen_Min;}
else if (ap == AggregationPeriod.fifteen_Min) {ap1=AggregationPeriod.thirty_min;}
else if (ap == AggregationPeriod.thirty_Min) {ap1= AggregationPeriod.hour;}
else if (ap == AggregationPeriod.hour) {ap1=AggregationPeriod.DAY;}
else if (ap == AggregationPeriod.TWO_HOURS) {ap1=AggregationPeriod.DAY;}
else if (ap == AggregationPeriod.FOUR_HOURS) {ap1=AggregationPeriod.DAY;}
else if (ap == AggregationPeriod.DAY) {ap1=AggregationPeriod.WEEK;}
else if (ap == AggregationPeriod.WEEK) {ap1=AggregationPeriod.MONTH;}
else {ap1=AggregationPeriod.DAY;}

script Moxie {
    input priceC = close;
    def vc1 = ExpAverage(priceC , 12) - ExpAverage(priceC , 26);
    def va1 = ExpAverage(vc1, 9);
    plot sData = (vc1 - va1) * 3;
}

def price = close(period = ap1);
def s2 = Moxie(price);

plot ZeroLine = 0;
plot pMoxie = s2;
pMoxie.SetLineWeight(2);
pMoxie.DefineColor("Positive and Up", Color.GREEN);
pMoxie.DefineColor("Positive and Down", Color.DARK_GREEN);
pMoxie.DefineColor("Negative and Down", Color.RED);
pMoxie.DefineColor("Negative and Up", Color.DARK_RED);
pMoxie.AssignValueColor(if pMoxie >= 0 then if pMoxie > pMoxie[1] then pMoxie.color("Positive and Up") else pMoxie.color("Positive and Down") else if pMoxie < pMoxie[1] then pMoxie.color("Negative and Down") else pMoxie.color("Negative and Up"));

AddCloud(ZeroLine,pMoxie,COLOR.RED,COLOR.GREEN);

#END OF Moxie Salty Port for ThinkOrSwim

I think a hot damn is in order!!!!!
 
@diazlaz so I am trying to match the slope line colors of the moxie code. I got close but the red color for the downslope is not showing up.
Appreciate any insight you can provide. I removed the cloud code since it is not needed.

I am unable to post images for some reason, but this youtube link should give you a clue as to what I am trying to do with the sloping lines of the moxie

 
Thanks. @MerryDay

@diazlaz take a look at this image below. I have circled what I am trying to achieve with the moxie. If slope of moxie is down, indicator should be red even if it is slight.

vm9Ba8M.png


However, I keep getting the following when I tweak the code. What I have circled here should be green not read since the slope is positive not negative.

Z2Oi0Uc.png
 
Hi @madpuri,

not sure, I don't trade this system. it could be a different interpretation or a set of inputs that are different.

I went back and compared the trading view results and it's similar to that version of the Moxie.

TradingView:
ImWlOYi.png


TOS:
Gr2wLFM.png
 
@diazlaz The indicator in the screen shot I posted is the same as trading view BUT I am just trying to match it color wise. I am just trying to change the color. Nothing more. That is what I was trying to highlight. When the line is above zero and slopes down. It should be red not green. That is all I am trying to change. Similarly if the line is below zero and sloping up. It should be green not red.
Hope this clarifies.
 
Last edited:
I tried that but it did not produce the correct result. I will try again and post a picture. Perhaps i did it wrong initially
It may not be exact but it does produce essentially the same effect... I only tested one stock symbol...
 
It may not be exact but it does produce essentially the same effect... I only tested one stock symbol...
plot ZeroLine = 0;
plot pMoxie = s2;
pMoxie.SetLineWeight(2);
pMoxie.DefineColor("Positive and Up", Color.GREEN);
pMoxie.DefineColor("Positive and Down", Color.DARK_RED); <-------
pMoxie.DefineColor("Negative and Down", Color.RED);
pMoxie.DefineColor("Negative and Up", Color.DARK_GREEN); <-------
pMoxie.AssignValueColor(if pMoxie >= 0 then if pMoxie > pMoxie[1] then pMoxie.color("Positive and Up") else pMoxie.color("Positive and Down") else if pMoxie < pMoxie[1] then pMoxie.color("Negative and Down") else pMoxie.color("Negative and Up"));

The arrows are where I made the changes. It messes up the indicator. Now slopes above zero line and sloping up are red. That should not be the case. I may check some indicators produced here. They are able to produce what I am looking for. I think the issue is the way the assignvaluecolor is written. (To be clear, the code is a perfect translation of tradingview, but I am trying to match the color change as previously shown)

Basically I am trying to get this to plot like @horserider's MACD.

Jmuq2Nv.png
 
Last edited:
If you remove the cloud, does the color change show? I will eye it again this weekend.
 
If you remove the cloud, does the color change show? I will eye it again this weekend.
What I have shown is without the cloud. That was the easy part. This is just a style thing to match the original.

@diazlaz I would not worry about this too much. It was just me trying to be exact. I got over it after doing some testing. Thanks for your help. The indy is helpful for me.
 
Last edited:
@madpuri It's doing exactly what it should be doing as the current code has four different colors (green, dark green, red, dark red) for four different conditions. If you simply want to mimic the original Moxie, then you simply only need two conditions (whether it's sloping up or down regardless if it's above or below the zero line) and and two colors.
 
Figured I would share this modified version of the Moxie Salty port.

WHLuRqQ.png



Code:
#START OF Moxie Salty Port for ThinkOrSwim
#
#CHANGELOG
# 2020.10.26 V1.1 @cos251 - Changed Colors; added transition signals (could be interpreted as buy/sell);
#                   - added input for aggperiod to allow use to customize or overlay more than one instance of indicator
#                   - for MTF style
# 2020.10.02 V1.0 @diazlaz Initial Port Release
#                 Request @madpuri
#
#CREDITS
# markmiotke
#
#LINK
# https://www.tradingview.com/script/mssQsys9-Moxie-Arrows-Salty/
#
#USAGE
#

declare lower;
input showCloud = no;
input aggPeriod = AggregationPeriod.Min;

# Calculate MOXIE Salty Signal
# Moxie Salty Version Script
script Moxie {
    input priceC = close;
    def vc1 = ExpAverage(priceC , 12) - ExpAverage(priceC , 26);
    def va1 = ExpAverage(vc1, 9);
    plot sData = (vc1 - va1) * 3;
}

def priceMoxie = close(period = aggPeriod);
def s2 = Moxie(priceMoxie);
rec moxieFT = CompoundValue(1, 0.5 * (Log((1 + s2) / (1 - s2)) + moxieFT[1]), 0);

plot MoxiePlot = s2; # Plot InverseFT Moxie
MoxiePlot.SetPaintingStrategy(PaintingStrategy.LINE);
MoxiePlot.DefineColor("Positive and Up", Color.MAGENTA);
MoxiePlot.DefineColor("Positive and Down", Color.PLUM);
MoxiePlot.DefineColor("Negative and Down", Color.DARK_ORANGE);
MoxiePlot.DefineColor("Negative and Up", Color.YELLOW);
MoxiePlot.AssignValueColor(if s2 >= 0 then if s2 > s2[1] then MoxiePlot.color("Positive and Up") else MoxiePlot.color("Positive and Down") else if s2 < s2[1] then MoxiePlot.color("Negative and Down") else MoxiePlot.color("Negative and Up"));

# plot zero line
plot zero = 0;


# Plot Up and Down Signals
plot moxieUpArrow = if (Sign (s2 - s2[1]) > Sign (s2[1] - s2[2])) then s2[1] else Double.NaN;
plot moxieDownArrow = if (Sign (s2 - s2[1]) < Sign (s2[1] - s2[2])) then s2[1] else Double.NaN;
moxieUpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
moxieUpArrow.SetDefaultColor(Color.GREEN);
moxieUpArrow.SetLineWeight(1);
moxieDownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
moxieDownArrow.SetDefaultColor(Color.RED);
moxieDownArrow.SetLineWeight(1);

AddCloud(zero, MoxiePlot, Color.CYAN,Color.YELLOW);
 
Last edited:
@cos251 those arrows are not repainting in above indicator ? In original Moxie indicator by TG... those arrows are repainting
In theory the higher timeframe arrows being plotted on a lower time frame should repaint since the bar for the high agg has to close/confirm. This is always a tricky situation with using high agg signals.
 
In theory the higher timeframe arrows being plotted on a lower time frame should repaint since the bar for the high agg has to close/confirm. This is always a tricky situation with using high agg signals.
Thank you for clarification. So how do we use above indicator and on which timeframe it works ?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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