How to: Algo order logic to be long above X and short below X?

Discussion in 'Order Execution' started by BrandNewTrader, Mar 14, 2017.

  1. Not sure if this thread belongs in Index/Commodity Futures, Programming, Strat Dev, Trading software, etc, but it deals with an order logi issue so this is probably the best place.

    For background, I have about 10 years experience trading futures and options but I'm just now getting into automated systems via TT's ADL.

    I'm developing an algorithm to trade a particular futures and futures options strategy I have designed. I've been trading it manually or a few months and now want to automate it. Problem is, there is a particular order logic that I execute manually that I am having a hell of a time ensuring happens automatically. It seems like a common issue so I am just not seeing the trees from the forest.

    Suppose S&P is at 2400. I want to be LONG X contracts above 2400 and SHORT X contracts below 2400. That is the entire goal. This also applies to any other futures market. When trading manually I use a combo of OCO orders, buy/sell stops and alerts to manage the position. However, my fear is that automatically I will end up in a situation where the market moves one way or the other and I will not get filled on all X of my contracts, but the market will continue to move. Yes, I can use if/then logic at particular market levels to do a "check" and make sure my position quanitity is indeed X number of contracts (and not something less than X), but that seems like something I should be doing as a backup rather than the primary means of ensuring I am getting filled.

    S&P is at 2400, It moves up a few ticks to 2400.50 so my algo enters an order to buy 30 contracts at market. Filled at average price 2401. Now, if the market retraces to 2400 I will have a sellstop order to sell 60 contracts (X times 2 to reverse the position) at 2399.75. My issue is that my contract size HAS to be 30 contracts for strategic purposes. The transaction costs and losses on getting stopped out on 1 and 2 pt fluctuations repeatedly does not concern me (I deal with that another way). What concerns me is that the market may leave this buy/sell zone and I will NOT be holding my required 30 contracts.

    What kind of orders or order logic can I impose such that my orders are in the order book and cannot be hurdled or gapped over? If that happens I will have a backup in place to chase the fill, but as a PRIMARY means of order execution I'd like to efficiently ensure fulfillment of my contract size at the buy/sell point.

    Any takers? I am not as familiar with all of the order tactics as I could be, such as hidden and iceberg orders. I suppose these could play a part?

    Let me know if this thread will get better traction in a diff category.
     
  2. tommcginnis

    tommcginnis

    There's too much hidden info here.
    A better bet would be to configure some logic, and post it for people to poke holes in.
    As it is, I couldn't get from one end to the other without half-a-dozen WhatAbouts.

    But you covered the biggest: market price hurdling your presumed range. How many 50pt days have we had in the past two years?? About one every quarter?? Your logic has to handle that adroitly, AS A FIRST TEST, or you're bankrupted the first time out.
     
    Zzzz1 likes this.
  3. bpr

    bpr

    STOP market order(instead of STOP Limit order) guarantees execution but slippage can be anything. In a liquid market not much of a issue
     
    BrandNewTrader likes this.
  4. Gameboy

    Gameboy

    Id use state blocks for the cross over such as "last traded < 2400" which leads to a second state block last traded > 2400. So when price is below it loads the second state block ready to fire, as soon as it trades above it fires.

    The order management is far more complicated, but id start off taking a snap shot of the Bid or ask with the value extractor block and then figuring out what ever other criteria you want to meet the bid/ask. Something simple using the if/then block might work, such as 'IF' ASK Qty< Bid Qty then ASK Price, else Bid price.
     
    BrandNewTrader likes this.
  5. Zzzz1

    Zzzz1

    I can take a stab though I am not entirely sure what the real problem is. A market order by definition guarantees you a fill. A limit order does not. It's as simple as that. If you must absolutely get filled then you don't get around using market orders. I would still use limit orders just in order to protect yourself from worst case scenarios. So, the trigger logic you just build into your own algorithmic code according to your strategy and then fire a limit order that is potentially 5 or so points beyond the trigger price just in order to protect against worst case. You should get filled right away and in full size. If your net long/short volume is identical then you just buy and sell twice the net volume each time, other than your first and last trade from flat to flat. Does that help at all or what is the problem?

     
    Last edited: Mar 23, 2017
    BrandNewTrader likes this.
  6. Is this a typical execution method? Or have HFT algos sniffed out this protocol and bankrupted suh attempts?. I mean, If I am long above 2400 and short below 2400 for the duration of a month, this portion of my algo will only execute when the market is at the 2400 level. I the market just happens to have a prolonged fluctuation through (continuously hurdling) that 2400 level and I am in and out of my 30 (X) contracts repeatedly, let's say 10 times in 2 minutes, will an HFT pickup on this pattern and then trade against my algo and artificially prolong this fluctuation until I am bankrupt? I.E. crossing back and forth over 2400 until my algo can't buy/sell anymore because my capital is depleted from commissions and tick losses on 30 contracts.

    This is my main concern. The logic is simple, long above, short below. The level is selected by me and is not based on support, resistance or any other significant actor. It is simply where the market is when I decide to initiate the trade, usually at the beginning of the month. This is Why I don't fear the market naturally fluctuating over my level (i.e 2400) hundreds of times in one crossing/session because it's improbable, as modeled. However, I do worry about an HT latching onto this simple logic and then deciding to make 1/4 tick profit by ping-ponging my algo back and forth across my level continuously until my algo surrenders from lack of funds.
     
  7. tommcginnis

    tommcginnis

    "However, I do worry about an HT latching onto this simple logic and then deciding to make 1/4 tick profit by ping-ponging my algo back and forth across my level continuously until my algo surrenders from lack of funds."

    Jah-HEEZ-zuss, man!
    If that's your worry, get off of ET and get busy with your PC.
    "Monte Carlo is your friend!"

    Code this into a little game with a recorder, run it 50 or 100 times, and see how things play out. As it is, you're trying to "post up" on a search-n-destroy algorithm that has no interest in you, and you're looking for solutions from a social platform with 95% non-algo traders. That's nuts. (I mean, *Good Luck!* and all, but still: nuts.)
     
  8. Just need to modify the above code.
     
  9. straddle2340.png

    ninjatrader straddling 2340
     
    #10     Apr 13, 2017
    tommcginnis likes this.