Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Instrument.Expiry for added instruments

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

    #16
    You could either close the short and then enter long 500 or just enter long with the 500. Both would close out your short position and then enter long 500 but the later option would first exit with a market order and then enter long.
    LanceNinjaTrader Customer Service

    Comment


      #17
      Perfect. If I'm short and I select GetAccountValue(AccountItem.CashValue), will it take into consideration the cash I receive by shorting?

      Comment


        #18
        Most likely yes. This will only work in real time and will depend on how the broker reports this value. Whether or not it includes the unrealized PnL will depend on the broker.
        LanceNinjaTrader Customer Service

        Comment


          #19
          Thanks again. I have new 2 problems now.

          1. I need to find the number of open market days between 2 dates. I can find the net number of days between 2 days, but then I have to test each day to see if it's a trading day. Is there a function that can do so?

          2. I need to have data for the past 20 days (CLOSE ONLY) of VIX Futures prices. There are 2 ways to do so. The most stable (and hardest/most expensive) way would be to have a feed with that data and then run an algo that will go get the data. I'm pretty sure IB will get me this info, but I also need the data for futures that have expired, if they've expired in the past 20 days. And I'm not entirely sure IB has that data. In that case, I'll need a new feed, which is kind of expensive. The other way would be to create an array with 20 slots that saves the close at the end of each day. That way I'll have my own data saved at all times. My issue with this is: Can my algo save data for the past 20 days securely? Is it possible to lose that data if the algo is ever disabled or disconnected?? If not, then it's the way to go, but it's seems risky.

          Comment


            #20
            Hello jean9114,

            1. There is not a supported function for this so you may have to calculate this manually. Best way of doing something like this would be to check to see how many day in-between each date that you would like to check.

            2. Once, you have downloaded the Historical Data it will be on your computer and Strategy will not delete or alter the historical data unless specifically programmed to do so.

            Click here to view more information on Historical Data and Understand the data provided by your connectivity provider
            JCNinjaTrader Customer Service

            Comment


              #21
              Ok. What happens if I try to get the close for a day that wasn't open?

              And if I say Close[3], will that go back exactly 3 days, or 3 business days? (Tuesday back to Saturday VS Tuesday back to Thursday)

              Also, using Bars.GetDayBar(days).Close, how do I get the Bars for an instrument that I added with Add()??

              Thanks.
              Last edited by jean9114; 04-04-2013, 03:43 PM.

              Comment


                #22
                Hello jean9114,

                Thanks for your note.

                Referencing a bar index that does not exist will always cause an error.
                Depending on how you are accessing the invalid bar the message will be:
                Index out of bounds of array
                Or
                Error on calling 'OnBarUpdate' method for indicator '<strategy name>' on bar 0: Object reference not set to an instance of an object.
                Or
                Error on calling 'OnBarUpdate' method for indicator '<strategy name>' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                You can check that a bar is valid with the bar index using the DataSeries method IsValidPlot.
                For example:
                if (Close.IsValidPlot(CurrentBar - 3))
                Print("Bar exists");

                This code will check that the bar 3 bars ago is valid by getting the CurrentBar number of 3 bars ago.


                When using the primary dataseries, the bars will be created according to the session template. So if you were to have a daily bar, and a session template that does not include weekends, such as the CME US Index Futures RTH, then the Close[3] on Tuesday will reference last Thursday. Using the default 24/7 template, Close[3] on Tuesday will reference Saturday.

                To see which what days specifically your script is using, change the interval to Daily and use the following line in an script:
                if (Close.IsValidPlot(CurrentBar - 3))
                Print(Time[0]+" - "+Time[3]);

                Below is a link to the help guide on Using the Session Manager.
                http://www.ninjatrader.com/support/h...on_manager.htm


                To reference the secondary dataseries you will need to use BarsInProgress to only execute when the second dataseries is processing.

                For example:
                If (BarsInProgress == 1)
                Print(Bars.GetDayBar(days).Close);

                Below is a link to the help guide on Multi-Time Frames & Instruments. Please refer to the section 'Accessing the Price Data in a Multi-Bars NinjaScript'.
                http://www.ninjatrader.com/support/h...nstruments.htm


                Please let me know if this does not resolve you inquiry.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #23
                  Wow, thank you so much. I didn't even know about the output window. I've debugged so much code!

                  I have another problem. Whenever my code signals to buy, it buys, but whenever I'm already long and want to buy more, it doesn't run. I'm using EnterLong. I don't know if I'm supposed to use another function.

                  Thanks again!

                  Comment


                    #24
                    Originally posted by jean9114 View Post
                    Wow, thank you so much. I didn't even know about the output window. I've debugged so much code!

                    I have another problem. Whenever my code signals to buy, it buys, but whenever I'm already long and want to buy more, it doesn't run. I'm using EnterLong. I don't know if I'm supposed to use another function.

                    Thanks again!
                    You need to specify a value for EntriesPerDirection.

                    ref: http://www.ninjatrader.com/support/h...rdirection.htm

                    Comment


                      #25
                      Great! One last issue. How can I reset a variable every time I enable the strategy? I know that I can create a new Workspace, but is that really necessary?

                      Comment


                        #26
                        Hello jean9114,

                        You can reset a variable when the strategy is enabled by setting the variable in the Initialize() area of your script.

                        For example:
                        #region Variables
                        private int myVariable = 0;
                        #endregion

                        protected override void Initialize()
                        {
                        private int myVariable = 1;
                        }

                        With this code, myVariable will always equal 1 when the script is started.

                        Please let me know if this does not resolve your inquiry.
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by sjsj2732, Yesterday, 04:31 AM
                        0 responses
                        32 views
                        0 likes
                        Last Post sjsj2732  
                        Started by NullPointStrategies, 03-13-2026, 05:17 AM
                        0 responses
                        286 views
                        0 likes
                        Last Post NullPointStrategies  
                        Started by argusthome, 03-08-2026, 10:06 AM
                        0 responses
                        283 views
                        0 likes
                        Last Post argusthome  
                        Started by NabilKhattabi, 03-06-2026, 11:18 AM
                        0 responses
                        133 views
                        1 like
                        Last Post NabilKhattabi  
                        Started by Deep42, 03-06-2026, 12:28 AM
                        0 responses
                        91 views
                        0 likes
                        Last Post Deep42
                        by Deep42
                         
                        Working...
                        X