Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I have a quick question. I am running an automated strategy that enters when the price crosses a indicator (Lets just say a MA)... Everything works great 90% of the time, but on a rare occasion it will make duplicate orders back to back within a second. So I am left with 2 contracts when I only asked for one.
This is running intrabar... Order placed is a market order.
I have pyramiding turned off, so I know it is not that. I have toggled the "Wait until UROUT" option in the automation tab and that didn't seem to do anything.
My best guess is that maybe since I am running this intrabar it is sending another signal before I get the return from TS that the original was filled?!?
Does anyone have any other ideas or suggestions?
Again 90% of the time it works as planned - This is why it confuses me.
I think what is happening is that in the milliseconds that it takes for the order to get sent to TradeStation, your strategy detects the same condition before it detects that you are in a position. Here are the settings I use for a strategy that uses stops (my wife, also a trader, recommended these to me):
If this doesn't help, then there are a few ways you can probably code around it, primarily by setting a short waiting period after the order is sent. I know there are a few ways to do this.
Let me know if the above settings work or not, and maybe I can help you further.
Your Screenshot is exactly how I have my settings configured.
The idea of setting a short waiting period sounds interesting. It happened to me again in the MES (Thankfully the micro) when it was really fast. I ended up with 4 contracts this time which was a first. When the market is moving at a "normal" speed, I always get 1 contract just the way I have it coded.
Do you know how I would code a waiting period to give Tradestation a chance to sync up? I imagine a 1 second pause should be sufficient.
I am using a tick bar chart... Usually a smaller time frame (500 tick) I am running intrabarordergeneration on though - So technically each new tick is a new bar (If I understand that correctly). I am trading MES or ES if that matters.
I have waded through the TS forums and didn't see anything that would help me out. As I said, I did find a reserve word that might work but the smallest time frame I can reference is minutes... I need seconds.
When I help people, it helps sharpen my coding skills and I can sometimes write something that is useful for me at some point. I'll work on it now..... with ticks, I may need to wait n-bars for that order.
Okay, this was a little easier than I thought. So here is how it works, plain English:
pending_order: if this value is true, then we have placed an order, but it is not filled. This prevents a new order from being placed until the order is fulfilled. Once it is filled, then it is false and ready for a new trade.
Check to see if we are in a position (Marketposition <> 0)
If we are in a position, then reset the pending_order variable to false (allows us to trade when the next signal comes along)
In the order entry section, if our condition for entry is met and we are not in a position (Marketposition = 0) and pending_order flag is false then
Place order
Set pending_order flag to true
Once the order if filled, the pending_order flag is reset (step 1), and the world keeps spinning.
Here is a simple sample strategy that demonstrates it (I use profit target and stop loss for my exits):
This is not a tradable strategy as-is, just something I threw together. Test the code execution in sim before you try to execute live. Live trading will also differ from sim, so just be aware of that.
I think this is a much better approach than trying to use a timer, which is kind of a "half *ss" workaround.
When you say it will perform differently in live vs sim - you just mean because the Sim always gets filled immediately on limit orders, etc when in real life it may or may not be filled, correct? Or are there other gotchas I am not aware of?
I will give this a shot and let you know later tonight how it comes out. I don't see any reason why it will not work though.