NexusFi: Find Your Edge


Home Menu

 





Getting duplicate fills in automated strategy


Discussion in TradeStation

Updated
    1. trending_up 3,826 views
    2. thumb_up 11 thanks given
    3. group 2 followers
    1. forum 12 posts
    2. attach_file 1 attachments




 
Search this Thread

Getting duplicate fills in automated strategy

  #1 (permalink)
Donovan2580
Port St. Lucie, FL
 
Posts: 36 since Jul 2016
Thanks Given: 22
Thanks Received: 37

Hello,

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.

Thanks for your time,

Donovan

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
How to apply profiles
Traders Hideout
Trade idea based off three indicators.
Traders Hideout
Better Renko Gaps
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
22 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (permalink)
 
vmodus's Avatar
 vmodus 
Somewhere, Delaware, USA
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,271 since Feb 2017
Thanks Given: 2,958
Thanks Received: 2,853

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.

~vmodus

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #3 (permalink)
Donovan2580
Port St. Lucie, FL
 
Posts: 36 since Jul 2016
Thanks Given: 22
Thanks Received: 37


Thanks VModus,

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.

Thanks much for taking the time to answer

Donovan

Reply With Quote
  #4 (permalink)
Donovan2580
Port St. Lucie, FL
 
Posts: 36 since Jul 2016
Thanks Given: 22
Thanks Received: 37

I have searched everywhere on this forum and cannot find any reference to adding a delay after a order.

I did find a reserved word, but it only works in minutes or hours, not seconds...

Anyone have any ideas?

Thanks

Reply With Quote
  #5 (permalink)
 
vmodus's Avatar
 vmodus 
Somewhere, Delaware, USA
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,271 since Feb 2017
Thanks Given: 2,958
Thanks Received: 2,853


Donovan2580 View Post
Thanks VModus,

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.

Thanks much for taking the time to answer

Donovan

I'm kind of busy this morning, but I will try to write something this afternoon. It shouldn't be too hard, but I need some more info:
  • What kind of chart type are you using? (time, tick, etc.). Please give me the parameters so I know my code will match.
  • What order type are you using? Include the buy and sellshort statements (e.g. buy this bar at close).

~vmodus

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #6 (permalink)
 
vmodus's Avatar
 vmodus 
Somewhere, Delaware, USA
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,271 since Feb 2017
Thanks Given: 2,958
Thanks Received: 2,853


Donovan2580 View Post
I have searched everywhere on this forum and cannot find any reference to adding a delay after a order.

I did find a reserved word, but it only works in minutes or hours, not seconds...

Anyone have any ideas?

Thanks

I'll work on this later,, but TradeStation forums can be a useful resource.

~vmodus

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #7 (permalink)
Donovan2580
Port St. Lucie, FL
 
Posts: 36 since Jul 2016
Thanks Given: 22
Thanks Received: 37

Thanks for the help VModus,

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.

My buy/sell statements are pretty simple:

Buy 1 contract next bar at market.

or

Sellshort 1 contract next bar at market.

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.

Thanks again!!

Donovan

Reply With Quote
Thanked by:
  #8 (permalink)
 
vmodus's Avatar
 vmodus 
Somewhere, Delaware, USA
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,271 since Feb 2017
Thanks Given: 2,958
Thanks Received: 2,853


Donovan2580 View Post
Thanks for the help VModus,

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.

My buy/sell statements are pretty simple:

Buy 1 contract next bar at market.

or

Sellshort 1 contract next bar at market.

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.

Thanks again!!

Donovan

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.

Stay tuned...


~vmodus

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #9 (permalink)
 
vmodus's Avatar
 vmodus 
Somewhere, Delaware, USA
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,271 since Feb 2017
Thanks Given: 2,958
Thanks Received: 2,853

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)
  1. If we are in a position, then reset the pending_order variable to false (allows us to trade when the next signal comes along)
  2. 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
  3. Place order
  4. 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):
 
Code
vars:
   pending_order(false) ;   // true = we have an order placed, but not filled... do not enter again; 
                               // false = we do not have any pending orders

if Marketposition <> 0  // we are in a position
   then 
      pending_order = false ; 


if Low > Low[1] and Low[1] > Low[2]
   and Marketposition = 0 
   and pending_order = false
   then
      begin 
         Buy next bar at market;
         pending_order = true ; 
      end ;

Setprofittarget(100) ; 
Setstoploss(50) ;
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.

Let me know if this solves your problem.

~vmodus

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #10 (permalink)
Donovan2580
Port St. Lucie, FL
 
Posts: 36 since Jul 2016
Thanks Given: 22
Thanks Received: 37


Hey VModus,

You work fast my friend!

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.

Great idea & thanks again!

Donovan

Reply With Quote
Thanked by:




Last Updated on June 30, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts