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 can I Enterlong before time session close e.g 5 mins before?

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

    How can I Enterlong before time session close e.g 5 mins before?

    Hi,
    Do you know How can I EnterLong before time session close e.g. 5 mins before?

    Thanks.

    #2
    Hello heiheilau,

    Thank you for your reply.

    You can use a session iterator to find the end time of the session, and then check if the current bar time is 5 minutes less:

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

    I'm attaching a very simple example that will enter a trade 5 minutes before the end of a session and then will be closed out at the end of the session as long as Exit on Session Close is checked.

    Please let us know if we may be of further assistance to you.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi, I found if I add the multi series, the strategy cannot be run, would you please suggest?

      I want if ( 1 minute Closes before session close > Yesterday High) Then EnterLong()



      Thanks.
      Attached Files

      Comment


        #4
        Hello heiheilau,

        Thank you for your reply.

        Keep in mind that as you have it now, you would need to load at least 20 days of data for the chart as you're returning if BarsArray[1] has fewer than 20 bars.

        Adding prints to your strategy that will show in the NinjaScript Output window, with information on what the variables you're using for your conditions are on a particular bar, can be helpful. I would suggest adding prints to see what may not be getting set as you'd expect within your code.

        This forum post goes into great detail on how to use prints to help figure out where issues may stem from — this should get you going in the correct direction. You can even add these using the Strategy Builder.

        https://ninjatrader.com/support/foru...ns-not-working

        If you run into issues like you're seeing here, the above information will allow you to print out all values used in the condition in question that may be evaluating differently than you expect. With the printout information you can assess what is different between the two. This should tell you exactly where the error is occurring.

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5

          Hello Kate,

          "Keep in mind that as you have it now, you would need to load at least 20 days of data for the chart as you're returning if BarsArray[1] has fewer than 20 bars."

          Thanks for reply. How I load at least 20 days of data. I have set the time frame of strategy analyzer from 2021/6/1 to 2021/9/15, However, I still get the error. I am not sure what is the error exact meaning and what's wrong with my code.
          Thanks.
          Error Code on Ninjascript Output:
          "Strategy 'Enter5MinBeforeSessionCloseExampleMultiTime': Error on calling 'OnBarUpdate' method on bar 8189: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."






          Attached Files

          Comment


            #6
            Hello heiheilau2000,

            Thank you for your reply.

            That time frame should be fine for the amount of data. Have you added prints to your strategy to determine where the error is occurring within your code? I will often add a print between each section of code in OnBarUpdate to narrow down where the code stops processsing, then once i've determined approximately where the prints stop, add further code to print the variables being used in that code section to see exactly which variable is causing the code to cease processing.

            The prints you add will be shown in the NinjaScript Output window (New > NinjaScript Output).

            Basically the error is saying you're trying to access a variable or series that nothing has been assigned to at the time you're trying to access it.

            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by stafe, Today, 12:34 PM
            2 responses
            16 views
            0 likes
            Last Post stafe
            by stafe
             
            Started by asmmbillah, Today, 11:18 AM
            1 response
            17 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Started by nickse2003, Today, 09:56 AM
            1 response
            26 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Started by ATMtrader0001, Today, 10:08 AM
            5 responses
            37 views
            0 likes
            Last Post ATMtrader0001  
            Started by WHICKED, Today, 09:47 AM
            1 response
            25 views
            0 likes
            Last Post NinjaTrader_Spencer  
            Working...
            X