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

Multi-TimeFrame in Ver 7

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

    Multi-TimeFrame in Ver 7

    Hi,

    I would just like to clarify some coding concerns.

    I have a strategy running on 1min data (primary series) which relies on Daily data for info such as previous Close and daily ATR.

    While running on intraday basis I want to know the previous days close
    double lastDailyClose = Closes[1][0];

    I also want to know the previous 50 days ATR
    double DailyATR = ATR(BarsArray[1],atrLookback)[1];

    It would be intuitive that the ATR is given using the same zero [0] index as per the Close but this gives me a zero value.
    I just want to verify that this is the correct way of getting the ATR.

    Thanks


    protected override void Initialize()
    {
    Add(PeriodType.Day, 1);

    CalculateOnBarClose = true;

    }

    protected override void OnBarUpdate()
    {
    // 50 Days lookback
    if (CurrentBar < 72000) //700
    return;

    if (BarsInProgress != 0)
    return;

    double DailyATR = ATR(BarsArray[1],atrLookback)[1];
    double lastDailyClose = Closes[1][0];


    }

    #2
    Hello abfc123,

    You should be able to use index [0] here as well. I set up the same snippet as yours only changed to index 0 and was able to view non-zero values here.

    I would add print statements that print the timestamp of the secondary series, so you can see what bar is used given the index.

    Print("0: " + Times[1][0]);
    Print(
    "1: " + Times[1][1]);


    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      I am running a 1min primary bar backtest.
      If I use the 0 index for the ATR, I get zero values for the current day.
      It appears that unlike the Close[0], the ATR[1] refers to the last complete Daily Bar.

      In the same strategy, I am trying to reset some variables at the start of a new daily sesssion(5.01pm).
      How do you recommend that i test if the last minute bar was the start of a new session.
      I tried testing for the close of the secondary Daily Bar series (if (BarsInProgress == 1)), but doesn't appear to work.

      Thanks.

      Comment


        #4
        We already talked about the reset in another thread - is the index of 1 giving your the correct ATR value? Do you have enought data loaded for the added series to calculate the ATR you need?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Hi,

          There are more than sufficient bars.
          It appears that the ATR value with an index of 0 is empty if called from within a partial daily bar, whereas with the Close BarArray it would be the last completed daily bar.

          This indicator index usage seems different to the BarsArray usage.


          protected override void Initialize()
          {
          Add(PeriodType.Day, 1);

          CalculateOnBarClose = true;

          }

          protected override void OnBarUpdate()
          {
          // 50 Days lookback
          if (CurrentBar < 72000) //700
          return;

          if (BarsInProgress != 0)
          return;

          atrLookback = 50;

          double DailyATR = ATR(BarsArray[1],atrLookback)[1];
          double lastDailyClose = Closes[1][0];

          string str = "Closes[1][0]("+Closes[1][0]+") at " + Times[1][0].ToString() + " ATR=" + DailyATR;
          Print(str);

          Thanks

          Comment


            #6
            I'm using the snippet below to compare:
            Code:
             
            double lastDailyClose = Closes[1][0];
            double myBarsArray = SMA(BarsArray[1], 1)[0];
            
            Print("ldc: " + lastDailyClose);
            Print("mba: " + myBarsArray);
            The values match up, and I'm not seeing the issue with empty or zero returned. Can you let us know exactly how to setup a test to see what you're seeing.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Secondary Bar index

              Hi Ryan,

              Here is a strategy with output snippet:-
              lastDailyClose(80.72) at 10/11/2010 5:00:00 PM MinuteBarTime=10/12/2010 1:54:00 PM DailyATR_n0=0 DailyATR_n1=1.34248242936283 myBarsArray=0
              lastDailyClose(80.72) at 10/11/2010 5:00:00 PM MinuteBarTime=10/12/2010 1:55:00 PM DailyATR_n0=0 DailyATR_n1=1.34248242936283 myBarsArray=0
              lastDailyClose(80.72) at 10/11/2010 5:00:00 PM MinuteBarTime=10/12/2010 1:56:00 PM DailyATR_n0=0 DailyATR_n1=1.34248242936283 myBarsArray=0
              lastDailyClose(80.72) at 10/11/2010 5:00:00 PM MinuteBarTime=10/12/2010 1:57:00 PM DailyATR_n0=0 DailyATR_n1=1.34248242936283 myBarsArray=0
              lastDailyClose(80.72) at 10/11/2010 5:00:00 PM MinuteBarTime=10/12/2010 1:58:00 PM DailyATR_n0=0 DailyATR_n1=1.34248242936283 myBarsArray=0
              lastDailyClose(80.72) at 10/11/2010 5:00:00 PM MinuteBarTime=10/12/2010 1:59:00 PM DailyATR_n0=0 DailyATR_n1=1.34248242936283 myBarsArray=0

              Thanks
              Attached Files

              Comment


                #8
                I should also have added that it is run against AUDJPY 1 minute Primary Bar data with 'Forex' session Template set to Session start/end at 5pm EST

                Comment


                  #9
                  One thing to understand is this will work differently in real time versus historical.

                  10/11/2010 5:00:00 PM MinuteBarTime=10/12/2010 1:54:00

                  The time stamp for the minute bar is earlier than the time stamp of the 10/12 daily bar (5:00 PM).

                  You can access the in-process daily bar in real-time, but you must store your chart data as historical. Check this option under tools > options > Data > Save chart data as historical.

                  Check this setting, disconnect, and reconnect, and then run this strategy.
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi,

                    I think you misunderstood the question and the attached .cs file.

                    To clarify/simplify:-

                    I am running a backtest on historical data, not realtime trading.

                    I am running a 1 minute primary bar series.
                    I am adding a daily bar series : - Add(PeriodType.Day, 1);
                    I have set CalculateOnBarClose = true;

                    During intraday analysis([email protected]) I want to know the previous Days closing price:- Closes[1][0];
                    I also want to know the 50 period Daily ATR

                    Do I use:-
                    ATR(BarsArray[1],50)[0];
                    or
                    ATR(BarsArray[1],50)[1];

                    Thanks

                    Comment


                      #11
                      abfc123, you want to reference a bar further back here, otherwise you would see 0 for the not yet closed daily bar returned (CalculateOnBarClose == true).
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Hi Bertrand,
                        This is what I observed.
                        I had just presumed however that the index denoting lookback for the Close of an barArray would be the same for an indicator using the same barArray. It appears this is not the case.

                        What I am attempting to do is run a 1minute strategy that tests on tick-by-tick basis(onBarClose=false) for a break above the previous Dailyclose+the daily ATR.
                        I wanted to calculate the Close and ATR at the completion of the last Daily bar
                        if (BarsInProgress == 1 && FirstTickOfBar){
                        DailyATR = ATR(BarsArray[1],atrLookback)[1];
                        lastDailyClose = Closes[1][0];
                        }

                        then I want to test on a tick-by-tick basis if the primary 1minute bar high H[0] exceeds the level

                        Is this going in the right direction?

                        Thanks and regards

                        Comment


                          #13
                          abfc123,

                          I would simplify this further so you can verify everything works the way you expect. In all my tests there has not been a different referencing model for BarsArray[1] compared to Closes[1].

                          The time stamps of the different series is critical to know which daily bar you're referencing.

                          I would use this statement on your 1 minute series:
                          DailyATR = ATR(BarsArray[1], 1)[0];

                          Compare this to the standard ATR(1) applied to a daily chart. It works differently historical / real time and with COBC true / false - try these combinations.

                          Once this lines up with your expectations, then you can move on to the more complicated items, like combining COBC true / false logic, taking 50 day averages, etc.
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi Ryan,

                            Think I'm going in circles here.
                            Please see previous message with output and .cs attached.
                            Closes[1][0]; gives the previous completed Daily bars close
                            ATR(BarsArray[1], 1)[0]; gives zero
                            ATR(BarsArray[1], 1)[1]; gives the last ATR value

                            This is with onBarClose=true so both values are dependent on bar being completed.

                            I am trying to verify whether the index subscript for an Indicator is different to BarArray

                            Thanks

                            Comment


                              #15
                              Sorry for your frustrations here.

                              ATR(BarsArray[1], 1)[0]; gives zero
                              We have to identify why you are getting these results as this has not been the case in any of my tests. Can you try with the attached file? Apply to 1 minute chart. It should plot ATR from the daily series, and uses index [0] to do this.
                              Attached Files
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by alifarahani, Today, 09:40 AM
                              6 responses
                              31 views
                              0 likes
                              Last Post alifarahani  
                              Started by Waxavi, Today, 02:10 AM
                              1 response
                              17 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by Kaledus, Today, 01:29 PM
                              5 responses
                              13 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by Waxavi, Today, 02:00 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by gentlebenthebear, Today, 01:30 AM
                              3 responses
                              17 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X