Math on indicator bars only

MFitz73

Member
Hi guys, I am trying my best but can't figure which way to go. I have a chart indicator that paints an arrow below the criteria met candle or candles. What I am trying to do is add up a value(say close price, if more than one I would want the average of the close prices) for each candle bar and paint a horizontal line on the chart.
What I can do is I can script the indicator. but I can not figure how to go about collecting the data and draw the line.
would I use the fold script here? I'm currently trying to write simple fold scripts to get a handle on it but... well here I am. lol
any help would be greatly appreciated.
thanks
Mike
 
Solution
@MFitz73
Replace <Signal> with your criteria.

Code:
def RunningClose;
def SignalCount;

If <Signal> {
RunningClose = RunningClose[1] + close;
SignalCount = SignalCount[1] + 1;
} else {
RunningClose = RunningClose[1];
SignalCount = SignalCount[1];}

plot AverageClose = RunningClose / SignalCount;
AverageClose.SetPaintingStrategy(PaintingStrategy.Horizontal);
@Svanoy I just ran the code in on demand and its painting the line far away from the price action. for example the 3 candles that are being calculate have values of (for example) 21.33, 21.37, 21.41 and the line is painted at 44 on the chart. I am running the code on a 2min chart.
 
@MFitz73
There was an issue if the amount of bars on a chart being less than the value of the offset causing the last bar number value to not be retrieved.
I have developed a work around for that and have been updating scripts I've posted here as I find them.
I've updated the code in post #7 with this work around and should now work no matter the amount of bars displayed on the chart.
If you find any other problems with the script, please let me know.
 
Ok been running the updated code in OnDemand and looks like its processing all the math correctly and painting
the threshold line in the right spot now. I will run it this week realtime. will report back. So far everything look
neat and reliable! Thank you @Svanoy !
 

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