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

(Ninja Script) How to get the day's opening bar

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

    (Ninja Script) How to get the day's opening bar

    Hey All,

    I have recently started working Strategies in Ninja Trader. I am trying to create a strategy that plays off the first bar of the day. Does anyone know how to do this?

    Would I have to check the time after each bar to see if it is the day's opening bar? Or does NT offer a built in variable that points directly to the day's opening bar?

    Thanks!

    #2
    Hello Force,

    Welcome to the NinjaTrader forums!

    You can use the built in property Bars.FirstBarOfSession to identify this.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks so much!

      Comment


        #4
        So my first script attempt was to change the day's opening bar to a different color. Below is the code that I created to do so. It failed and I believe I know why but I wanted to be sure. When applying historical data to a strategy the individual ticks \ updates are not applied are they? If not that would prevent the code below from ever being triggered. I tried placing this code in the CalculateOnBarClose as well and nothing changed. Any ideas?

        Code:
                protected override void OnBarUpdate()
                {
                    // Condition set 1
                    if (Bars.FirstBarOfSession = true)
                    {
                        BarColor = Color.Chocolate;
                    }
                                
                }

        Comment


          #5
          Yes, it's run against all historical data. When testing for equality, you need double == sign.

          if (Bars.FirstBarOfSession == true)

          Single = is for assignment.

          Since it's a bool expression, the only options are true/ false so you can also use the format below:

          if (Bars.FirstBarOfSession) //tests if true

          if (!Bars.FirstBarOfSession) //tests if false
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Thanks for getting back so quickly. I am converting from VB to C# so syntax is going to be the bane of me.

            Beyond that I also did not realize that Strategies have to be compiled before being applied (stupid mistake). However, when I try to compile it I receive the following errors
            CS1518 "Expected Class, delegate, enum, interface, or struc"
            CS1022 "Type or namespace definition, or end-of-file-expect"

            Just to be sure I did not screw something up I created a new strategy from scratch and without changing any code received the same errors.

            Appears one other person has had this issue before:


            Is this a known issue?

            Comment


              #7
              When you compile, it checks all files, not just the one you're working with.

              It should list the file name and error. Deleting this file should allow you then to compile a new code.

              You can delete a file in the Tools > Edit NinjaScript Strategy (or indicator) window.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Thanks Ryan, I was able to get the script to compile and function correctly.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by yertle, Yesterday, 08:38 AM
                7 responses
                28 views
                0 likes
                Last Post yertle
                by yertle
                 
                Started by bmartz, 03-12-2024, 06:12 AM
                2 responses
                21 views
                0 likes
                Last Post bmartz
                by bmartz
                 
                Started by funk10101, Today, 12:02 AM
                0 responses
                4 views
                0 likes
                Last Post funk10101  
                Started by gravdigaz6, Yesterday, 11:40 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by MarianApalaghiei, Yesterday, 10:49 PM
                3 responses
                10 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X