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

ATM Strategy Close/Invert

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

    ATM Strategy Close/Invert

    Hello,

    I have a add-on thats opens an ATM Strategy:

    Code:
    string entry_name = "Entry";
    Order order = Account.CreateOrder(Instrument, OrderAction.Buy, OrderType.Market, OrderEntry.Automated, cbxTif.SelectedTif, quantityToExecute, 0, 0, oco, entry_name, gtd, customOrder);
    AtmStrategy.StartAtmStrategy(cbxStrategySelector.SelectedAtmStrategy, order);
    I have a ATM strategy that has a 3 ticks stop loss.

    After open a LONG position with this strategy, the stop loss automatically enters 3 ticks bellow. So far so good.

    With this code, I can close the opened position:

    Code:
    Order order = Account.CreateOrder(Instrument, OrderAction.Sell, OrderType.Market, OrderEntry.Automated, cbxTif.SelectedTif, quantityToExecute, 0, 0, oco, "Sell", gtd, customOrder);
    Account.Submit(new[] { order });
    after the position close, the ATM stop loss (3 ticks below) still online and didn't canceled.

    How can I invert or close a position openned with an ATM Strategy, and all the limit/stop ordens from that strategy also be closed in a smart way?

    Thanks

    #2
    Hello Rudmax,

    Thanks for your post.

    ATM strategy Profit target and Stop loss orders are tied together with OCO, so the same OCO id would have to be used with the close position/reversal order, or you would have to cancel the order yourself with CancelOrder(). To note with reversals involving ATM strategies, NinjaTrader handles this by creating a reversal order at the same price level which then re-enters in the the opposite direction since the target or stop get filled/cancelled from OCO pairing. NinjaTrader does not use a native OCO id with the reversal order.

    I may suggest checking the Account's OrderUpdate events to catch the OCO of the generated ATM strategy orders if you would like to tie the orders together.

    OrderUpdate events - https://ninjatrader.com/support/help...rderupdate.htm

    CancelOrder() - https://ninjatrader.com/support/help...-us/cancel.htm

    Please let me know if there is anything else I can do to help.

    JimNinjaTrader Customer Service

    Comment


      #3
      Hello Jim, Thanks for your reply!

      I´m chasing the same SuperDOM behaviour. With SuperDOM, it is possible to open a ATMStrategy with EXIT behaviour:

      Code:
      This order is an ATM strategy controlled order : orderId='eef699b933f341c5affefc1e531f2cb5' account='Sim101' name='[B]Exit[/B]' orderState=Initialized instrument='ES 12-18' orderAction=Buy orderType='Limit' limitPrice=2571.75 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=297 time='2018-12-18 11:04:15' gtd='2099-12-01' statementDate='2018-12-18'
      But I only could open a Entry AtmStrategy like saying: https://ninjatrader.com/support/help...erence_wip.htm

      Critical: The "name" argument on the CreateOrder() method MUST be named "Entry" for the ATM Strategy to be started successfully.

      Code:
      string entry_name = "[B]Entry[/B]"; // [U][B]"Exit" will not work[/B][/U]
      Order order = Account.CreateOrder(Instrument, OrderAction.Sell, OrderType.Market, OrderEntry.Automated, cbxTif.SelectedTif, quantityToExecute, 0, 0, oco, entry_name, gtd, customOrder);
      AtmStrategy.StartAtmStrategy(cbxStrategySelector.SelectedAtmStrategy, order);
      So, when using ATMStrategy with my AddOn, could left with some broken stop loss orders. Like the screenshot:

      Click image for larger version

Name:	Anotação 2018-12-18 142940.jpg
Views:	516
Size:	115.6 KB
ID:	1043171

      Could be possible I send you the source code (Vendor FlowBots) to help me figure it out how to get the same SuperDom behaviour?

      Best Regards,

      Comment


        #4
        Hello Rudmax,

        How are you entering your ATM strategy with an order named "Exit" from the SuperDOM? Could you give me some steps I could take to do the same? My expectation would be that we would only see ATM associated orders called "Entry" "Stop1" "Target1" etc.

        As for modelling the behavior of the SuperDOM for ATM strategies, this would actually just be a behavior for ATM order handling that isn't specific to the SuperDOM window.

        My advice for modelling the behavior that we observe when using the SuperDOM would be in line with post 2.
        1. Order for opening the ATM strategy is submitted with "Entry"
        2. ATM strategy is created with this order
        3. Manually closing the position with another order should use CancelOrder() to cancel the active orders
        4. Reversing ATM position should be made by creating an additional "Entry" order at the reversal level for a new ATM strategy. If you are trying to have reversals at both target and stop, additional logic should be added to cancel the reversal orders if one fills.
        Essentially, modelling your ATM strategy handling as Entries, Targets, and Stops should be enough to effectively use ATMs in your AddOn.

        If you have specific questions about your code, you can send us an email to platformsupport [at] ninjatrader [dot] com and my teammates and I on the NinjaScript team could give some further input. Typically, we will refer to the AddOnFramework example that shows how AddOn code can be used/tested. I'd also want to note that we don't have resources for in depth analysis of 3rd party code, so it is often best to communicate using small samples or with the samples that we have provided. With that in mind, please feel free to reach out.

        I look forward to being of any further assistance.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hello Jim,

          My expectation would be that we would only see ATM associated orders called "Entry" "Stop1" "Target1"
          I have captured the order update event from an superdom action and realize that superdom can create a atmstrategy order with "Exit" name on it if already have a position at the current account/instrument.

          Code:
          This order is an ATM strategy controlled order : orderId='eef699b933f341c5affefc1e531f2cb5' account='Sim101' name='[B]Exit[/B]' orderState=Initialized instrument='ES 12-18' orderAction=Buy orderType='Limit' limitPrice=2571.75 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=297 time='2018-12-18 11:04:15' gtd='2099-12-01' statementDate='2018-12-18'
          This was my concern about if it is possible to create a Exit atm strategy order. But I can´t. Let´s moving on

          To exemplifly, how do I enter an ATM Strategy:

          Code:
           string entry_name = "Entry";
          Order order = Account.CreateOrder(Instrument, OrderAction.Sell, OrderType.Market, OrderEntry.Automated, cbxTif.SelectedTif, quantityToExecute, 0, 0, oco, entry_name, gtd, null);
          AtmStrategy.StartAtmStrategy(cbxStrategySelector.SelectedAtmStrategy, order);
          And to Exit:

          Code:
          string entry_name = "Entry";
          Order order = Account.CreateOrder(Instrument, OrderAction.Buy, OrderType.Limit, OrderEntry.Automated, cbxTif.SelectedTif, quantityToExecute, lastBid, 0, oco, entry_name, gtd, null);
          AtmStrategy.StartAtmStrategy(cbxStrategySelector.SelectedAtmStrategy, order);
          With this code above, If the market hit my Buy Bid order, I end up with two stop loss orders at the book.

          For this example I´m using a 3 Tick stop Loss ATM Strategy like the image send in a previous reply.

          You are correct, maybe I need to modelling some behavior to mimic the superdom, except for the ATMStrategy order that superdom can create with "Exit" name.

          Thanks for your help!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by adeelshahzad, Today, 03:54 AM
          4 responses
          25 views
          0 likes
          Last Post adeelshahzad  
          Started by merzo, 06-25-2023, 02:19 AM
          10 responses
          823 views
          1 like
          Last Post NinjaTrader_ChristopherJ  
          Started by frankthearm, Today, 09:08 AM
          5 responses
          17 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          43 views
          0 likes
          Last Post jeronymite  
          Started by yertle, Today, 08:38 AM
          5 responses
          16 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X