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

Odd behavior with FirstTickOfBar

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

    Odd behavior with FirstTickOfBar

    I am occasionally finding the FirstTickOfBar will not fire true after running for a while.

    Has anyone else experienced this? I am using multiple time frames for an indicator to track volume changes which is why I have noticed this since the volume counts are not reseting.

    #2
    Do you have a sample script you can post that repicates this error?

    Is CalculateOnBarClose set to false?

    Look forward to assisting you further.
    LanceNinjaTrader Customer Service

    Comment


      #3
      here is a stripped down version.



      /// <summary>
      /// This method is used to configure the indicator and is called once before any bar data is loaded.
      /// </summary>
      protected override void Initialize()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
      Overlay = false;
      Add(PeriodType.Minute, 2);
      Add(PeriodType.Minute, 3);

      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Use this method for calculating your indicator values. Assign a value to each
      // plot below by replacing 'Close[0]' with your own formula.
      Plot0.Set(Close[0]);

      if (CurrentBar==0) return;

      if (FirstTickOfBar) {
      Print(Label + "Time:" + Time[1] + ", Total Volume:" + Volume[1]);

      if (BarsInProgress == 0) {
      askVolume = 0;
      bidVolume = 0;
      }

      hasTime=false;
      } else {
      if (BarsInProgress == 0) {
      if (!hasTime) { Print(Label + "Time:" + Time[0]); hasTime=true; };
      Print(" Volume:" + (Volume[0] - lastVolume));
      }
      }
      if (BarsInProgress == 0) {
      lastVolume = Volume[0];
      }
      }

      Comment


        #4
        It may be IB - could their data cause it to act strange?
        Last edited by MarketAlly; 12-31-2013, 01:23 PM.

        Comment


          #5
          Thank you for this. One thing to be aware of is that FirstTickOfBar is only intended to be used when CalculateOnBarClose = false.

          Otherwise all calculations will be performed on the closing tick.


          Once you have this if the issue persists please let me know the output your getting that appears incorrect.

          Let me know how I can further assist.
          LanceNinjaTrader Customer Service

          Comment


            #6
            Originally posted by MarketAlly View Post
            here is a stripped down version.



            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
            Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
            Overlay = false;
            Add(PeriodType.Minute, 2);
            Add(PeriodType.Minute, 3);

            }

            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            Plot0.Set(Close[0]);

            if (CurrentBar==0) return;

            if (FirstTickOfBar) {
            Print(Label + "Time:" + Time[1] + ", Total Volume:" + Volume[1]);

            if (BarsInProgress == 0) {
            askVolume = 0;
            bidVolume = 0;
            }

            hasTime=false;
            } else {
            if (BarsInProgress == 0) {
            if (!hasTime) { Print(Label + "Time:" + Time[0]); hasTime=true; };
            Print(" Volume:" + (Volume[0] - lastVolume));
            }
            }
            if (BarsInProgress == 0) {
            lastVolume = Volume[0];
            }
            }
            Your script is using the default COBC = true. That means that there is only one tick per bar (that triggers OBU), so the first tick is also the only tick. What behavior are you expecting?

            Comment


              #7
              No - I left that out unless the indicator gets to choose when to obey the setting on the indicator properties window? It works for a while then stops triggering the FirstTickOfBar.

              Comment


                #8
                In that case please let me know the output your getting that appears incorrect and provide me with steps to reproduce so that I can further assist.
                LanceNinjaTrader Customer Service

                Comment


                  #9
                  The output is the following until the FirstTickOfBar stops being set:

                  1 min - Time:12/31/2013 11:41:00 AM, Total Volume:884
                  2 min - Time:12/31/2013 11:40:00 AM, Total Volume:2028
                  3 min - Time:12/31/2013 11:39:00 AM, Total Volume:1405
                  Time:12/31/2013 11:47:00 AM <-- at every tick
                  Volume:21 <-- at every tick

                  then it simply keeps printing:

                  Volume:# <-- at every tick

                  if the FirstTickOfBar stops being set to true - then it will continuously print

                  Volume:# <-- at every tick

                  otherwise every minute it should print:

                  1 min - Time:12/31/2013 11:47:00 AM, Total Volume:#

                  with a few more at the 2 and 3 minute mark.

                  Comment


                    #10
                    With the way your code is stuctured I would expect it to print every single tick update.

                    The reason for this is that you have print statements outside the conditional check.

                    Consider moving your if(FirstTickOfBar) braces to encompass your BarsInProgress logic too, if this is your goal.

                    Let me know if I can further assist.
                    LanceNinjaTrader Customer Service

                    Comment


                      #11
                      That is not my goal Lance... if you run the code, you will see how it will (hopefully) stop working. It worked for 90 minutes before stopping the first time and then after 40 minutes. I am unsure what would cause it to be intermittent.

                      I am not seeking assistance in what the output is - only why the FirstTickOfBar stopped being triggered.

                      Comment


                        #12
                        here is the missing Label variable.


                        string Label = "";

                        if (BarsInProgress == 0) {
                        Label = "1 min - ";
                        lastVolume = 0;
                        } else if (BarsInProgress == 1) {
                        Label = "2 min - ";
                        } else {
                        Label = "3 min - ";
                        }

                        Comment


                          #13
                          In this case could you please provide me with the following.

                          1. Please attach complete script source file located in (MY)Documents\NinjaTrader 7\bin\Custom\Indicator

                          2. Instrument to test on

                          3. any custom input settings

                          4. time of day (and timezone) when you saw the issue.

                          Look forward to assisting you further.
                          LanceNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Barry Milan, Yesterday, 10:35 PM
                          5 responses
                          16 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by DanielSanMartin, Yesterday, 02:37 PM
                          2 responses
                          13 views
                          0 likes
                          Last Post DanielSanMartin  
                          Started by DJ888, 04-16-2024, 06:09 PM
                          4 responses
                          13 views
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Started by terofs, Today, 04:18 PM
                          0 responses
                          12 views
                          0 likes
                          Last Post terofs
                          by terofs
                           
                          Started by nandhumca, Today, 03:41 PM
                          0 responses
                          8 views
                          0 likes
                          Last Post nandhumca  
                          Working...
                          X