Offsets in study-based conditional order

10basetom

New member
Hi, in my study I have a trigger to enter a position, enterSignal. In order to prevent false positives during live trading, I currently use this code to enter the position:

Code:
# Enter if enterSignal was TRUE in the previous bar
enterSignal[1]

This is working as expected so far -- when using 15m charts, trades are entered as soon as the clock strikes 10:45 if enterSignal was TRUE at 10:30 bar.

My question is, what if I changed the code to a negative offset:

Code:
enterSignal[-1]

Using the example above, if enterSignal was TRUE at the 10:30 bar, when would the order execute?

I read https://usethinkscript.com/threads/plotting-future-and-past-offsets.4093/, but still not sure how it would impact a live trade such as in the example above.
 
Hi, in my study I have a trigger to enter a position, enterSignal. In order to prevent false positives during live trading, I currently use this code to enter the position:

Code:
# Enter if enterSignal was TRUE in the previous bar
enterSignal[1]

This is working as expected so far -- when using 15m charts, trades are entered as soon as the clock strikes 10:45 if enterSignal was TRUE at 10:30 bar.

My question is, what if I changed the code to a negative offset:

Code:
enterSignal[-1]

Using the example above, if enterSignal was TRUE at the 10:30 bar, when would the order execute?

I read https://usethinkscript.com/threads/plotting-future-and-past-offsets.4093/, but still not sure how it would impact a live trade such as in the example above.
You can use both the Condition Wizard and the thinkScript Editor to set your conditions or define a numerical value, e.g., a study. Note when creating conditions for conditional orders via the Condition Wizard, anytime you use a STUDY you must offset the bars by 1. I REPEAT: YOU MUST OFFSET THE BARS BY 1 WHEN CREATING A CONDITIONAL ORDER USING A STUDY! This is because you want your order to execute on the open of the bar FOLLOWING the bar in which the strategy was fulfilled. You want the previous bar to close to ensure that your condition(s) remain true througout the entire duration of the bar till the close. For example, midway through a 15 minute candlestick, your condition could trigger being fulfilled, let's say the MACD crossing 0, thus creating a buy order. However, the bar could close in a way where the MACD did not end up closing crossing 0, which means your conditions weren't actually satisfied since the bar didn't close with the conditions being fulfilled. This should reflect how the same code would be executed via backtesting a strategy if that is your desire. Once you have created your order conditions, press Save.
 

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

Hi, in my study I have a trigger to enter a position, enterSignal. In order to prevent false positives during live trading, I currently use this code to enter the position:

Code:
# Enter if enterSignal was TRUE in the previous bar
enterSignal[1]

This is working as expected so far -- when using 15m charts, trades are entered as soon as the clock strikes 10:45 if enterSignal was TRUE at 10:30 bar.

My question is, what if I changed the code to a negative offset:

Code:
enterSignal[-1]

Using the example above, if enterSignal was TRUE at the 10:30 bar, when would the order execute?

I read https://usethinkscript.com/threads/plotting-future-and-past-offsets.4093/, but still not sure how it would impact a live trade such as in the example above.
Code:
# Enter if enterSignal was TRUE in the previous bar
enterSignal[1]
This code uses a look back so it lags 2 bars waiting until this previous bar is one bar back.
This is useful at times when using on a higher aggregation with an indicator that "repaints" the current candle with false signals until is closes.

Code:
enterSignal[-1]
This code uses a look forward so it lags 2 bars waiting for the future bar to close.
This is useful at times when using an additional condition that is waiting to confirm the current candle.

Most conditional orders can just use "close" wherein the order executes at the close of the current candle or as the poster stated above: open[-1] waits for the open of the next candle (this is the better option if getting false signals on the current candle)
 
You can use both the Condition Wizard and the thinkScript Editor to set your conditions or define a numerical value, e.g., a study. Note when creating conditions for conditional orders via the Condition Wizard, anytime you use a STUDY you must offset the bars by 1. I REPEAT: YOU MUST OFFSET THE BARS BY 1 WHEN CREATING A CONDITIONAL ORDER USING A STUDY! This is because you want your order to execute on the open of the bar FOLLOWING the bar in which the strategy was fulfilled. You want the previous bar to close to ensure that your condition(s) remain true througout the entire duration of the bar till the close. For example, midway through a 15 minute candlestick, your condition could trigger being fulfilled, let's say the MACD crossing 0, thus creating a buy order. However, the bar could close in a way where the MACD did not end up closing crossing 0, which means your conditions weren't actually satisfied since the bar didn't close with the conditions being fulfilled. This should reflect how the same code would be executed via backtesting a strategy if that is your desire. Once you have created your order conditions, press Save.
That's a great explanation, and it's also why I'm currently using the [1] offset. My question was out of curiosity what would happen if I were to use a negative offset in a conditional study, which I now understand a little better after what the admin said.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
437 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