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

        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.

            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?

                  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.

                      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 Kaledus, Today, 01:29 PM
                        0 responses
                        0 views
                        0 likes
                        Last Post Kaledus
                        by Kaledus
                         
                        Started by PaulMohn, Today, 12:36 PM
                        1 response
                        14 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by yertle, Yesterday, 08:38 AM
                        8 responses
                        36 views
                        0 likes
                        Last Post ryjoga
                        by ryjoga
                         
                        Started by rdtdale, Today, 01:02 PM
                        1 response
                        6 views
                        0 likes
                        Last Post NinjaTrader_LuisH  
                        Started by alifarahani, Today, 09:40 AM
                        3 responses
                        17 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Working...
                        X