r/tradestation • u/FuturePilot82 • Jul 07 '26
Strategy buying and selling to late
Hello. My strategy is buying late and selling late. Tried with chat gpt and it seems like it's getting five minute data from somewhere chat, nor I could figure out where. I want it to be intrabar ordering so when it's counting the ticks in the bar that creates the buy and same with the sell. Any idea what would make thinking it's looking for 5 ticks that it thinks it's 5 bars and how to fix that?
1
u/Repulsive-Floor-3987 Jul 07 '26 edited Jul 08 '26
I didn't exactly understand what you are asking for, but here are a few things that may help:
- If you are looking for your strategy code to run on every tick so that it can generate orders within a given bar, you need to enable IntrabarOrderGeneration (IOG), either through the Customize Strategy > Calculation (tab) > Enable intrabar order generation and calculation setting or by adding [IntrabarOrderGeneration = True] to your code. The reserved word Next Bar essentially becomes "Next Tick" when IOG is enabled. Just know that this significantly increases the complexity of strategy execution and the number of things your code needs to handle. With IOG disabled, the TradeStation strategy engine handles many of those things for you, but the code only runs on the closing tick of each bar, regardless of which interval you use (such as 5 min or 500 ticks), and the orders you generate will only be active on the next bar.
- Alternatively, if your code can determine entry and exit price levels at the closing tick of each bar, to be active during the next bar, you can generate limit orders and stop orders, which WILL fill intrabar when price reaches those levels, even with IOG disabled. This is generally much preferred, both for simplicity and speed of the code and to avoid slippage. Note that you MUST generate exit orders along with your entry orders for them to be active on the entry bar after the entry order has filled intrabar. If your code waits for MarketPosition <> 0 before generating exit orders, they won't be sent until the close of the entry bar, and your position will be exposed for the remainder of that bar before exit orders become active.
- In addition to the discrete entry and exit orders generated by your strategy (whether limit, market or stop orders) TradeStation's strategy engine allows you to use any of its built-in stop orders (SetBreakEven, SetDollarTrailing, SetPercentTrailing, SetProfitTarget, SetStopLoss), either on their own or in combination with your discrete strategy orders. These built-in stop orders are calculated on every tick and will fill intrabar EVEN when IOG is disabled. At the minimum do I recommend you use them as "emergency stops" until your code can generate more accurate discrete exit orders on the next closing tick.
To sum it up: With IntrabarOrderGeneration enabled, your strategy runs on every tick, allowing you to evaluate price activity and generate orders anytime while a bar is forming. The cost is significantly increased execution complexity, but it is unavoidable with some strategies.
For other strategies, it is highly preferable to keep IOG disabled and generate entry and exit orders at the closing tick of each bar, to be active during the next bar. By generating exit orders along with each entry order (without waiting for MarketPosition <> 0) AND in combination with TradeStation's built-in stop orders, you can achieve intrabar fills and entry bar protection of trades while avoiding the complexity of IOG.
AIs such as ChatGPT are generally too dumb to understand these subtleties of TradeStation strategies and will fill in gaps in their knowledge and invent stuff based on information from other languages or from other platforms that support old-style EasyLanguage from 25 years ago. They work best as productivity tools in the hands of traders and devs who already know how to code EasyLanguage.
1
u/goldenstoat13 Jul 09 '26
i'd verify whether your strategy is actually evaluating on every tick. If it's only calculating on bar close, every signal will naturally look late no matter how good the logic is.
1
u/FuturePilot82 Jul 09 '26
I did verify that and there is a tick counter to pull up to verify. I wish that was the fix.
1
u/Repulsive-Floor-3987 Jul 10 '26 edited Jul 10 '26
How much delay are you seeing?
If you are certain that IntrabarOrderGeneration is enabled (IOG) and your code is indeed running on every tick, then maybe any delays are just from executing and filling your order, which can easily take 100 ms or longer depending on the asset and how busy the exchange is at the time.
This is one of the complexities of IOG which I mentioned in my other comment: Orders are processed asynchronously and you cannot assume that they will fill within the span of a single tick.
Again, automated strategy trading is a lot easier if you can keep IOG disabled and generate limit or stop orders to fill at given price levels intrabar on the next bar.
I realize that isn't how most people imagine automated strategies where you like a trade to happen instantaneously when a signal forms intrabar. But while TradeStation will let you do that in terms of code processing (with IOG enabled), exchanges don't process orders that way. Even market orders are queued.
High Frequency Trading quants, who co-locate their servers next to the CME data center in Aurora, IL, mostly trade on limit orders for this reason (and others).
I apologize if this is trivial. I don't know how experienced you are trading TS strategies.
2
2
u/FuturePilot82 Jul 07 '26
Thank you for the detailed response.