Adaptive MA stops plotting today but plots all prior days

Glefdar

Active member
Hello all,

I'm really confused by this, see screenshot:

HefecOI.png


It just doesn't make any sense to me why this stops plotting. The code is cut out of and modified from the NextSignals trend following strategy, this is the code creating the above plot:

Code:
def direction;
def volatility;
def ER;

def length = 2;
direction = AbsValue(close – close[length]);
volatility = Sum(AbsValue(close – close[1]), length);
ER = AbsValue((close – Lowest(low, length)) –
(Highest(high, length) – close)) / (Highest(high,
length) – Lowest(low, length));
def SlowSF = 0.2222;
def ScaledSF = ER * (0.4 – SlowSF) + SlowSF;
def AMA = CompoundValue(1, AMA[1] + Sqr(ScaledSF) * (close – AMA[1]),
close);
plot MAA = AMA;
MAA.assignvaluecolor(if OHLC4 > AMA then Color.White
else Color.Light_Red);
MAA.setlineweight(2);
MAA.hidebubble();
MAA.hidetitle();

This AMA is a crucial part of another indicator I am using (which takes the AMA plot value as an input for another function). I would be very grateful if anyone has any idea about how or why this stopped plotting for the current day while working for previous days.
 
Solution
Hello all,

I'm really confused by this, see screenshot:

HefecOI.png


It just doesn't make any sense to me why this stops plotting. The code is cut out of and modified from the NextSignals trend following strategy, this is the code creating the above plot:

Code:
def direction;
def volatility;
def ER;

def length = 2;
direction = AbsValue(close – close[length]);
volatility = Sum(AbsValue(close – close[1]), length);
ER = AbsValue((close – Lowest(low, length)) –
(Highest(high, length) – close)) / (Highest(high,
length) – Lowest(low, length));
def SlowSF = 0.2222;
def ScaledSF = ER * (0.4 – SlowSF) + SlowSF;
def AMA = CompoundValue(1, AMA[1] + Sqr(ScaledSF) * (close – AMA[1]),
close);
plot MAA = AMA;
MAA.assignvaluecolor(if OHLC4 > AMA then...
Hello all,

I'm really confused by this, see screenshot:

HefecOI.png


It just doesn't make any sense to me why this stops plotting. The code is cut out of and modified from the NextSignals trend following strategy, this is the code creating the above plot:

Code:
def direction;
def volatility;
def ER;

def length = 2;
direction = AbsValue(close – close[length]);
volatility = Sum(AbsValue(close – close[1]), length);
ER = AbsValue((close – Lowest(low, length)) –
(Highest(high, length) – close)) / (Highest(high,
length) – Lowest(low, length));
def SlowSF = 0.2222;
def ScaledSF = ER * (0.4 – SlowSF) + SlowSF;
def AMA = CompoundValue(1, AMA[1] + Sqr(ScaledSF) * (close – AMA[1]),
close);
plot MAA = AMA;
MAA.assignvaluecolor(if OHLC4 > AMA then Color.White
else Color.Light_Red);
MAA.setlineweight(2);
MAA.hidebubble();
MAA.hidetitle();

This AMA is a crucial part of another indicator I am using (which takes the AMA plot value as an input for another function). I would be very grateful if anyone has any idea about how or why this stopped plotting for the current day while working for previous days.

This seems to work. There was a divisor of zero in the def ER causing the termination of the AMA.

Capture.jpg
Ruby:
def direction;
def volatility;
def ER;
def c = if isnan(close) then c[1] else close;
def h = if IsNaN(high) then h[1] else high;
def l = if IsNaN(low) then l[1] else low;

def length = 2;
direction = AbsValue(close – close[length]);
volatility = Sum(AbsValue(close – close[1]), length);

def hhll =  if   (Highest(h, length) – Lowest(l, length)) == 0
            then hhll[1]
            else (Highest(h, length) – Lowest(l, length));
ER = AbsValue((c – Lowest(l, length)) – (Highest(h, length) – c)) / hhll;

def SlowSF = 0.2222;
def ScaledSF = ER * (0.4 – SlowSF) + SlowSF;
def AMA = CompoundValue(1, AMA[1] + Sqr(ScaledSF) * (close – AMA[1]),
close);
plot MAA = AMA;
MAA.AssignValueColor(if OHLC4 > AMA then Color.WHITE
else Color.LIGHT_RED);
MAA.SetLineWeight(2);
MAA.HideBubble();
MAA.HideTitle();
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

This seems to work. There was a divisor of zero in the def ER causing the termination of the AMA.

Thank you so much, this was a great help to me. From what I can determine, your addition of the variable "AMA_hhll" was enough to resolve the problem, so I removed the "if isnan(close) then c[1]" (likewise for high and low) part as unnecessary complexity, but if it stops working again the first thing I'll try is adding that back in.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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