Offset of 1 required for condition orders

msammons

Member
I realize that when converting a strategy into a conditional order it is necessary to offset the strategy by one in the conditional order (so the conditional buy order looks at the close of the last candle for the trigger and executes at the open of the next candle, just like the strategy back-test does).

So assume the strategy for back-testing I have is this:

def s = StochasticFull();
def buy = s<10 and close<close[1];
plot z = buy;
AddOrder(OrderType.BUY_TO_OPEN, buy, open[-1], 100);

I tried to convert that to a conditional order:

def s = StochasticFull();
def buy = s<10 and close<close[1];
plot z = buy;

This conditional order triggers "before" the last candle has closed (thus not matching the results from the back-test).

But to make the conditional order actually execute at the same point as the strategy I read you must add an offset of 1. The TOS Conditional Wizard to add the offset adds "from 1 bars ago" - but when I add that to my conditional order (which is not built from the Wizard) I get a red error message.

My question is: Can I accomplish the necessary offset of one bar by using the following?:

def s = StochasticFull();
def buy = s[1]<10 and close[1]<close[2];
plot z = buy;

Would adding the [1] to s and close (an offset back additional one bar) cause the conditional buy order to trigger at the same point as the strategy back-testing?
 
Last edited:

rad14733

Well-known member
VIP
@msammons You should be able to look back at close[2] in conditional orders without issue but I haven't actually tried it... And I'm not sure whether testing with OnDemand would answer that question or not...
 

msammons

Member
I guess the most concise question is:

Is "def buy = s<10 and close<close[1] from 1 bars ago" equal to "def buy = s[1]<10 and close[1]<close[2]"

I do not think you can do conditional orders with OnDemand, so live trading is necessary to test - I just needed some reassurance in my theory before throwing out there live (I took your reply as agreeing with my basic theory that they are the same).
 

msammons

Member
@msammons I seem to recall Pete Hahn of Hahn-Tech.com covering something along these lines in his Thinkorswim AutoTrade Almost forum topic... It might be worth watching if you haven't already done so...
I have watched that very informative video (several times) - the problem is that he did the offset through the Condition Wizard (which adds "from one bars ago"); and for some reason I cannot simply add that addition phrase to my conditional order (get red error message). Unfortunately he never showed any code written from scratch dealing with the offset required to shift the trigger signal 1 bar.
 

rad14733

Well-known member
VIP
I have watched that very informative video (several times) - the problem is that he did the offset through the Condition Wizard (which adds "from one bars ago"); and for some reason I cannot simply add that addition phrase to my conditional order (get red error message). Unfortunately he never showed any code written from scratch dealing with the offset required to shift the trigger signal 1 bar.
Ok... Was just a thought because I have also watched it more than a few times in the past but not recently... Maybe I can watch it yet again later... As I just posted in another topic, I keep getting interrupted this afternoon...
 

THINK711

New member
question ? multipal MTF study has anyone come up with a combination of OFFSET from BUY to SELL right now i am using 1 to1 on the buy side same on the SELL any IDEA's something like 2 to 1 Depending on the time frame being used eather 1 5 15 MIN BARS .
 

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.
Top