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

Problems with FirstBarOfSession in FX sessions

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

    Problems with FirstBarOfSession in FX sessions

    First up my charts are plotting FX sessions *properly* - starting at 14:00PDT - so far so good. That said take this little test indicator:


    Code:
    protected override void Initialize() {
       Add("$EURUSD", PeriodType.Minute, 5);
    }
    protected override void OnBarUpdate() {
        if (Bars.FirstBarOfSession) { 
             Log(Time[0]+ " First BAR!", LogLevel.Warning);
        }
    }
    The chart running this indicator also has a 5 minute interval on the EURUSD. Now, the output I'm getting is this:

    3/21/2011 5:27:27 PM|2|4|3/15/2011 2:05:00 PM First BAR!
    3/21/2011 5:27:27 PM|2|4|3/15/2011 2:05:00 PM First BAR!
    3/21/2011 5:27:27 PM|2|4|3/15/2011 2:13:44 PM First BAR!
    3/21/2011 5:27:28 PM|2|4|3/16/2011 2:00:00 PM First BAR!
    3/21/2011 5:27:28 PM|2|4|3/16/2011 2:00:05 PM First BAR!
    3/21/2011 5:27:28 PM|2|4|3/16/2011 2:05:00 PM First BAR!
    3/21/2011 5:27:28 PM|2|4|3/16/2011 2:05:00 PM First BAR!
    3/21/2011 5:27:28 PM|2|4|3/17/2011 2:05:00 PM First BAR!
    3/21/2011 5:27:28 PM|2|4|3/17/2011 2:05:00 PM First BAR!
    3/21/2011 5:27:28 PM|2|4|3/17/2011 2:59:59 PM First BAR!
    3/21/2011 5:27:28 PM|2|4|3/20/2011 2:00:37 PM First BAR!
    3/21/2011 5:27:28 PM|2|4|3/20/2011 2:05:00 PM First BAR!
    3/21/2011 5:27:28 PM|2|4|3/20/2011 2:05:00 PM First BAR!
    3/21/2011 5:27:28 PM|2|4|3/21/2011 2:00:01 PM First BAR!
    3/21/2011 5:27:28 PM|2|4|3/21/2011 2:05:00 PM First BAR!
    3/21/2011 5:27:28 PM|2|4|3/21/2011 2:05:00 PM First BAR!

    Very confusing - why would I get such varying output? Shouldn't it always strike at 2:05:00PM?

    Can someone please explain this to me?

    #2
    My current work around

    I'm using this work around currently:

    Code:
    protected bool firstBarOfSession() {
        return (ToTime(Time[0]) >= ToTime(14, 00, 00)) && (ToTime(Time[0]) <= ToTime(14, 05, 00));
     }
    Now, this hack gets called properly but I usually prefer to use NT functionality instead of dirty code that has a tendency to blow up at a different chart interval or if I wind up moving to a different time zone.

    Any input on this would be appreciated.

    Comment


      #3
      Ahem...

      Anyone? Would appreciate some help here.

      Comment


        #4
        Hello,

        Whats more strange that seems to be where are issue may be.

        Is that you have 3 entries for some Bars.FirstBarOfSession.

        When I test on my side this does not occur. As far as the slightly delayed times I could foresee this if you where missing some data at the start of the bars since it would run on missing data if this is even an issue here.

        However more then likely not the above since we are getting this third call. Do you have any recall on where this third call could be coming from? Do you have another Add() series your not showing me or another indicator by any chance that would do this?

        Secondly, you are sending these to the log. You never want to send OnBarUpdate / debug information to the log. As if you where to run this on a large bars back chart you can end up with thousands of log entries. Which NinjaTrader has to concstantly keep loaded into Memory which will slow down NinjaTrader once you run out of ram.

        Its best to send these to the print window instead with Print();

        Finally, Can you please let me know what version of NinjaTrader you are using this is located in the Control Center under Help->About and is to the right of the NinjaTrader logo.


        My Output with your test code:

        3/14/2011 3:05:00 PM First BAR!
        3/14/2011 3:05:00 PM First BAR!
        3/15/2011 3:05:00 PM First BAR!
        3/15/2011 3:05:00 PM First BAR!
        3/16/2011 3:05:00 PM First BAR!
        3/16/2011 3:05:00 PM First BAR!
        3/17/2011 3:05:00 PM First BAR!
        3/17/2011 3:05:00 PM First BAR!
        3/20/2011 3:05:00 PM First BAR!
        3/20/2011 3:05:00 PM First BAR!
        3/21/2011 3:05:00 PM First BAR!
        3/21/2011 3:05:00 PM First BAR!

        Comment


          #5
          Yes, I am actually adding a lot more currency pairs - that could be the reason and it's something I suspected already. Will look into this in more detail.

          You are also correct about the log statements. Problem is that I don't know how to capture the Print() calls. I am starting NinjaTrader from the command line but am not seeing any output. What do I have to do to see those print statements?

          Comment


            #6
            Hello,

            No problem let me know what you find.

            What do you mean by capture? You wanting to export them or something to external app? All Print() calls get routed to the Control Center->Tools->Output window.

            Let me know if I can be of further assistance.

            Comment


              #7
              Oh - THAT window - sorry. I never used that before. Good one - that should speed things up in the future. Thanks!

              Comment


                #8
                Excellent!

                Let me know if I can be of further assistance.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by nandhumca, Today, 03:41 PM
                0 responses
                4 views
                0 likes
                Last Post nandhumca  
                Started by The_Sec, Today, 03:37 PM
                0 responses
                3 views
                0 likes
                Last Post The_Sec
                by The_Sec
                 
                Started by GwFutures1988, Today, 02:48 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by ScottWalsh, 04-16-2024, 04:29 PM
                6 responses
                33 views
                0 likes
                Last Post ScottWalsh  
                Started by frankthearm, Today, 09:08 AM
                10 responses
                36 views
                0 likes
                Last Post frankthearm  
                Working...
                X