Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

(FirstTickOfBar) issue

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

    (FirstTickOfBar) issue

    I'm confused, what am I doing wrong? I'm trying to capture the opening price of the ES at 9:30am EST. When I print the results to the output window I'm getting 3 different prices. Does (FirstTickOfBar) not work in this application? What would be a more accurate way? This is for a strategy running on a 150 tick chart.

    Output Window
    10/17/2012 9:30:00 AM - ===== OpenPrice = 1450.5 =====
    10/17/2012 9:30:00 AM - ===== OpenPrice = 1450.75 =====
    10/17/2012 9:30:00 AM - ===== OpenPrice = 1450.75 =====
    10/17/2012 9:30:00 AM - ===== OpenPrice = 1450.75 =====
    10/17/2012 9:30:00 AM - ===== OpenPrice = 1450.75 =====
    10/17/2012 9:30:00 AM - ===== OpenPrice = 1451 =====
    10/17/2012 9:30:00 AM - ===== OpenPrice = 1451 =====
    10/17/2012 9:30:00 AM - ===== OpenPrice = 1451 =====
    10/17/2012 9:30:00 AM - ===== OpenPrice = 1451 =====

    Code:
    #region Variables
    private int openTime =  930;
    private int _OpenBar = 0;
    private double _OpenPrice = 0; 
    #endregion
    protected override void OnBarUpdate(){  
    if (ToTime(Time[0]) == OpenTime*100){
     if (FirstTickOfBar){
     _OpenPrice = Open[0];
     _OpenBar = CurrentBar;
     Print(Time[0]+" - ===== OpenPrice = "+_OpenPrice+" =====");
    } }
    }

    #2
    Hello kenb2004,
    To assist you further may I know is this a multi-series NinjaScript code?

    I look forward to assisting you further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      No multiseries. Tick data only

      Comment


        #4
        If you're running this script on a tick chart, you may get multiple bars that have the same time stamp. In your example, when I run this on market replay, we have 3 150 tick bars each with a time stamp of 9:30:00AM. This results in the following output:

        Code:
        10/17/2012 9:30:00 AM - ===== OpenPrice = 1450.75 =====
        10/17/2012 9:30:00 AM - ===== OpenPrice = 1451 =====
        10/17/2012 9:30:00 AM - ===== OpenPrice = 1451 =====
        If you only want the first bar, I'd suggest using a session template that starts at the market open and use Bars.FirstBarOfSession:

        MatthewNinjaTrader Product Management

        Comment


          #5
          Got it, Thanks

          Comment


            #6
            Without using a session template, how could I count the 930 bars and only use the first one?
            Thanks

            Comment


              #7
              Ken,

              You would need to loop through your bars and only count the first bar that is at 930

              Please see our Reference Sample on looping to the correct bar:

              MatthewNinjaTrader Product Management

              Comment


                #8
                Thanks Mathew, I'll check it out.

                Comment


                  #9
                  Originally posted by kenb2004 View Post
                  Without using a session template, how could I count the 930 bars and only use the first one?
                  Thanks
                  Try it the other way around, using FirstTickOfBar as the initial filter. If that does not work, then you are going to have to custom code it, resetting the value of interest at the start of the day to some specified value (best would be zero), then recording its value, the first time it changes.

                  Code:
                  if (FirstTickOfBar && ToTime(Time[0]) == OpenTime*100){//yada, yada, yada}

                  Comment


                    #10
                    koganam

                    Why would the order matter if they both have to be true to continue?

                    thanks

                    Comment


                      #11
                      Originally posted by kenb2004 View Post
                      koganam

                      Why would the order matter if they both have to be true to continue?

                      thanks
                      I have not myself tested what I wrote, but the reason that I think it maybe/could/might make a difference, is because we do not know the internal implementation of FirstTickOfBar. It just seemed to me that if there is something wonky in there (this being event-driven), NT could be seeing every tick that meets the time critierion as a FTOB if COBC is false. (Depends on CPU pipeline depth, caching and other arcana of the modern CPU).

                      If I have some time, I might test it out for myself, but I just wanted to give you a quick suggestion to try, as I do not know when I will have the free cycles to run a test, seeing as how I am terribly occupied with getting my website online at this time.

                      Comment


                        #12
                        koganam

                        Thanks for input, I think....sheeww. Wouldn't it be nice if NinjaTrader gave us a Internal Logic user guide so we might/maybe know what was inside the black box?

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by WeyldFalcon, 12-10-2020, 06:48 PM
                        14 responses
                        1,426 views
                        0 likes
                        Last Post Handclap0241  
                        Started by Barry Milan, Today, 10:35 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post Barry Milan  
                        Started by DJ888, Yesterday, 06:09 PM
                        2 responses
                        9 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by jeronymite, 04-12-2024, 04:26 PM
                        3 responses
                        40 views
                        0 likes
                        Last Post jeronymite  
                        Started by bill2023, Today, 08:51 AM
                        2 responses
                        16 views
                        0 likes
                        Last Post bill2023  
                        Working...
                        X