Moxie Indicator for ThinkorSwim

Status
Not open for further replies.

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/

Here is the actual code for convience

Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © markmiotke
//@version=4
// Moxie_Arrows[Salty]
// By Mark Miotke
// Initial Release: 2/20/2020


study(title="Moxie_Arrows[Salty]", overlay=false)
ShowZeroCrossArrows = input(false, title="Show Zero Cross Arrows")
ShowCrossArrows = input(false, title="Show Cross Arrows")

Red       = #FF0000
DarkRed   = #BA0000
Green     = #00FF00
DarkGreen = #00BA00

funcMoxie() =>
    priceC = close
    vc1 = ema(priceC , 12) - ema(priceC , 26)
    va1 = ema(vc1, 9)
    (vc1 - va1) * 3

//Resolution, e.g. '60' - 60 minutes, 'D' - daily, 'W' - weekly, 'M' - monthly, '5D' - 5 days, '12M' - one year, '3M' - one quarter
currentPeriod = timeframe.period

s2 = currentPeriod == '1' or currentPeriod == '3' ? security(syminfo.tickerid, '5', funcMoxie())
  : currentPeriod == '5' ? security(syminfo.tickerid, '15', funcMoxie())
  : currentPeriod == '15' ? security(syminfo.tickerid, '30', funcMoxie())
  : currentPeriod == '30' ? security(syminfo.tickerid, '60', funcMoxie())
  : currentPeriod == '45' ? security(syminfo.tickerid, '120', funcMoxie())
  : currentPeriod == '60' or currentPeriod == '120' or currentPeriod == '180' or currentPeriod == '240' ? security(syminfo.tickerid, 'D', funcMoxie())
  : currentPeriod == 'D' ? security(syminfo.tickerid, 'W', funcMoxie())
  : currentPeriod == 'W' ? security(syminfo.tickerid, 'M', funcMoxie())
  : na

c_color=s2 < 0 ? (s2 < s2[1] ? DarkRed : DarkGreen) : (s2 >= 0 ? (s2 > s2[1] ? Green : Red) : na)
fill_Color=s2 < 0 ? (s2 < s2[1] ? DarkRed : Red) : (s2 >= 0 ? (s2 > s2[1] ? Green : DarkGreen) : na)

p1 = plot(s2 , style=plot.style_line, color=c_color, linewidth=3, transp=0)
zeroline = hline(0, title="Zero Line", color=color.black, linestyle=hline.style_dotted, linewidth=1)
plotshape(ShowZeroCrossArrows and crossover(s2, 0) ? s2 : na, color=Green, style=shape.arrowup, location=location.absolute, size=size.huge)
plotshape(ShowCrossArrows and crossover(s2, s2[1]) and s2 > 0 ? s2 : na, color=Green, style=shape.arrowup, location=location.absolute, size=size.huge)
plotshape(ShowCrossArrows and crossunder(s2, s2[1]) and s2 > 0 ? s2 : na, color=Red, style=shape.arrowdown, location=location.absolute, size=size.normal)
plotshape(ShowZeroCrossArrows and crossunder(s2, 0) ? s2 : na, color=DarkRed, style=shape.arrowdown, location=location.absolute, size=size.huge)
plotshape(ShowCrossArrows and crossunder(s2, s2[1]) and s2 < 0 ? s2 : na, color=DarkRed, style=shape.arrowdown, location=location.absolute, size=size.huge)
plotshape(ShowCrossArrows and crossover(s2, s2[1]) and s2 < 0 ? s2 : na, color=DarkGreen, style=shape.arrowup, location=location.absolute, size=size.normal)
fill(p1,plot(0,color=color.black,linewidth=1),color=fill_Color,transp=50)

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

diazlaz

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

madpuri

Member
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!!!!!
 

madpuri

Member
@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

 

madpuri

Member
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
 

diazlaz

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

madpuri

Member
@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:

rad14733

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

madpuri

Member
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:

diazlaz

Well-known member
2019 Donor
VIP
If you remove the cloud, does the color change show? I will eye it again this weekend.
 

madpuri

Member
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:

tradegeek

Active member
2019 Donor
@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.
 

cos251

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

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

Praful005

Member
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 ?
 
Status
Not open for further replies.

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