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

Session Template and ATR

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

    Session Template and ATR

    I have imported historical tick data and have checked "Generate minute bars" and Generate Day bars" when importing the historical data. I use this data for backtesting.

    I am using a session template Temp1 with trading hours between 9:00 and 17:30.

    My strategy calculates the ATR on the Daily bars and enters and manages the trade at M1.
    I had expected the High, Low and Close to be determined by the bars that fall within the trading range. However, I get the same results for ATR whether I use my Temp1 template or the <Use instrument settings> session template.

    How is ATR(14)[0] determined when using session template?
    How do I generate an ATR that only uses the candles within my session template and ignores candles outside the template?

    #2
    Hello PaulZ,

    Thank you for writing in.

    The information available to your strategy is based on the session template you are using.

    Can you please attach a screenshot of your session template so I may test on my end?

    To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

    Click here for instructions

    Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

    Click here for detailed instruction
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Hi ZacharyG,

      I have attached the Session Template I used.
      Attached Files

      Comment


        #4
        Hi ZacharyG,

        I add a Daily Bar to my chart with the command: Add(PeriodType.Day,1);
        I then later calculate my Risk, based on ATR on (ATRDays number of) Days:
        if (BarsInProgress == 1)
        {Rsk = PercATR*ATR(ATRDays)[0];}

        I did some further testing and it seems that NT7 takes the OHLC data from the Daily Bars that have been created when I imported my historical data and checked the "Generate day Bars" box.
        I tested this by creating a session with only few hours and then show chart with Daily Bars. The Close time in the Data Box is correctly refrecting end of session, but the OHLC reflect the data from the 24 hour session.
        Instead I want to create Daily Bar charts that are different when I change my session template as OHLC could/should then be different. How do I dynamically crate daily bars that are dependent on session template selected?

        Comment


          #5
          Hello PaulZ,

          Thank you for your response.

          Instead, use a 1440 minute bar with your Session Template applied. This would correct the data on the chart for the OHLC. Session Templates would not apply to Daily bars as they are treated as is from the provider or when imported.

          Comment


            #6
            Thanks. I have tried that and it works.
            My next challenge is that I want to launch a strategy on M1 timeframe that calculates the OHLC of the previous day (M1440 timeframe) right at the start.
            I have tested this on FDAX 06-16 with Session Templates with different start and end dates and thye following comand:

            PrintWithTimeStamp("D1[0] open: "+Opens[1][0]+" D1[0] close: "+Closes[1][0]);
            I then get the same Open and Close values printed for the different Session templates, whereas I would expect different Open and Close values.
            Also, I cannot relate the printed values on March 31: D1[0] open: 9909,5 and D1[0] close: 9881,5 to relevant historical bars.

            Comment


              #7
              Hello PaulZ,

              Thank you for your response.

              In a multiple series script the added series will use the same session template as the primary series.

              Comment


                #8
                Thanks.
                After some more testing I found that I need to set "Days to Load" = 1 when defining a New Strategy in the Control Center.
                If I leave this at the default setting of 5, the program will load 2 days (more is not available) and the program sees Opens[1][0] not as yesterday, but as the day before yesterday.
                Is that correct? (Seems like a flaw in the code)

                Comment


                  #9
                  Hello PaulZ,

                  Thank you for your response.

                  That should not be the case. However, you can verify the date by using Times[1][0].Date and compare that against Times[0][0].Date to ensure they are processing the same date.

                  Comment


                    #10
                    I compared Times[1][0].Date against Times[0][0].Date as you suggested.
                    This confirms my suspicion that Times[1][0].Date takes the date from the start of de Days Loaded and not from today.
                    If I load with Days to Load = 5 today (April 1), I get the date: 29/3 for Times[1][0]. (irrespective if I use D1 or M1440).
                    Looks like a bug in NT7 software.

                    Comment


                      #11
                      Hello PaulZ,

                      On historical data I suspect that, yes. Did the date increase? Are you printing the values? Can you attach the code you are running?

                      You can attach your indicator or strategy to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your Indicator or Strategy > select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.

                      Comment


                        #12
                        Hi PatrickH,

                        Yes, this is on historical data from IB connection when I launch the Strategy.
                        The date only increases for Times[0][0], not for Times[1][0] as you can see on the Output File.
                        I have uploaded the code of my test program as well as snippets of my Control Center, Test Session template, and Output File.
                        Attached Files

                        Comment


                          #13
                          Thank you for the additional details, PaulZ.

                          Daily bars or minute bars that are of 1440 minutes would need far more days to load. Please set the DaysToLoad to 30 and test again.

                          Comment


                            #14
                            Hi PatrickH,

                            Yes that makes a diffence and seems to resolve the issue I had been struggling with..
                            What is the logic why so many days to load are needed to get a correct value for Yesterday's Close?

                            Comment


                              #15
                              Hello PaulZ,

                              Thank you for your response.

                              The NinjaScript objects generally need 20 bars before they process. If you do not have enough DaysToLoad on the chart then there is no data to access. If you need yesterdy's close you may wish to set BarsRequired to 0: http://ninjatrader.com/support/helpG...rsrequired.htm
                              Then set the DaysToLoad in the Data Series menu to 2. If that does not work increase the days by 1.

                              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
                              11 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X