Scan for doji candle x bars back

ARL

Member
Plus
Greetings! I'd like to have the TOS scan for doji candle that returns results from x bars back. For example, I'd like to see the dojis that printed 2 bars back.
How would the stock script from TOS below look to include this look back function? Thank you for your help.

Code:
input length = 20;
input bodyFactor = 0.05;

assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);

plot Doji = IsDoji(length, bodyFactor);

Doji.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Doji.SetDefaultColor(CreateColor(153, 153, 255));
Doji.SetLineWeight(3);
 
Last edited by a moderator:
It will be something like this:

Code:
Plot scan = Doji within 3 bars;

Or use the Scan editor and add:

Code:
Doji() is true within 3 bars
 
  • Like
Reactions: ARL
Greetings! I'd like to have the TOS scan for doji candle that returns results from x bars back. For example, I'd like to see the dojis that printed 2 bars back.
How would the stock script from TOS below look to include this look back function? Thank you for your help.

Code:
input length = 20;
input bodyFactor = 0.05;

assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);

plot Doji = IsDoji(length, bodyFactor);

Doji.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Doji.SetDefaultColor(CreateColor(153, 153, 255));
Doji.SetLineWeight(3);

Hi ARL,

Here is another version of it... the number of days ago is set to 2 by default but can be changed in the inputs.

I did a scan with RecentDoji set to true and minimum price $10 and min volume 100,000 and found 55 stocks with Doji's two bars ago. One of the hits is shown in the chart below.

Doji-Nbars-Ago-ARL-chart-4-2-23.png


Code:
# Doji_NbarsAgo
# ARL question 4-2-23

input price = close;
input offset = 2;

plot RecentDoji = open[offset] == close[offset];

RecentDoji.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
RecentDoji.SetDefaultColor(Color.BLUE);
RecentDoji.SetLineWeight(4);
 
Is there a way to add 2 things to the indicator with a watchlist column in mind? Would love for this code to color the doji candlei yellow on the chart AND put up a button that flashes yellow with the word doji if forming in the last candle? And is there any way there can be a watchlist column that flashes yellow when a doji is forming on the last candle?
 
Is there a way to add 2 things to the indicator with a watchlist column in mind? Would love for this code to color the doji candlei yellow on the chart
You can change the color of the doji candle in chart settings.

AND put up a button that flashes yellow with the word doji if forming in the last candle?
For your label on your chart:
You can add this label to the bottom of your script:
AddLabel(open == close, "doji",color.yellow);

And is there any way there can be a watchlist column that flashes yellow when a doji is forming on the last candle?
For your watchlist, add this to the bottom of your watchlist script:
AddLabel(open == close, "doji",color.black);
AssignPriceBackground( if open == close then color.yellow else color.black);
 
Last edited:

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