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

AtmStrategy.StartAtmStrategy(aTM_Template, entryOrder);

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

    AtmStrategy.StartAtmStrategy(aTM_Template, entryOrder);

    Hi,
    this returns an instance of AtmStrategy:

    AtmStrategy strat = NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(aTM_Template, entryOrder);

    So far so good.

    Now let's say I want to change the stoploss orders of this AtmStrategy, for example to move to breakeven.
    If the method used for that was strat.AtmStrategyChangeStopTarget(...), how do I get the correct strategyId to use in this call? Neither strat.Id nor strat.AtmSelector work.

    If there is no way to access the needed strategyId, then is there another recommend method?
    I'd prefer not to dig into the Account and manipulate real orders because I want to avoid interfering with other possible simultaneous trades from other strategies on the same Instrument.

    Thanks,
    saltminer

    (p.s. this code is running in an indicator)

    #2
    Hi,
    over the weekend I implemented examining the orders in the Account, and filtering them based on order.GetOwner() to match my instance of an AtmStrategy. That works fine.

    HOWEVER, an unrelated matter is that when using NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(...) sometimes the AtmStrategy does not place its exit orders. This seems random.

    I've been using the same template for a few days, with a 50 tick stoploss and 50 tick target. Occasionally, it just doesn't do anything after entry. See screenshots.
    There are no errors in the log - just the "Entry" order getting filled then tumbleweeds.
    This is of great concern. What can I do to assist your investigation of this matter?
    This is on v8.0.26.1. I'm now downloading v8.0.27.0 and will continue testing.

    Regards,
    saltminer

    Click image for larger version  Name:	AtmStrategySettings.png Views:	0 Size:	21.5 KB ID:	1227072

    Click image for larger version  Name:	ChartScreenshot.png Views:	0 Size:	16.5 KB ID:	1227073
    Last edited by saltminer; 12-11-2022, 07:17 PM. Reason: fixed typo

    Comment


      #3
      Update: I can confirm the problem still exists in v8.0.27.0

      Comment


        #4
        Hello saltminer,

        Thank you for your patience.

        To see an example of a NinjaScript that uses AtmStrategyCreate() and manages the strategy ID to call AtmStrategyChangeStopTarget() I recommend reviewing the Strategy that comes with NinjaTrader by default called SampleAtmStrategy. This may be found in the NinjaScript Editor inside of the Strategies folder. What it does is saves the strategy ID to a variable prior to calling AtmStrategyCreate()

        atmStrategyId = GetAtmStrategyUniqueId();

        You may review lines 98-100 to see how the stop price is changed within the strategy. I understand that scripting via an indicator with the Account class uses StartAtmStrategy() rather than AtmStrategyCreate(), though I feel it is still valuable to see this example of how a NinjaScript strategy interacts with an ATM Strategy Template and orders.

        As for an ATM Strategy called from a script not placing exit orders, have you identified a way to reproduce this consistently? If so, please provide a reduced sample of your Indicator so we may test it on our end as well. Additionally, please check to make sure you are not using Submit() to submit the entry order and that it is being submitted only with StartAtmStrategy().

        I look forward to your reply.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Hi Emily,
          thanks but AtmStrategyCreate() is not relevant to this discussion, nor is the creation of an id, since StartAtmStrategy does not use an id in the signature nor offer one back as a return.

          But that question has been handled on this end, so my focus now is the problem of the started AtmStrategy not placing its exit orders.
          This is how the strategy is being started:


          // create order
          entryOrder = account.CreateOrder(Instrument, orderAction, OrderType.Market,TimeInForce.Day, quantity, 0, 0, string.Empty, "Entry", null);
          // submit to become an AtmStrategy
          AtmStrategy result = NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(aTM_Template, entryOrder);​

          That is pretty straightforward.
          It always opens a position. It sometimes does not go ahead and place exit orders as per the template, which is alarming.
          I will work up a reduced sample for your testing.

          saltminer

          Comment


            #6
            Hello saltminer,

            Thank you for the information.

            I look forward to reviewing your reduced sample. I would also like to see the ATM strategy template file. These files are located in the Documents\NinjaTrader 8\templates\AtmStrategy folder and are saved as XML files; please include a copy of the file with your sample. If you would prefer to work via email rather than posting your reduced sample and template file here in the forum, feel free to write to us at support[AT]ninjatrader[DOT]com and include "ATTN Emily 03572913" in the subject line along with a link to this forum thread in the body of your email.

            I appreciate your patience and look forward to investigating this matter further.
            Emily C.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Segwin, 05-07-2018, 02:15 PM
            14 responses
            1,788 views
            0 likes
            Last Post aligator  
            Started by Jimmyk, 01-26-2018, 05:19 AM
            6 responses
            837 views
            0 likes
            Last Post emuns
            by emuns
             
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            6 responses
            3,291 views
            1 like
            Last Post jgualdronc  
            Started by Touch-Ups, Today, 10:36 AM
            0 responses
            11 views
            0 likes
            Last Post Touch-Ups  
            Started by geddyisodin, 04-25-2024, 05:20 AM
            11 responses
            62 views
            0 likes
            Last Post halgo_boulder  
            Working...
            X