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

Enter5MinBeforeSessionCloseExampleMultiTime

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

    Enter5MinBeforeSessionCloseExampleMultiTime

    HI,

    I want to add the multi timeframe entry condition, however, somehow it is not work after added if (Closes[0][0]>Highs[1][1]) // 1 minute Closes before session close > Yesterday High. No trade is executed.

    Would you please suggest?
    Attached Files

    #2
    Hello heiheilau2000,

    For this type of question you would need to add a Print so you can see if the condition you made is becoming true. A simple way to do that would be to output the variables you used in your condition and the bar time so you can compare the value for each bar.


    Code:
    Print(Time[0] + " " + Closes[0][0] + " > " + Highs[1][1]); 
    if(Time[0] == endTime.AddMinutes(-5))
    {
        if (Closes[0][0]>Highs[1][1]) // 1 minute Closes before session close > Yesterday High
       {
          // Print(Time[0]);
          EnterLong();
       }
    }
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse
      I tested with AAPL 1 min bar (primary) and generate this error.
      Here is the output message. Can you help to suggest and how to modify the code?

      Calculating trading day for 16/8/2023 9:31:00 pm
      Strategy 'Enter5MinBeforeSessionCloseExampleMultiTime/-1': An order placed at '08/16/2023 21:31:00' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met.
      Strategy 'Enter5MinBeforeSessionCloseExampleMultiTime': Error on calling 'OnBarUpdate' method on bar 0: 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.

      Comment


        #4
        Hello heiheilau2000,

        It looks like that sample has its bar check commented out, the following code needs to be uncommented to avoid both of those messages.


        // if (CurrentBars[0] < BarsRequiredToTrade || CurrentBars[1] < BarsRequiredToTrade)
        // return;

        This makes sure that the CurrentBar is at least equal to the ​BarsRequiredToTrade before executing the code below it.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Enter5MinBeforeSessionCloseExampleMultiTime.cs Thanks Jesse.

          The code were uncommented. However, I still have another error. Would you please suggest?


          15/2/2024 5:00:00 am 184.02 > 186.21
          Strategy 'Enter5MinBeforeSessionCloseExampleMultiTime': Error on calling 'OnBarUpdate' method on bar 8579: 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.​

          Comment


            #6
            Hello heiheilau2000,

            That means an invalid index is being used which is likely a BarsAgo. The script is using a daily series, did you make sure to use a far enough lookback in the chart? You will need at least 2 daily bars loaded, if you are using a small primary like a 1 minute series you would need to load at least a few trading days on the chart to accommodate the trading session for the instrument.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thanks Jesse.

              How can I know I have at least daily bars loaded. I think I have enough daily bars that at least 2 years. Would you help to suggest? Thanks for your patience and guidence.


              did you make sure to use a far enough lookback in the chart? You will need at least 2 daily bars loaded, if you are using a small primary like a 1 minute series you would need to load at least a few trading days on the chart to accommodate the trading session for the instrument.
              Attached Files

              Comment


                #8
                Hello heiheilau2000,

                That would be the purpose of the CurrentBar check, the code I mentioned was commented out in the sample you attached.

                Regarding the image I am not sure I follow what you are trying to do, the sample is adding a daily series so the sample is intended to be used on a less granular series like 1 minute as an example. If you are going to use a daily series bar type as the primary then you don't need to add 1 day data in the code.

                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by xfactscout, 07-22-2024, 09:01 PM
                1 response
                23 views
                0 likes
                Last Post xfactscout  
                Started by Chrisnasdaq, 08-26-2023, 08:37 PM
                4 responses
                1,401 views
                0 likes
                Last Post pierodicarlo  
                Started by GillRymhes, 06-23-2022, 09:16 AM
                13 responses
                743 views
                5 likes
                Last Post pierodicarlo  
                Started by aligator, 06-22-2022, 01:10 PM
                13 responses
                1,821 views
                0 likes
                Last Post pierodicarlo  
                Started by sumobull, Today, 06:48 PM
                0 responses
                10 views
                0 likes
                Last Post sumobull  
                Working...
                X