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

First bar of session

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

    First bar of session

    hello,

    Newbie here. I am trying to build my first strategy and I need to set it up such a way that some action is happening based on the opening price of the session. I am using "First bar of session" but it doesn't work. When I set a comparison action vs. for example the Ask Price I get an error (in Strategy Builder). Anyone can help? Probably the "First Bar of Session" doesn't do what I think it should (get the opening price of the trading session).

    Thanks

    #2
    Hello space_trader,

    Thanks for your post and welcome to the NinjaTrader forums!

    What instrument, bar type, bar size are you using?

    What Trading hours are you using/expecting? (Look in the Data series window for "trading hours")

    Are you intending to trade on the first bar of the session or do you want to save the Open price of the session into a variable to be used later?

    What is the "Calculate" setting of the strategy?

    Do you have any added data series?

    In case you have not accessed the reference materials, here is a link to each. (This will not solve the questions, just wanted to make sure you know or had these for reference)
    Free live webinar every other Thursday at 4:00 PM EST, through this link to all webinars: https://ninjatrader.com/PlatformTraining
    Previous recording of the Strategy Builder 301 webinar: https://youtu.be/HCyt90GAs9k?list=PL...auWXkWe0Nf&t=2
    Help guide for the strategy builder: https://ninjatrader.com/support/help...gy_builder.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      hello Paul,

      To answer your questions:

      ES S&P 500 mini futures, currently 1 min candlestick bar
      Full daily session
      Both (place a trade based on the first bar of the session and also save this for later)
      That depends (still optimizing). Mostly will be a comparison of the opening bar to some other bar later in the session
      No added data series

      I have gone through some of the videos and tutorials. I understand the set up of the Strategy Builder. It seems that I misinterpreter some of the meanings of the many options.

      thanks!

      Comment


        #4
        Hello space_trader,

        Thanks for your reply.

        I assume the full daily session means the ETH hours of the session "CME US index futures ETH". The start of the session would then be the late afternoon of the day before which starts at 5:00 PM CST.

        If you are using Calculate.OnBarClose, you can save the open price of the session by checking if the First Bar Of The Session is true and then saving the Open[0] price of the bar into your double type variable and place an order if you wish.


        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Ok, great. I will try this.

          Comment


            #6
            Hello Paul,

            Just a question regarding the Strategy Analyzer. I 've managed to make it work but when I try to run it in Strategy Analyzer with a Bar size less than 1 Minute (ex. 30 sec) doesn't work. I use Interactive Brokers. Do you think this is due to IB data limitation?

            Regards

            Comment


              #7
              Hello space_trader,

              This is Jim, responding on behalf of Paul who is out of the office at this time.

              Interactive Brokers only offers historical minute and daily data to NinjaTrader. Second bars are tick based bars which we cannot get historical data though IB.

              Data By Provider - https://ninjatrader.com/support/help...y_provider.htm

              You could consider a data feed service like Kinetick to get historical tick data, though.

              Kinetick (publicly available link) - https://kinetick.com/

              We look forward to assisting.
              JimNinjaTrader Customer Service

              Comment


                #8
                Hello Jim,

                Thanks, that's clear. Another question I have is about looping. I 've noticed in the actual code all of the statements are IF statements, but how can I create a LOOP in Strategy Builder, like for example a FOR loop that check for an initial condition and then repeats the process. In my example it enters a LONG position if first bar of session is greater than something but when it closes this position (through a profit taker for example) it goes back to check the initial condition again etc.
                Last edited by space_trader; 11-08-2020, 02:07 AM.

                Comment


                  #9
                  Hello space_trader,

                  Thanks for your reply.

                  There is no means to create a for loop in the strategy builder.

                  In Post#4 I suggested saving the Open price of the session into a double type variable. You can check the current price to that variable and enter a new order, or not, as you wish. The variable would not change until the next first bar of session.

                  1) So on the first bar of the session, save the open price to a variable.

                  2) If the strategy is in a flat position and the current price crosses the saved session open price, place an order.

                  3) When the profit or loss is hit and the strategy becomes flat, repeat step 2

                  Not quite a for loop but basically an event loop. The event is a flat position and price crossing above the saved open price.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello,

                    I have another question. So, let's assume I save the first session bar price to a variable (as instructed above). I believe what I am going to save is up to me and all available options work with no issues (Open, Close, Medium etc.). What I would like to understand is how the Algo will work from there. What I want to do is compare this saved variable (let's assume in that case is the Close price) to the (for example) Close price of the Next Bar. Is this sequence right?

                    1. Check for First Bar of Session and if True assign a variable (ex. the Close price of the Bar)
                    2. Make a comparison of this saved variable to the the Close price of Next Bar

                    Is this going to compare the Close Price of the First Session Bar to the following Bar or, is it going to compare the Close Price of the same Bar? What I mean is, is this set going to move to the next Bar and get the next price to compare or will compare the Close Price of the same bar? Do I need to state a Bars Ago = -1 to check the following Bar or this is not required?

                    Thanks

                    Comment


                      #11
                      Hello space_trader,

                      Thanks for your reply.

                      What you would have is a set that has the condition to see if it is the first bar of the session, if true then the action of that set is to save the price (you can choose which price type) into a double type variable that you create.

                      In another set then you would check to see if the price of the current bar to the variable and perform whatever actions you wish.
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Ok, I see. But what is the Bar that this 2nd set will compare the variable against? Let's assume it is the first time it runs. First Bar is also the First Bar of Session and this sets the price value of the variable. The 2nd set compares this variable to the price (Open, Close etc.) of which Bar? I want the algo to compare the variable against the Price (Open, Close etc.) of the next bar, which in our case is the 2nd Bar of the session. Is it how it works? Do I need to add any additional code to make that happen?

                        I would like to avoid the first time the algo runs to set the variable and compare to itself. I am not sure I am clear.

                        Thanks

                        Comment


                          #13
                          Hello space_trader,

                          Thanks for your reply.

                          To avoid the condition in the 2nd set you would add the condition Misc>First bar of session , not equal, Misc>true or you can use: Misc> First bar of session, equals, Misc>False
                          Paul H.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by JonesJoker, 04-22-2024, 12:23 PM
                          8 responses
                          41 views
                          0 likes
                          Last Post JonesJoker  
                          Started by timko, Today, 06:45 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post timko
                          by timko
                           
                          Started by Waxavi, 04-19-2024, 02:10 AM
                          2 responses
                          38 views
                          0 likes
                          Last Post poeds
                          by poeds
                           
                          Started by chbruno, Yesterday, 04:10 PM
                          1 response
                          44 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Started by Max238, Today, 01:28 AM
                          1 response
                          25 views
                          0 likes
                          Last Post CactusMan  
                          Working...
                          X