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

Order Management

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

    Order Management

    Hello,

    How would I go about using a bool to prevent an order in progress from being force closed by a new order? I currently have an issue when I have an open order(long) and the conditions become true for a short order, the short order will try and force close the long order, causing the strategy and NT to crash.

    Thank you,
    Chris

    #2
    Hello Chris,

    Thanks for opening the thread.

    Are you referring to an open position that is being closed and reversed when you submit an entry method in the opposite direction?

    Or are you mentioning that you have an active order that is getting cancelled when you are submitting an Order in the opposite direction?

    The first case would have to do with the Internal Order Handling rules reversing your position when an entry is called in the opposite direction. It would be expected then to have the entry for the opposite direction close the current position and re-enter in the opposite direction.

    If you would like to avoid this behavior, you will want to make sure your conditions to enter are only made when you are in a flat position. Please see Position.MarketPosition below. Another option would be to separate the strategy into a Long and Short version.

    The second case also has to do with Internal Order Handling rules where an entry for an opposite direction will be ignored when active order in one direction exists. If you do not call the entry method for the first order, it will be cancelled if you are not using the isLiveUntilCancelled overload. I am not sure the moments after this that would lead your strategy to submit an order that gets rejected and aborts the strategy.

    Please be sure to review the Internal Order Handling rules when designing your strategy. I have included publicly available documentation on the items discussed.

    Internal Order Handling - https://ninjatrader.com/support/help...antedPositions

    Position.MarketPoisition (to detect when you are in a flat position before attempting to enter in an opposite direction to avoid reversals) - https://ninjatrader.com/support/help...etposition.htm

    isLiveUntilCanelled overloads - https://ninjatrader.com/support/help...ancelledOrders

    Please let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Jim,

      Thank you. I was able to get that to work. Now as for the stop loss action, I am using 2 contracts and having my stoploss break even when the first contract is filled and closed. With the remaining contract though, I would like the stop loss to then trail the remaining contract by 6 ticks or so. Is this possible? I would like it turn into a trail stop after breakeven has been achieved.

      Thanks,
      Chris

      Comment


        #4
        Hello Chris,

        It would not be possible to use SetStopLoss() to take a portion of the strategy's position. You could use your own exit methods, though.

        For example, you could use an ExitLongStopMarket() order for the first contract of your stop loss and another ExitLongStopMarket() for the other contract. As long as the exit's signal names are unique you can have both orders active. Please see the documentation page for using an overload that lets you specify a Signal Name for the exit.

        You can then update that order by calling the method again with a new price level. This could be, for example, after your first contract has exited. You can use BarsSinceExitExecution() to detect when an exit has occurred or you may use OnExecutionUpdate().

        The SampleOnOrderUpdate strategy provides an example for modifying an order to breakeven and using OnExecutionUpdate(). An auto trail only differs that the order is frequently updated in association to the current price rather than the average entry price.

        BarsSinceExitExecution() - https://ninjatrader.com/support/help...texecution.htm

        ExitLongStopMarket() - https://ninjatrader.com/support/help...stopmarket.htm

        OnExecutionUpdate() - http://www.ninjatrader.com/support/h...xecutionUpdate

        SampleOnOrderUpdate - https://ninjatrader.com/support/foru...ead.php?t=7499

        If there is anything else we can do to assist, please let us know.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        59 views
        0 likes
        Last Post DynamicTest  
        Started by ScottWalsh, Today, 06:52 PM
        4 responses
        36 views
        0 likes
        Last Post ScottWalsh  
        Started by olisav57, Today, 07:39 PM
        0 responses
        7 views
        0 likes
        Last Post olisav57  
        Started by trilliantrader, Today, 03:01 PM
        2 responses
        22 views
        0 likes
        Last Post helpwanted  
        Started by cre8able, Today, 07:24 PM
        0 responses
        10 views
        0 likes
        Last Post cre8able  
        Working...
        X