Script for price action that follows an EMA over a period of time.

Mutagenix

New member
I've noticed a pattern that I really want to be able to set a scan criteria for.

I'm working with this piece of code, and it gets the results I'm looking for, but only
for the current candle. I'm trying to add a "time" function to it so it looks for specific
behavior that say the last X candles exhibited.

def EMA = ExpAverage(low, 9);
plot scan = Between(low, EMA - (.03 * EMA), EMA + (.03 * EMA));

As a logical statement, it will look something like this:

"The (low/high) of the last ( ) consecutive candles has occurred within ( )% of the ( )EMA"

I realize this may not be possible due to the limitations of TOS, but I'm hoping you guys
(and gals) can deliver the way you always have.

Much thanks!
 
Solution
Well **** guys, I'm pretty proud of myself. I really dug into this thing last night, determined
to figure it out on my own. Impressed with the results so far. The code is still pretty unrefined
so I'll be making adjustments as I go. I really like this pattern and I'm hoping anyone who
decided to run queries against it will see the same value. Also, I'm pretty new to coding, so
take it easy on me lol.

Geared towards bullish patterns, but swapping >= for <= and > for < will yield bearish results.

Here's what I have so far, pleaese let me know if it can be simplified further:

Code:
#Created by Mutagenix (01/04/2022)
#Intended to identify the early stages of distribution

def EMA = ExpAverage (close, 9);

def money = hl2;

def lucy =...
Well **** guys, I'm pretty proud of myself. I really dug into this thing last night, determined
to figure it out on my own. Impressed with the results so far. The code is still pretty unrefined
so I'll be making adjustments as I go. I really like this pattern and I'm hoping anyone who
decided to run queries against it will see the same value. Also, I'm pretty new to coding, so
take it easy on me lol.

Geared towards bullish patterns, but swapping >= for <= and > for < will yield bearish results.

Here's what I have so far, pleaese let me know if it can be simplified further:

Code:
#Created by Mutagenix (01/04/2022)
#Intended to identify the early stages of distribution

def EMA = ExpAverage (close, 9);

def money = hl2;

def lucy = Between(low, EMA - (.01 * EMA), EMA + (.01 * EMA)); 

def groovy = money >= EMA and EMA > EMA[1];
def groovy1 = money[1] >= EMA[1] and EMA[1] > EMA[2];
def groovy2 = money[2] >= EMA[2] and EMA[2] > EMA[3];
def groovy3 = money[3] >= EMA[3] and EMA[3] > EMA[4];
def groovy4 = money[4] >= EMA[4] and EMA[4] > EMA[5];

plot scan = lucy is true and groovy is true and groovy1 is true and 
groovy2 is true and groovy3 and groovy4 is true;
 
Last edited:
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
204 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