Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Exit Via Limit Orders Not Working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Exit Via Limit Orders Not Working

    I've got a strategy that basically ping-pongs... that is, it always has an open position, and with the exception of end-of-day handling, it only uses "EnterLong" or "EnterShort" as they conveniently exit any open/opposite position. I recently decided to try switching to limit orders, to see if I could improve the profit margin slightly. I directly replaced the existing EnterLong() and EnterShort() calls with their Limit counterparts, with limits set extremely high/low for debugging purposes. That is, the limits shouldn't prevent an order from occurring. Problem is, the script only enters the first position it comes to, and never places ANY exit orders at all. If I put ExitLong()/ExitShort() right before the enter/limit calls, the script works mostly as expected, except of course my exits aren't placed as limit orders. If I try to use ExitShortLimit()/ExitLongLimit() calls, they never work.

    Basically the following code works, exiting the short position, and entering the long via limit:

    ExitShort();
    EnterLongLimit(Quantity, 1000);

    And this doesn't, as it never places any orders to exit the short position, despite the fact that both functions should place such an order:

    ExitShortLimit(1000);
    EnterLongLimit(Quantity, 1000);

    I've tried manually setting the limits for both from 1 to 1000 (nominal price for the future I'm testing on is around 700) just in case I was somehow getting things backwards. I'm using the lastest/production NT 6.5. Any ideas what might be wrong?

    #2
    The Limit orders should be capable of reversing your position in the exact same manner as your EnterLong() and EnterShort() methods.

    I suggest you try to debug your code as per these tips: http://www.ninjatrader-support.com/v...ead.php?t=3418


    Also, this tip may be useful in understanding how Limit orders work in NinjaTrader: http://www.ninjatrader-support.com/v...ead.php?t=3271
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      TraceOrders was very useful, it showed that it was trying to enter the position, but was never trying to exit the open one first. I had a hunch, and commented out the stop loss and profit target bits in Initialize() (since those were the only other orders showing up) and then it worked as expected. I tried simplifying it, and adding only a simple profit target, but that again broke things. I tried with just a normal stoploss instead of a trailing one, and most every variation of the syntax possible for both those. It seems that if I have EITHER in place at all, then an enter/limit order won't exit the previous position. It doesn't even show up in the TraceOrder output. Weird.

      On the plus side, that got me far enough to test things (the strategy rarely ever hits a target/stop... they're just there for safety) and I quickly found the limit entries do more harm than good to my profit, so I no longer need to solve this. Just my curiosity left, wondering why adding a stop or profit target breaks the limit exit capability. I can only guess it has something to do with the being limit orders themselves, and NT doesn't cancel them before trying to do the exit order or some such. As I said, I no longer need to solve this, but I'm just posting this follow up in case anyone else runs across the same thing.

      Comment


        #4
        The most likely reason for the Limit orders not reversing your position is simply that the order was not resubmitted at every new bar. If a resubmission is not received on every bar NinjaTrader will automatically cancel that limit order.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rhyminkevin, Today, 04:58 PM
        3 responses
        48 views
        0 likes
        Last Post Anfedport  
        Started by iceman2018, Today, 05:07 PM
        0 responses
        5 views
        0 likes
        Last Post iceman2018  
        Started by lightsun47, Today, 03:51 PM
        0 responses
        7 views
        0 likes
        Last Post lightsun47  
        Started by 00nevest, Today, 02:27 PM
        1 response
        14 views
        0 likes
        Last Post 00nevest  
        Started by futtrader, 04-21-2024, 01:50 AM
        4 responses
        50 views
        0 likes
        Last Post futtrader  
        Working...
        X