How Do References To Future Bars Work?

HODL-Lay-HE-hoo!

Well-known member
VIP
Lifetime
mod note: script revised 5/8/23
Question… when you say carrying the signal into the future… is that in reference to the active[-1]?
https://usethinkscript.com/threads/...gnals-with-opened-position.15228/#post-125045

if !buySignal[1] and doubleBottom and volumeCheck and timeFilter and spreadCondition and Active[-1]{
buySignal = 1;
sellSignal = 0;
entryPrice = close;
hardStopLossPrice = doubleBottomLow;
targetPrice = entryPrice + currentRange;
}

And does cause repaint issues… I guess not since the signal bar would have closed previously?

Curious because to accomplish a similar effect I reference the bar number from a higher aggregation signal then something like:

if buy signal ag 1 and (buy signal ag 2 Bn < buy signal ag 1 bn) and (buy signal ag 2 Bn > sell signal ag 2 Bn) then 1 else 0

Or the old if buy signal and buy signal[1] or buy signal[2] or etc etc you get the point. Then 0 else 1

Or subtract the bar numbers and within x bars back 0 else 1…
 
Last edited by a moderator:
Solution
So if a signal closes on bar 10 then the code uses -1 to look at future bars with the same signal in order to filter them out the signal from bar 10 could not repaint correct? It would be the future signals that are going repaint and or lag?
The bars are repaint with every tick with a guess of what the future bar is going to close at.
Once the future bar closes, it goes back and paints the final signal.

It is similar to the MTF indicators which repaint every tick until the upper aggregation closes.
Only MTF does not have the additional wait of future bars but MTF repaints more bars.
Question… when you say carrying the signal into the future… is that in reference to the active[-1]?

if !buySignal[1] and doubleBottom and volumeCheck and timeFilter and spreadCondition and Active[-1]{
buySignal = 1;
sellSignal = 0;
entryPrice = close;
hardStopLossPrice = doubleBottomLow;
targetPrice = entryPrice + currentRange;
}

And does cause repaint issues… I guess not since the signal bar would have closed previously?

Curious because to accomplish a similar effect I reference the bar number from a higher aggregation signal then something like:

if buy signal ag 1 and (buy signal ag 2 Bn < buy signal ag 1 bn) and (buy signal ag 2 Bn > sell signal ag 2 Bn) then 1 else 0

Or the old if buy signal and buy signal[1] or buy signal[2] or etc etc you get the point. Then 0 else 1

Or subtract the bar numbers and within x bars back 0 else 1…
Yes, active[-1] looks at future bars.
This is the worst type of repainter. Not only does it repaint until the future bar closes; but it also has built-in lag until the future bar closes.

The Pros of using future bars is that it confirms that the signals are real.
So they can have appropriate use with Swing Traders, who benefit from the confirmation and have no worry about the lag as they can afford the wait.
 
Yes, active[-1] looks at future bars.
This is the worst type of repainter. Not only does it repaint until the future bar closes; but it also has built-in lag until the future bar closes.

The Pros of using future bars is that it confirms that the signals are real.
So they can have appropriate use with Swing Traders, who benefit from the confirmation and have no worry about the lag as they can afford the wait.
So if a signal closes on bar 10 then the code uses -1 to look at future bars with the same signal in order to filter them out the signal from bar 10 could not repaint correct? It would be the future signals that are going repaint and or lag?
 
So if a signal closes on bar 10 then the code uses -1 to look at future bars with the same signal in order to filter them out the signal from bar 10 could not repaint correct? It would be the future signals that are going repaint and or lag?
The bars are repaint with every tick with a guess of what the future bar is going to close at.
Once the future bar closes, it goes back and paints the final signal.

It is similar to the MTF indicators which repaint every tick until the upper aggregation closes.
Only MTF does not have the additional wait of future bars but MTF repaints more bars.
 
Solution
The bars are repaint with every tick with a guess of what the future bar is going to close at.
Once the future bar closes, it goes back and paints the final signal.

It is similar to the MTF indicators which repaint every tick until the upper aggregation closes.
Only MTF does not have the additional wait of future bars but MTF repaints more bars.
Ahhh I see… 1000 thanks.
 
@HODL-Lay-HE-hoo!
What I meant by carrying the buysignal forward was combining the four variables to be dependent on previous values. In the logic below, once the first seciton is true it cannot be true again until after the second section is true on the prior bar, therefore the targetPrice and hardStopLossPrice would not change either until the second section was true on the prior bar. That was the fix requested by the original poster.
Ruby:
def buySignal;
def sellSignal;
def entryPrice;
def hardStopLossPrice;
def targetPrice;

if !buySignal[1] and doubleBottom and volumeCheck and timeFilter and spreadCondition and Active{
buySignal = 1;
sellSignal = 0;
entryPrice = close;
hardStopLossPrice = doubleBottomLow;
targetPrice = entryPrice + currentRange;
}
else if buySignal[1] and (low <= hardStopLossPrice[1] or high >= targetPrice[1] or !Active) {
buySignal = 0;
sellSignal = 1;
entryPrice = double.nan;
hardStopLossPrice = double.nan;
targetPrice = double.nan;
}
else {
buySignal = buySignal[1];
sellSignal = sellSignal[1];
entryPrice = entryPrice[1];
hardStopLossPrice = hardStopLossPrice[1];
targetPrice = targetPrice[1];
}

Also, the reference of Active[-1] in my original code was not a cause of repainting as the Active variable was defined by time not price action.
Ruby:
def Active = SecondsFromTime(0645) >=0 and SecondsTillTime(1600) > 0;
The open time of a future bar will never change. All bars even those yet to be plotted and without price data have a defined time.
I used the [-1] in reference to time so that a buySignal could not trigger on the open of the same bar that was the last bar of the day. In the case above 4:00 p.m..
 
@HODL-Lay-HE-hoo!
What I meant by carrying the buysignal forward was combining the four variables to be dependent on previous values. In the logic below, once the first seciton is true it cannot be true again until after the second section is true on the prior bar, therefore the targetPrice and hardStopLossPrice would not change either until the second section was true on the prior bar. That was the fix requested by the original poster.
Ruby:
def buySignal;
def sellSignal;
def entryPrice;
def hardStopLossPrice;
def targetPrice;

if !buySignal[1] and doubleBottom and volumeCheck and timeFilter and spreadCondition and Active{
buySignal = 1;
sellSignal = 0;
entryPrice = close;
hardStopLossPrice = doubleBottomLow;
targetPrice = entryPrice + currentRange;
}
else if buySignal[1] and (low <= hardStopLossPrice[1] or high >= targetPrice[1] or !Active) {
buySignal = 0;
sellSignal = 1;
entryPrice = double.nan;
hardStopLossPrice = double.nan;
targetPrice = double.nan;
}
else {
buySignal = buySignal[1];
sellSignal = sellSignal[1];
entryPrice = entryPrice[1];
hardStopLossPrice = hardStopLossPrice[1];
targetPrice = targetPrice[1];
}

Also, the reference of Active[-1] in my original code was not a cause of repainting as the Active variable was defined by time not price action.
Ruby:
def Active = SecondsFromTime(0645) >=0 and SecondsTillTime(1600) > 0;
The open time of a future bar will never change. All bars even those yet to be plotted and without price data have a defined time.
I used the [-1] in reference to time so that a buySignal could not trigger on the open of the same bar that was the last bar of the day. In the case above 4:00 p.m..
Ahhh ok thanks for the explanation.
 

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