Invalid Statement.. Why?

Mocnarf1

Member
Why would this statement be invalid in a Study?
close + 0.20 < SimpleMovingAvg("length" = 9)."SMA"[0];

The ThinkScript Forum on TOS suggested using AverageType so this is what I have
close + 0.25 < averageType.SIMPLE

How do I change the averageType say to 21 or 42?
And does averageType default to 9?
 
Solution
Why would this statement be invalid in a Study?
close + 0.20 < SimpleMovingAvg("length" = 9)."SMA"[0];

The ThinkScript Forum on TOS suggested using AverageType so this is what I have
close + 0.25 < averageType.SIMPLE

How do I change the averageType say to 21 or 42?
And does averageType default to 9?

In a study you need a def or plot statement or labels or bubbles. I added a def x to you code and it works.

So see below some of these options and how to use averagetype.

Code:
def x = close + 0.20 < SimpleMovingAvg("length" = 9)."SMA"[0];

AddLabel(1, SimpleMovingAvg("length" = 9)."SMA"[0], Color.WHITE);
AddChartBubble(1, low, SimpleMovingAvg("length" = 9)."SMA"[0], Color.GRAY, no);

input length  = 9;
input...
Why would this statement be invalid in a Study?
close + 0.20 < SimpleMovingAvg("length" = 9)."SMA"[0];

The ThinkScript Forum on TOS suggested using AverageType so this is what I have
close + 0.25 < averageType.SIMPLE

How do I change the averageType say to 21 or 42?
And does averageType default to 9?

In a study you need a def or plot statement or labels or bubbles. I added a def x to you code and it works.

So see below some of these options and how to use averagetype.

Code:
def x = close + 0.20 < SimpleMovingAvg("length" = 9)."SMA"[0];

AddLabel(1, SimpleMovingAvg("length" = 9)."SMA"[0], Color.WHITE);
AddChartBubble(1, low, SimpleMovingAvg("length" = 9)."SMA"[0], Color.GRAY, no);

input length  = 9;
input averagetype = AverageType.SIMPLE;
plot y = MovingAverage(averagetype, close, length);
 
Solution
I assume the statements evaluate to either true or false, 1 or 0 Correct?
I will try out your suggestion.

I have also been trying this, See any problem with it?

def sell =
close > Average(close - 0.2, 9)
and close > Average(close, 21) ;
 
I assume the statements evaluate to either true or false, 1 or 0 Correct?
I will try out your suggestion.

I have also been trying this, See any problem with it?

def sell =
close > Average(close - 0.2, 9)
and close > Average(close, 21) ;

What you posted in #1 will work in a scanner as is returning a 1/0. In a study though you need to do what I suggested abpve.

Likewise, what you posted above is valid in a study, but a study needs a plot, or label or bubble in addition to be a valid study. If you want to use it in the scanner then the following will work returning 1/0

Code:
plot sell =
close > Average(close - 0.2, 9)
and close > Average(close, 21) ;
or
Code:
close > Average(close - 0.2, 9) and close > Average(close, 21)
 

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