Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

actualtradingdayendl doc example not working

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

    actualtradingdayendl doc example not working

    Good afternoon,
    I am trying to get the session's end-time information that should be provided by the function above. However, NT8 is giving errors when trying to compile the example from the documentation:

    https://ninjatrader.com/support/helpguides/nt8/NT%20HelpGuide%20English.html?actualtradingdayendl ocal.htm

    I get these errors:

    Click image for larger version

Name:	Screenshot 2025-01-28 131650.png
Views:	90
Size:	97.3 KB
ID:	1332676




    Please advise.

    Thank you! image widget
    Last edited by Lele2k24; 01-28-2025, 12:19 PM.

    #2
    Originally posted by Lele2k24 View Post
    Good afternoon,
    I am trying to get the session's end-time information that should be provided by the function above. However, NT8 is giving errors when trying to compile the example from the documents:

    https://ninjatrader.com/support/help...tradingdayendlocal.htm

    I get these errors:



    Please advise.

    Thank you! image widget
    It looks like you were trying to post a file showing the errors, but they didn't come through. You'll need to copy and paste the error text.

    Comment


      #3
      Thank you.. here is a pdf of the errors
      Attached Files

      Comment


        #4
        Here it is as txt only:

        NinjaScript File Error Code Line Column MyCustomIndicator.cs A namespace cannot directly contain members such as fields methods or statements CS0116 3 25
        MyCustomIndicator.cs A namespace cannot directly contain members such as fields methods or statements CS0116 11 25
        MyCustomIndicator.cs '<invalid-global-code>.OnStateChange()': no suitable method found to override CS0115 3 25
        MyCustomIndicator.cs '<invalid-global-code>.OnBarUpdate()': no suitable method found to override CS0115 11 25
        MyCustomIndicator.cs Program using top-level statements must be an executable. CS8805 1 1
        MyCustomIndicator.cs The type or namespace name 'SessionIterator' could not be found (are you missing a using directive or an assembly reference?) CS0246 1 1
        MyCustomIndicator.cs The name 'State' does not exist in the current context CS0103 5 7
        MyCustomIndicator.cs The name 'State' does not exist in the current context CS0103 5 16
        MyCustomIndicator.cs Cannot use local variable or local function 'sessionIterator' declared in a top-level statement in this context. CS8801 7 5
        MyCustomIndicator.cs The type or namespace name 'SessionIterator' could not be found (are you missing a using directive or an assembly reference?) CS0246 7 27
        MyCustomIndicator.cs The name 'Bars' does not exist in the current context CS0103 7 43
        MyCustomIndicator.cs The name 'Bars' does not exist in the current context CS0103 14 7
        MyCustomIndicator.cs Cannot use local variable or local function 'sessionIterator' declared in a top-level statement in this context. CS8801 17 5
        MyCustomIndicator.cs The name 'Time' does not exist in the current context CS0103 17 36
        MyCustomIndicator.cs The name 'Print' does not exist in the current context CS0103 19 5
        MyCustomIndicator.cs Cannot use local variable or local function 'sessionIterator' declared in a top-level statement in this context. CS8801 19 50

        Comment


          #5
          Hello Lele2k24,

          May I confirm you created a new script using the NinjaScript Editor?

          You have not modified the default namespace path or class name or inheritance from Indicator?

          May I also confirm you have not removed or modified any of the default using statements at the top of the script?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            That is correct.. I used the editor.. hit new indicator or strategy and then cut and pasted right from the website's example.

            I see the same errors on both indicators and strategy..

            I did not modify spaces or any text.. just copied it from the example on the site.

            Comment


              #7
              Hello Lele2k24,

              May I confirm you did not remove any of the structure code that was already there in the newly generated script?

              I want to confirm you didn't delete or paste over the existing code in the script.

              I was not able to confirm from post # 5:
              "You have not modified the default namespace path or class name or inheritance from Indicator?"

              The using statements, namespace, classname are all required.

              I suspect you either removed or pasted over the existing structure code and you have not pasted the declarations and logic code from the other script into the proper scope.

              Your screen shot in post # 1 is not showing the necessary using statements, namespace, or class and is not a complete script.

              I recommend you create a new script. And do not remove the default structure code.

              Copy logic into the proper scope of the class and override methods.

              If you are not familiar scope, see the section on scope in the support article linked below.


              Also, below is a link to a support article with helpful resources on getting started with C# and NinjaScript.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thank you. I didn't know that the example code was incomplete.

                Here what i am getting now when i try to enable the strategy:

                Strategy 'MyCustomStrategy3': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object.


                Code:
                #region Using declarations
                using System;
                using System.Collections.Generic;
                using System.ComponentModel;
                using System.ComponentModel.DataAnnotations;
                using System.Linq;
                using System.Text;
                using System.Threading.Tasks;
                using System.Windows;
                using System.Windows.Input;
                using System.Windows.Media;
                using System.Xml.Serialization;
                using NinjaTrader.Cbi;
                using NinjaTrader.Gui;
                using NinjaTrader.Gui.Chart;
                using NinjaTrader.Gui.SuperDom;
                using NinjaTrader.Gui.Tools;
                using NinjaTrader.Data;
                using NinjaTrader.NinjaScript;
                using NinjaTrader.Core.FloatingPoint;
                using NinjaTrader.NinjaScript.Indicators;
                using NinjaTrader.NinjaScript.DrawingTools;
                #endregion
                
                
                
                
                //This namespace holds Strategies in this folder and is required. Do not change it.
                namespace NinjaTrader.NinjaScript.Strategies
                {
                public class MyCustomStrategy3 : Strategy
                {
                
                SessionIterator sessionIterator;
                
                protected override void OnStateChange()
                {
                if (State == State.SetDefaults)
                {
                Description = @"Enter the description for your new custom Strategy here.";
                Name = "MyCustomStrategy3";
                Calculate = Calculate.OnBarClose;
                EntriesPerDirection = 1;
                EntryHandling = EntryHandling.AllEntries;
                IsExitOnSessionCloseStrategy = true;
                ExitOnSessionCloseSeconds = 30;
                IsFillLimitOnTouch = false;
                MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                OrderFillResolution = OrderFillResolution.Standard;
                Slippage = 0;
                StartBehavior = StartBehavior.WaitUntilFlat;
                TimeInForce = TimeInForce.Gtc;
                TraceOrders = false;
                RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                StopTargetHandling = StopTargetHandling.PerEntryExecution;
                BarsRequiredToTrade = 20;
                // Disable this property for performance gains in Strategy Analyzer optimizations
                // See the Help Guide for additional information
                IsInstantiatedOnEachOptimizationIteration = true;
                
                
                 if (State == State.Historical)
                 {
                   sessionIterator = new SessionIterator(Bars);
                 }
                
                }
                else if (State == State.Configure)
                {
                }
                }
                
                
                protected override void OnBarUpdate()
                {
                 // on new bars session, find the next trading session
                 if (Bars.IsFirstBarOfSession)
                 {
                   // use the current bar time to calculate the next session
                   sessionIterator.GetNextSession(Time[0], true);
                
                   Print("The current session end of day is " + sessionIterator.ActualTradingDayEndLocal);
                 }
                }
                }
                }
                ​
                Please advise.

                This isn't my first time working with Ninjascript.. and most examples that I find in the docs run fine with just coping and pasting into my code.

                Thanks again.

                Comment


                  #9
                  Hello Lele2k24,

                  You have nested 'if (State == State.Historical)' within the scope of 'if (State == State.SetDefaults)'. The State property cannot be both State.SetDefaults and State.Historical at the same time.
                  These should not be nested.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    I got the example code to work... had to change that's if statement above and add it to state.dataLoaded

                    Thank you!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    58 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    133 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    73 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    45 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    50 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X