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

switch from manual trading to auto

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

    switch from manual trading to auto

    Hi, please give me some advice. I want to make a position, then switch on an automated strategy to set the stop in every bar, and the position will close in that way. What is the best way, when I have an open position, and I want to be managed it by a strategy. What is the right set of the "wait until flat before live", or "immediately submit live ..." and the sync account position would be false or true. And there is a method to scan the live positions? So, my goal is:
    - I start a position manually
    - Then I start a strategy, wich will recognise the position, and from this time this position will be contorlled by the strategy (stop, exit...)

    Thank you for advance
    Akos

    #2
    Hello akkiss,

    Using supported methods, strategies are not able to detect orders placed outside of that instance of the strategy.

    You may be able to achieve this with unsupported code, but the NinjaTrader Support will not be able to assist.

    To point you in the right direction, below is a tip of unsupported code you may find helpful.

    Code:
    foreach (Account acct in Cbi.Globals.Accounts)
    {
    if (acct.Positions != null)
    {
    // print information about each position
    PositionCollection positions = acct.Positions;
    foreach (Position pos in positions)
    {
    Print(pos.Account.Name + " " + pos.Instrument + " " + pos.MarketPosition + " " + pos.Quantity + " " + pos.AvgPrice);
    }
    // print information about each order
    OrderCollection orders = acct.Orders;
    foreach (Order ord in orders)
    {
    Print(ord.ToString());
    }
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB
      Thank You for your answer. I see, that this script will dump the parameters of the running positions to the output window. In our case we have only one position, but how will accept it the Ninja strategy?
      Best regards Akos

      Comment


        #4
        Hello akkiss,

        The unsupported code tip is meant to go in a strategy and detect your manual orders.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi ChelseaB

          Sorry, it isn't clear. After this, I can use the managed or unmanaged part of order commands, to enter submits? Need it to set the sync parameters in Ninja? What kind of array the Cbi.Globals.Accounts?
          Sorry for the stupid questions I can't see the solution yet.


          Kind regards

          Akos

          Comment


            #6
            Hello akkiss,

            You would likely use the unmanaged approach as any manual order that is detected by the strategy will not be added to the Strategy Position.

            You would call this when you wanted to detect that a manual order has been placed.

            Your inquiry was to detect a manual order that was placed and submit protective orders to cover it correct? If so, you need to detect the manual order. This code is to detect the manual order.

            The code can pretty much be added anywhere in a method. So you want to detect the orders when the script starts then add this code to OnStartUp. If you want to detect this on a button click then add a button click and run this code. etc.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi ChelseaB
              I have to think through your advice, that will be the solution!
              Thank you for your time
              Kind regards
              Akos

              Comment


                #8
                Hí ChelseaB
                I have a new question, sorry I'm not experienced in C#, but Im studying. I see, we got the Order object. But I need the IOrder read only interface, if I want to use the ChangeOrder, or CancelOrder methods. How can I generate from Order object an IOrder interface?
                Thank you for your time
                Akos

                Comment


                  #9
                  Hello akkiss,

                  To create an IOrder variable to store the order:
                  private IOrder myOrder = null;

                  To cast an existing order object to an IOrder variable:
                  myOrder = (IOrder) ord;

                  http://www.ninjatrader.com/support/h...nt7/iorder.htm
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi ChelseaB
                    Thank you for your answer. I inserted the lines. First to the variables, th seconds to the OnBarUpdate methods. I got an error warning, from the editor, so I inserted a new line to the variables:
                    private Order ord = null
                    The compiling was succesfull, but the result is not very good. In this script I want to print out the parameters of the myOrder, wich is equal the ord, wich shows the running ("hand-made") position. The first part of the script contains your one in the OnStartUp method, then comes the OnBarUpdate. It contains the line from your last letter
                    myOrder = (IOrder) ord;
                    and anothers, to print the myOrder.

                    This:

                    protected override void OnBarUpdate()
                    {

                    if(Historical)
                    return;

                    myOrder = (IOrder)ord;
                    Print("+++++++++++++++");
                    Print (ord.ToString()); //secondary it was deleted
                    Print(Time[0].ToShortTimeString());

                    if(myOrder != null)
                    {
                    Print("writing out the myOrder");
                    Print (myOrder.ToString());

                    // ChangeOrder(myOrder, myOrder.Quantity, 0, stopPrice);
                    // Print("betette a stopot");
                    }


                    Print("end of the OnBarUpdate ");
                    }


                    }

                    #region Properties
                    // [Description("")]
                    // [GridCategory("Parameters")]
                    // public int MyInput0
                    // {
                    // get { return myInput0; }
                    // set { myInput0 = Math.Max(1, value); }
                    // }
                    #endregion

                    }

                    I made a position in the chart trader, then started this script, (EURUSD, M2). First in the output window the order parameters appeared, then I got an error warning:
                    **NT** Error on calling 'OnBarUpdate' method for strategy 'STteszt1/b14e81b9bb5547ad965a651c86d672e1': Object reference not set to an instance of an object.
                    I can't understand it. Second, I ereased a line after the +++++++++++++++++, (remarked on the script) and this case I didn't get the error warning, but the printing was not succesfull too.
                    What would be the failure?
                    My goal is: First make a position, then start a script, wich reconise the position, and add to it a stop, or profit target, or exit the position. I took your advice, but may be, that the right place of "myOrder = (IOrder) ord;" is not in the OnBarUpdate method? I hope You can help me.
                    Thank for advance
                    Akos

                    Comment


                      #11
                      Hello akkiss,

                      This is unsupported code that I cannot assist with.

                      However, this thread will remain open for any community members that would like to contribute.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi ChelseaB
                        My last question
                        How can I get more detailed knowledge about ninja script than the ninja help?
                        kind regards
                        Akos

                        Comment


                          #13
                          Hello akkiss,

                          The best source for learning NinjaScripts are the reference and tip samples.

                          Reference samples - http://www.ninjatrader.com/support/f...ead.php?t=3220

                          Tip samples - http://www.ninjatrader.com/support/f...ead.php?t=3229

                          Also, the indicators and strategies on the forum are very helpful.
                          http://www.ninjatrader.com/support/f...splay.php?f=37

                          You can also contact a NinjaScript Educator for one-on-one assistance. Would you like a link to the Ecosystem Educator partners?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Thank You, it's enough for me first!

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Christopher_R, Today, 12:29 AM
                            0 responses
                            9 views
                            0 likes
                            Last Post Christopher_R  
                            Started by sidlercom80, 10-28-2023, 08:49 AM
                            166 responses
                            2,235 views
                            0 likes
                            Last Post sidlercom80  
                            Started by thread, Yesterday, 11:58 PM
                            0 responses
                            3 views
                            0 likes
                            Last Post thread
                            by thread
                             
                            Started by jclose, Yesterday, 09:37 PM
                            0 responses
                            8 views
                            0 likes
                            Last Post jclose
                            by jclose
                             
                            Started by WeyldFalcon, 08-07-2020, 06:13 AM
                            10 responses
                            1,415 views
                            0 likes
                            Last Post Traderontheroad  
                            Working...
                            X