Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

is it possible to create ATM strategy on the fly in an addon?

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

    is it possible to create ATM strategy on the fly in an addon?

    My addon has code like below:
    Order buyOrd = account.CreateOrder(Instrument,OrderAction.Buy,Ord erType.Market,TimeInForce.Day,1,0,0,"myOCO","Entry ",null);

    NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy("MyStrategy", buyOrd);
    It works only if I ALREADY HAVE AN ATM STRATEGY TEMPLATE NAMED 'MyStrategy' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK.

    My problem is I want to create "MyStrategy" on the fly in the addon code, instead of creating it manually on DOM in advance by mouse and keyboard, just like this:
    AtmStrategy myStrategy = new AtmStrategy();
    myStrategy.AddTarget();
    myStrategy.SetProfitTarget(xxx);
    myStrategy.SetStopLoss(xxx);
    myStrategy.SetTrailStop(xxx);

    // some code to add myStrategy to NT8 ATM Strategy Selection Control
    account.Strategies.Add(myStrategy);
    ...


    Order buyOrd = account.CreateOrder(Instrument, OrderAction.Buy, OrderType.Market, TimeInForce.Day, 1, 0, 0, "myOCO", "Entry", null);

    NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(myStrategy, buyOrd);
    is that possible?


    Another question is about CreateOrder(),
    CreateOrder(Instrument instrument, OrderAction action, OrderType orderType, TimeInForce timeInForce, int quantity, double limitPrice, double stopPrice, string oco, string name, CustomOrder customOrder)
    there's no any help information about the CustomOrder class. I saw it's definition, it has fields like AutoBreakXXX, AutoTrailXXX etc. I guess it maybe represent the "stop strategy" associated with ATM stragety, if so, it really important to me, could you provide some help or sample on this CustomOrder class?
    Last edited by jjhou; 10-29-2016, 03:56 AM.

    #2
    Hello,

    Thank you for the questions.

    Regarding your first item, ATM strategies are based off of a template system, for what you are wanting to do I can put in a feature request but currently it would not be possible to dynamically generate templates based on a order.


    The ATM strategies are separate from NinjaScript strategies in how they work, in the addon the ATM code would still work essentially the same as it did in NinjaScript.

    For the second item, I am also unable to see any information currently documented on this subject. I will provide a note to product management to see if that could be added for further clarification. Currently these documents are still under construction as the beta continues.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      What a pity...
      Then I have to work it around by another way, maybe writing code that simulate mouse/keyboard input to help me create/modify/delete a ATM template "automaticlly".
      Hope to see the feature in the future.

      Thank you anyway, Jesse

      Comment


        #4
        Hello,

        Rather than simulating user interaction, you may be able to use serialization for generating templates. If you can serialize or export a valid xml template that would likely be easier. There is no documentation/support for this subject and would only be a suggestion on something you could explore further if you wanted.

        This wouldn't necessarily be something I could suggest as there are likely roadblocks you will run into in doing this. But in theory this may be easier than trying to interact with the user interface through code. You could explore both routes and pick something that works for you.

        I have also submitted this as a feature request to have better NinjaScript support for generating templates.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          I really appreciate your suggestion! It helps me a lot, I have already done it through modifing ATM xml file, that save me a lot of time.

          Comment


            #6
            Hi Jesse,
            I met another problem, hope for your help. I wrote code like below:

            Order buyOrd = account.CreateOrder(Instrument, OrderAction.Short, OrderType.StopLimit, TimeInForce.Day, 1, 1.2400, 1.2400, "myOCO", "Entry", null);

            NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(myStrategy, buyOrd);
            For example, if I create a stop-limit order that shorts above the market, NT8 will pop up an error dialog tells me it cant' be above the market. The problem is how I detect the failure in the code?

            Appreciate your reply.

            Comment


              #7
              Hello,

              Thank you for the reply.

              The message is pretty clear as far as why it was rejected, can you tell me are you using static prices like shown or do you instead have variables for the prices used?

              To check what is happening, you could add Prints before the snytax provided to see what price you are submitting against, this could tell you if your variable or what is being used for the price is being calculated correctly.

              For example:

              Print(Close[0] + " 1.2400");

              This would just print the Close next to the price used, you could change the price used in the print to a variable if you are using a variable. If you are not using a variable and instead using static prices, it is very likely that the specific prices would not always be on the correct side of the market unless you have logic that ensures they are.


              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                yes, the message is pretty clear as far as why it was rejected, but it's not the point. The point is how to retrieve that error in my code, like this:

                Order buyOrd = account.CreateOrder(...);
                NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(myStrategy, buyOrd);

                bool orderSubmitFailed = ???

                if (orderSubmitFailed)
                {
                // do something...
                }
                else
                {
                // do something else
                }
                What I wondered is what I should assign to the variable orderSubmitFailed?

                Actually the price is provided by another external program, my AddOn receive it through TCP, so it may be invalid for current market data because the delay between sending and receiving, and that's why I need detect order submission result in my code. Now understand what I mean?

                Hope for your help, thanks.
                Last edited by jjhou; 11-08-2016, 08:56 PM.

                Comment


                  #9
                  Hello,

                  If you are not using prices coming from the native platform, I could not really comment on if that would work correctly or not, but you could use debugging to find what prices are being used to see what the problem is in more detail.

                  As far as taking action on an order rejection, you could look into the following item: http://ninjatrader.com/support/helpG...htsub=rejected



                  Please let me know if I may be of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by PaulMohn, Today, 05:00 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post PaulMohn  
                  Started by ZenCortexAuCost, Today, 04:24 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post ZenCortexAuCost  
                  Started by ZenCortexAuCost, Today, 04:22 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post ZenCortexAuCost  
                  Started by SantoshXX, Today, 03:09 AM
                  0 responses
                  16 views
                  0 likes
                  Last Post SantoshXX  
                  Started by DanielTynera, Today, 01:14 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post DanielTynera  
                  Working...
                  X