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

How to close position by time?

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

    How to close position by time?

    Hi!

    I want to open new position with Order with name = "2016.03.26 12.25" and make my strategy check this name and close this if current time is greater then order name.

    I want to be able to close NT and reopen it
    so I won't be able to get to entryOrder variable.
    entryOrder = EnterShort("2016.03.26 12.25");

    How can I check this, the last order name which opened the currently running position?

    #2
    Hello ronenk,

    The signalName of the order will identify the order and be set as the IOrder.Name.

    Code:
    IOrder myEntry = null;
    myEntry = EnterLong("An entry string 1");
    Print(myEntry.Name);
    The Position object does not provide the orders that make up the AvgPrice. This would need to be tracked with the IOrder handle.

    As you resume your strategy, assuming the strategy was designed to resume correctly (meaning there is a secondary 1 tick series for intra-bar granularity and the script is allowed to calculate historically and the on starting a real-time strategy setting is set to immediately submit live working historical orders), then the IOrder handle you use should be the same when you resume as the strategy will have taken all of the same actions historically as it did when running live.

    However, if you want the IOrder of the order that entered the position, you would need to capture this as the last order in OnExecution.
    Make some private IOrder object and set this to the execution.Order after your signal name is found.

    Code:
    private IOrder myFoundOrder = null;
    protected override void OnExecution(IExecution execution)
    {
    	if (execution.Name == "An entry string 1")
    	{
    		myFoundOrder = execution.Order;
    		Print(myFoundOrder.AvgFillPrice.ToString());
    	}
    }
    That said, there is an undocumented way of listing all orders for all accounts and not just orders made by this instance of this running strategy.
    http://ninjatrader.com/support/forum...376#post413376
    Last edited by NinjaTrader_ChelseaB; 03-21-2016, 07:54 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Economic calendar

      Thank you for your answer!

      I have another question, I hope you can help me with.

      I'm developing automatic trading strategy, it trades currency futures on market events such as: Non farm payroll, Purchasing Managers' Index (PMI), GDP etc.

      The strategy needs to look back on previous releases values and dates to decides how to trade, so I need to get access from NT to some kind of data array/series that will contain for example this kind of data:

      U.S. Manufacturing PMI
      Release Date Time Actual Forecast Previous
      Apr 01, 2016 (Mar) 09:45
      Mar 22, 2016 (Mar) 09:45 51.8 51.3
      Mar 01, 2016 (Feb) 10:45 51.3 51.0 51.0
      Feb 22, 2016 (Feb) 10:45 51.0 52.3 52.4
      Feb 01, 2016 (Jan) 10:45 52.4 52.7 52.7
      Jan 22, 2016 (Jan) 10:45 52.7 51.1 51.2
      Jan 04, 2016 (Dec) 10:45 51.2 51.1 51.3
      Dec 16, 2015 (Dec) 10:45 51.3 52.6 52.8
      Dec 01, 2015 (Nov) 10:45 52.8 52.6 52.6
      Nov 23, 2015 (Nov) 10:45 52.6 53.9 54.1
      Nov 02, 2015 (Oct) 10:45 54.1 54.0 54.0
      Oct 23, 2015 (Oct) 09:45 54.0 52.8 53.1

      Is there any convenient way to get this data straight from strategy script?

      Comment


        #4
        ronenk,

        I'm not entirely sure where this information comes from. I don't think this is fundamental data that is sent by the data provider.

        Likely, you will need to do a web request if you are getting this information from a website.

        Where are you getting this information?

        If it is from a file, this would be simple to stream read into a script.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          OK, I need the way to:

          1. Find this data
          2. Somehow pass it to the script

          I hoped there was some way to connect to economic calendar events through NT somehow, but now I see that there is no other way than to download this data to file from somewhere and read from this file in a script.

          Anyway, Thanks
          Ronen

          Comment


            #6
            How to read data from url and open position

            HI,

            I have remote server that generates trades, I need to go to URL, like this:
            www.xxxxxx.com/trades it returns the list of trades, in format: datetime,instrument, stop loss, takeprofit, like this:

            "2016-03-24 15:30","6A 06-16","30","40"
            "2016-03-26 17:37","6E 06-16","37","60"

            So what I need to create is the script that check every few minutes if there are new trades on that url and if they are, takes them, wait until the open time as in example "2016-03-24 15:30" open trades with sl and tp.

            So the questions are:

            1. How to run strategy instead of OnBarUpdate() on something like OnTimer(20) each 20 seconds.
            2. How to access remote url and get trades list.
            3. How to open position according to instrument (it can be anything, futures/stocks/indexes etc)

            Thanks in advance
            Ronen

            Comment


              #7
              Hello Ronen,

              To use a timer, take a look at this example I've made and posted to the forums.
              http://ninjatrader.com/support/forum...895#post427895

              Webrequests are not supported by NinjaTrader Support to do. However, take a look at this stackoverflow thread for some pointers from the C# community.
              http://stackoverflow.com/questions/2...-from-internet

              Placing an order will depend on where this script is running. A strategy is the only supported script that can place orders and will already need to be subscribed to instruments either by using that instrument as the primary series or by calling the Add() method with the instrument symbol to load a series for that instrument.

              If you are wanting to place orders from a script that is not a strategy, this would be outside of the realm of platform support. Below is a link where some of the NinjaTrader community discusses accessing accounts with unsupported / undocumented methods.
              http://ninjatrader.com/support/forum...ad.php?t=55687
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                There are traders working on all kinds of scale and in all kinds of time frames. These are traded within by choice, whether it’s the trader’s own choice or their employer’s. In most circumstances there aren’t going to be any broker or market set restrictions on you as to when you close positions. Believe me, they’ll happily take all the money you’re willing to give them.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by SightCareAubetter, Today, 12:55 PM
                0 responses
                0 views
                0 likes
                Last Post SightCareAubetter  
                Started by traderqz, Today, 12:06 AM
                8 responses
                15 views
                0 likes
                Last Post traderqz  
                Started by SightCareAubetter, Today, 12:50 PM
                0 responses
                1 view
                0 likes
                Last Post SightCareAubetter  
                Started by Mongo, Today, 11:05 AM
                4 responses
                14 views
                0 likes
                Last Post Mongo
                by Mongo
                 
                Started by Skifree, Today, 03:41 AM
                5 responses
                13 views
                0 likes
                Last Post Skifree
                by Skifree
                 
                Working...
                X