• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Easy Enter/Exit Questions

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

    Easy Enter/Exit Questions

    how do I

    1. enter long (current chart instrument only)
    2. flatten all open positions in current account (current chart instrument only)
    3. cancel all unfilled orders in current account (current chart instrument only)

    e.g.
    Code:
    		public void flattenAccountPositions(Instrument i)
    		{
    			if (myAccount != null)
    			{
    				lock (myAccount.Positions);
    				myAccount.Flatten(new[] { i });
    			}
    		}
    		
    		public void cancelAccountOrders(Instrument i)
    		{
    			if (myAccount != null)
    			{
    				lock (myAccount.Orders);
    				foreach (Order order in myAccount.Orders)
    				{
    					if (order.Instrument == i)
    						myAccount.Cancel(new[] { order });
    				}
    			}
    		}
    when calling cancelAccountOrders what is "i" if it represent the chart instrument?
    Last edited by delTik; 06-08-2016, 07:28 AM.

    #2
    Hello,

    Thank you for your post.

    To start you will want to make sure you have Chart Trader enabled, you can do so either by clicking the Chart Trader button at the top of the chart or by:

    Right Click within the chart>Properties>Show Chart Trader = Set to 'True'

    This should give you a Buy and Sell column attached to your chart.

    To enter long simply click the 'Buy Market' button.

    To flatten all your positions right click within the chart trader column and select 'Flatten Everything'.

    To close all positions right click within the chart trader column and click 'Cancel All Orders' on the chart trader column.

    Remember that you will not see these options if chart trader is not enabled.

    I've included a link to our help guide on placing orders with Chart Trader.

    http://ninjatrader.com/support/helpG...art_trader.htm

    Please let us know if we may be of further assistance..
    Justin S.NinjaTrader Customer Service

    Comment


      #3
      ok thanks. I want to use c#
      Last edited by delTik; 06-08-2016, 07:56 AM.

      Comment


        #4
        Hello delTik,

        Thank you for your response.

        In NinjaTrader 8 NinjaScript you would use EnterLong() for to enter on the specific instrument through a strategy: http://ninjatrader.com/support/helpG.../enterlong.htm

        In an Add On Flatten() can be called to flatten an account: http://ninjatrader.com/support/helpG...us/flatten.htm

        Flatten() would cancel the orders as well.

        cancelAccountOrders is a custom method that needs an Instrument passed to it. If you need the instrument the strategy is running on, you would just pass through Instrument: http://ninjatrader.com/support/helpG...instrument.htm
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          thank you, a few questions ...

          "In an Add On Flatten() can be called to flatten an account:" can I call flatten anywhere else e.g. OnBarUpdate?

          calling cancelAccountOrders(Instrument) would use the instrument the strategy is running on?

          if I EnterLong and then Account.Flatten(Instrument) will the strategy assume it's still long i.e. be out of sync?
          Last edited by delTik; 06-09-2016, 02:43 AM.

          Comment


            #6
            Hello delTik,

            Thank you for your response.

            You can Flatten in OnBarUpdate. For example:
            Code:
            		protected override void OnBarUpdate()
            		{
            			// instantiate a list of instruments
            			List<Cbi.Instrument> instrumentsToCancel = new List<Instrument>();         
            			 
            			// add instruments to the collection
            			instrumentsToCancel.Add(Instrument);
            			 
            			// pass the instrument collection to the Flatten() method to be flattened
            			Account.Flatten(instrumentsToCancel);
            		}
            Calling Account.CancelAllOrders(Instrument) would cancel the orders for the instrument the strategy is running on.

            If you call Account.Flatten() your strategy will be disabled. As the account the strategy is running on was just set to flat.
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              so this is how it works ... (i.e. flatten always disables strategy if i = Position.Instrument)

              Code:
              		//flatten all account positions, orders & disable strategy (if i = Position.Instrument)
              		public void flattenAll(Instrument i, Account myAccount)
              		{
              			if (myAccount != null)
              			{
              				lock (myAccount.Positions);
              				lock (myAccount.Orders);
              				List<Cbi.Instrument> instrumentsToCancel = new List<Cbi.Instrument>();         
              				instrumentsToCancel.Add(i);
              				myAccount.Flatten(instrumentsToCancel);				
              			}
              		}
              		
              		//cancel all account orders
              		public void cancelAll(Instrument i, Account myAccount)
              		{
              			if (myAccount != null)
              			{
              				lock (myAccount.Orders);
              				myAccount.CancelAllOrders(i);
              			}
              		}

              Account.Flatten(instrumentsToCancel): no strategy equivalent

              and

              Account.CancelAllOrders(Instrument): strategy equivalent CancelOrder(Order order) cancels a specified order (no strategy "Orders" list available requires C# Order List management - synchronization?)
              Last edited by delTik; 06-13-2016, 07:44 AM.

              Comment


                #8
                sorry but totally confused, any help appreciated?

                Comment


                  #9
                  Hello delTik,

                  You would not be able to sync your orders with your account orders in this manner. Can you provide further detail on your inquiry from post #7?
                  Patrick H.NinjaTrader Customer Service

                  Comment


                    #10
                    its ok Patrick I think I understand what's happening. I think NT8 Beta11 synchronisation needs a rethink? Not having something easy in C# e.g.

                    adoptAccountPosition(Instrument), adoptAccountOrders(Instrument), myAccount.adoptStrategyPosition(), myAccount.adoptStrategyOrders()

                    and no strategy Orders collection that gets updated with adoptAccountOrders or something like that is a real pain.

                    this interface will cause me real hassle requiring tests for changes on new releases.
                    Last edited by delTik; 06-14-2016, 12:09 PM.

                    Comment


                      #11
                      Thank you for your feedback, delTik.
                      Patrick H.NinjaTrader Customer Service

                      Comment


                        #12
                        no problem Patrick,

                        NT8 is a great product but synchronization between account and strategy is letting it down. it needs to be done in C# at anytime quick and easy.

                        isStrategyInSync()
                        isAccountInSync()
                        myAccount.adoptStrategy()
                        adoptAccount()
                        Strategy Order List
                        etc.

                        I know there will be issues but will put NT8 ahead of the game. most of my work has been on Interactive Brokers api and feeling a bit constrained.

                        I hope you will pass on my comments?
                        Last edited by delTik; 06-21-2016, 01:14 AM.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by daya123, Today, 09:16 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post daya123
                        by daya123
                         
                        Started by Wingo, Today, 04:52 PM
                        1 response
                        9 views
                        0 likes
                        Last Post bltdavid  
                        Started by Bionian, Today, 10:10 AM
                        3 responses
                        20 views
                        0 likes
                        Last Post Bionian
                        by Bionian
                         
                        Started by D Trader, Today, 01:41 PM
                        0 responses
                        13 views
                        0 likes
                        Last Post D Trader  
                        Started by rexmie888, Today, 04:00 AM
                        1 response
                        10 views
                        0 likes
                        Last Post NinjaTrader_ShawnB  
                        Working...
                        X