TOS Indicator for Mobius with EMA 8 support

ark.analyst

New member
Hi, I am trying to modify Mobius supertrend indicator with EMA8 support. if paint the candles in GREEN, if mobius UP and close > ema 8, and candles RED, if Mobius DOWN with close < ema 8 , and others GRAY candles (NO ACTION).
See the code snippet below:

Code:
input AtrMult = 1.0;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;
plot SuperTrend = ST;

def ema8 = MovAvgExponential(8);

def Pos_State = close > ST and close > ema8;
def Neg_State = close < ST and close < ema8;


SuperTrend.AssignValueColor(if Pos_State then Color.GREEN
                     else if Neg_State then Color.RED
                     else Color.GRAY);
AssignPriceColor(if PaintBars and close < ST and close < ema8

                 then Color.RED

                 else if PaintBars and close > ST and close > ema8

                      then Color.GREEN

                      else Color.GRAY);




While applying the settings, I can see only GREEN and GRAY candles, but not RED.

Can someone help identify the error and point to me ?
 
Solution
Hi, I am trying to modify Mobius supertrend indicator with EMA8 support. if paint the candles in GREEN, if mobius UP and close > ema 8, and candles RED, if Mobius DOWN with close < ema 8 , and others GRAY candles (NO ACTION).
See the code snippet below:

Code:
input AtrMult = 1.0;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;
plot SuperTrend = ST;

def ema8 = MovAvgExponential(8);

def Pos_State = close > ST and close > ema8;
def Neg_State = close < ST and close < ema8;


SuperTrend.AssignValueColor(if Pos_State then Color.GREEN...
Hi, I am trying to modify Mobius supertrend indicator with EMA8 support. if paint the candles in GREEN, if mobius UP and close > ema 8, and candles RED, if Mobius DOWN with close < ema 8 , and others GRAY candles (NO ACTION).
See the code snippet below:

Code:
input AtrMult = 1.0;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;
plot SuperTrend = ST;

def ema8 = MovAvgExponential(8);

def Pos_State = close > ST and close > ema8;
def Neg_State = close < ST and close < ema8;


SuperTrend.AssignValueColor(if Pos_State then Color.GREEN
                     else if Neg_State then Color.RED
                     else Color.GRAY);
AssignPriceColor(if PaintBars and close < ST and close < ema8

                 then Color.RED

                 else if PaintBars and close > ST and close > ema8

                      then Color.GREEN

                      else Color.GRAY);




While applying the settings, I can see only GREEN and GRAY candles, but not RED.

Can someone help identify the error and point to me ?

you are using MovAvgExponential incorrectly. ema8 is always = to 8 , not an average.
so (close < ema8) is rarely true, unless you are looking at penny stocks.

def ema8 = MovAvgExponential(8);
MovAvgExponential is a study, that requires several parameters.
parameter 1 is a price type.
parameter 2 is a length
parameter 3 is a displace
parameter 4 is show breakouts

you have just 1 parameter, length. which is being interpreted as the 1st parameter, the price type.
so instead of finding the average of the price, it is finding the average of 8, which is 8.

if you had added a price then length, it would work.
def ema8 = MovAvgExponential(close, 8);

https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/M-N/MovAvgExponential

-------------------------------------------

when you want to find just a number, i would suggest using a function instead of a study.
ExpAverage is a function to return the exponential average.
def ema8 = ExpAverage(close, 8);

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/ExpAverage

-------------------------------------------

to start debugging this, i made a chartbubble to display some variables

addchartbubble(1, low*0.997,
"P " + pos_State + "\n" +
(close > ST) + "\n" +
(close > ema8) + "\n" +
"N " + Neg_State + "\n" +
(close < ST)+ "\n" +
(close < ema8)
, color.yellow, no);

i noticed the 2nd part of this, close < ema8, is always 0.
def Neg_State = close < ST and close < ema8;

so i made another bubble,
addchartbubble(1, low*0.997, ema8, color.magenta, no);
and it was always 8, not the average of the price.

i changed the ema8 formula, by adding close as the 1st parameter, and it worked.
def ema8 = MovAvgExponential(close, 8);

------------------------------------------

you have assignpricecolor() used twice.
the 1st one is correct, with the plot name before it.
the 2nd one is incorrect, and not needed.

-------------------------------------------

here is another way of assigning colors to a plotted line.

reference the plot name with the color reference, in the assign( formula )
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AssignPriceColor

# plot x =
x.DefineColor("Up", color.green);
x.DefineColor("Down", GetColor(5));
x.AssignValueColor(if abc then x.color("down") else x.color("up"));

notice how the plot name, x. is added in front of the word color.
 
Solution

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