Trying to AssignPriceBar for a range of bars

keithmj

New member
I think my logic might be wrong here. What I'm trying to do sounds like it should be simple to do, but I'm not sure how to do it with the way TOS scripts work.

I simply was to:

  • Set a length input (I got that part)
  • Paint the price bar on the day earnings are reported (I got that part)
  • Paint each day after that for the length of bars given (I don't have that part)
  • Stop painting the bars after the length of bars is reached
  • Repeat the process at the next earnings date.
The way I'm thinking is to get the bar of the earnings date, then get the bar (n + length) ahead to get my start and end bars. It sounds simple, and using the below lines, I am getting what I want. However, when TOS processes the next day after earnings those values are lost. Therefore, I can only paint the day of the earnings.

def earnings_day = if(HasEarnings()) then BarNumber() else 0;
def earnings_drift = if(HasEarnings()) then BarNumber() + earnings_drift_length else 0;

AssignPriceColor(if(earnings_day) then Color.LIME else Color.GRAY);

So, on earnings day the variables are set correctly, but then they are set back to 0 and lost the day after. Somehow, I need to maintain those variables so I can evaluate the subsequent days after earnings.
 
Solution
I think my logic might be wrong here. What I'm trying to do sounds like it should be simple to do, but I'm not sure how to do it with the way TOS scripts work.

I simply was to:

  • Set a length input (I got that part)
  • Paint the price bar on the day earnings are reported (I got that part)
  • Paint each day after that for the length of bars given (I don't have that part)
  • Stop painting the bars after the length of bars is reached
  • Repeat the process at the next earnings date.
The way I'm thinking is to get the bar of the earnings date, then get the bar (n + length) ahead to get my start and end bars. It sounds simple, and using the below lines, I am getting what I want. However, when TOS processes the next day after...
I think my logic might be wrong here. What I'm trying to do sounds like it should be simple to do, but I'm not sure how to do it with the way TOS scripts work.

I simply was to:

  • Set a length input (I got that part)
  • Paint the price bar on the day earnings are reported (I got that part)
  • Paint each day after that for the length of bars given (I don't have that part)
  • Stop painting the bars after the length of bars is reached
  • Repeat the process at the next earnings date.
The way I'm thinking is to get the bar of the earnings date, then get the bar (n + length) ahead to get my start and end bars. It sounds simple, and using the below lines, I am getting what I want. However, when TOS processes the next day after earnings those values are lost. Therefore, I can only paint the day of the earnings.

def earnings_day = if(HasEarnings()) then BarNumber() else 0;
def earnings_drift = if(HasEarnings()) then BarNumber() + earnings_drift_length else 0;

AssignPriceColor(if(earnings_day) then Color.LIME else Color.GRAY);

So, on earnings day the variables are set correctly, but then they are set back to 0 and lost the day after. Somehow, I need to maintain those variables so I can evaluate the subsequent days after earnings.

This seems to work.

In your code's earnings_day, the barnumber is zero after hasearning(). The addition of earnings_day[1] retains that barnumer.

The use of the between() function in the assignpricecolor is a common way to limit an action to a range of bars.

Capture.jpg
Ruby:
input earnings_drift_length = 8;
def bn = BarNumber();
def earnings_day = if HasEarnings() then bn else earnings_day[1];

AssignPriceColor(if (Between(bn, earnings_day, earnings_day + earnings_drift_length)) then Color.LIME else Color.GRAY);
 
Solution
Holy smokes I'm an *****! I knew my problem was resetting earnings_day to 0 every time it wasn't earnings day, I just couldn't think how to fix it. Thanks for making it work.
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
587 Online
Create Post

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