Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problems with CalculateOnBarClose

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

    Problems with CalculateOnBarClose

    I'm trying to use CalculateOnBarClose (COBC) = false and FirstTickOfBar in an Indicator.

    I have CalculateOnBarClose = false in the Initialize() method AND I have Data:Calculate on bar close = False on the chart. It's not clear to me why 2 COBC's are required. Can you explain this?

    Here's the issue: If I have Data:Calculate on bar close = True on the chart then the Indicator works as expected but it's not a real-time update, it's "on bar".

    But, if I set Data:Calculate on bar close = False on the chart the indicator fails to update regardless of whether I set Historical = True or False.

    One final twist is that if I set Data:Calculate on bar close = False AND Historical = False AND constantly reload the Indicator on the chart (using F5) THEN the Indicator calculates the correct values in "real-time". Why would this be the case? How can I get the Indicator to update in real-time without constantly reloading the code?
    Last edited by bluelou; 10-24-2013, 07:12 PM.

    #2
    bluelou, there would not really be 2 COBC required - one would just set it from your code's Initialize() and the other from the UI. The UI setting would always override anything the code prepopulates for this property so to speak.

    If you have FirstTickOfBar combined with COBC = false this would act basically like a COBC true indicator as you only calculate on the open tick of the new bar - which is the tick that triggered the closing bar OnBarUpdate() call, so COBC true behavior.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand,
      Maybe you can guide me on how to do this? Here's what I need to do:

      1) I need a real-time (tick-by-tick) magnitude calculation:
      mag = Close[0] / Close[x] - 1, where Close[0] is the most recent tick but Close[x] is the close of a historical bar, also x is not constant

      So, I need Close[0] to be the most recent tick but I need Close[x] to be a historical bar. Does that mean I need to combine a COBC = false real-time numerator with a COBC = false AND FirstTickofBar denominator?

      In this case would Close[0] be a real-time price but Close[1] would be my first true bar Close price?

      2) For COBC do I set either COBC = false in the UI OR COBC = false in the Initialize() method? If I set BOTH COBC's = false then the indicator fails to update.


      Originally posted by NinjaTrader_Bertrand View Post
      bluelou, there would not really be 2 COBC required - one would just set it from your code's Initialize() and the other from the UI. The UI setting would always override anything the code prepopulates for this property so to speak.

      If you have FirstTickOfBar combined with COBC = false this would act basically like a COBC true indicator as you only calculate on the open tick of the new bar - which is the tick that triggered the closing bar OnBarUpdate() call, so COBC true behavior.
      Last edited by bluelou; 10-25-2013, 07:07 AM.

      Comment


        #4
        bluelou, there is only one COBC setting. There's just two ways to set it :

        a) from your script in Initialize()
        b) from the UI > which would override the script setting if you have it in.

        The COBC setting will only impact the behavior of the Close[0] bar in realtime or replay. With it being 'false' this gives you the last tick that updated the bar, on 'true' you get the last completed bar close - this historical one. That in turn would equal Close[1] if you worked on COBC false.

        So I don't see where the FirstTickOfBar would need to be used, as you can access historical bars on COBC false as well (just index one bar more back to makeup calling on the building bar [0]) and you also want to update the study intrabar.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Bertrand,
          This hasn't been my experience. I'm pretty sure I need FirstTickofBar for the denominator part of the calculation. I'm using a List to store historical bar data to evaluate what the denominator will be. If I set COBC = False AND don't use FirstTickofBar then the List appears to be populated with tick data and not bar data as required.

          Looking at the sample code NT has provided titled SampleEnterOnceExit Every Tick.cs it looks like in order to calculate a magnitude I need COBC = false data for my tick-by-tick numerator and FirstTickofBar for my historical bar based List that is used to calculate the denominator.

          Do you agree that I would need FirstTickofBar in this case or am I thinking incorrectly?


          Originally posted by NinjaTrader_Bertrand View Post
          bluelou, there is only one COBC setting. There's just two ways to set it :

          a) from your script in Initialize()
          b) from the UI > which would override the script setting if you have it in.

          The COBC setting will only impact the behavior of the Close[0] bar in realtime or replay. With it being 'false' this gives you the last tick that updated the bar, on 'true' you get the last completed bar close - this historical one. That in turn would equal Close[1] if you worked on COBC false.

          So I don't see where the FirstTickOfBar would need to be used, as you can access historical bars on COBC false as well (just index one bar more back to makeup calling on the building bar [0]) and you also want to update the study intrabar.

          Comment


            #6
            Hi bluelou,

            Yes, I would agree with you - FirstTickOfBar would allow you to calculate as soon as we get that first tick, but also allow you to run on CalculateOnBarClose to get the most recent close value.
            MatthewNinjaTrader Product Management

            Comment


              #7
              For anyone else looking to mix real-time tick data with bar data here's a simple Indicator example that works. The numerator is the most recent tick and the denominator is the most recent bar close.

              //The following code will print to Tools -> Output Window when running a real-time data feed.

              double denom = 0;
              double mag = 0;

              protected override void Initialize()
              {
              Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
              Overlay = false;
              CalculateOnBarClose = false;

              }

              protected override void OnBarUpdate()
              {
              Plot0.Set(Close[0]);

              if (CurrentBar < 1)
              return;

              if (FirstTickOfBar)
              {
              denom = Close[1];
              }

              mag = (Close[0] / denom) -1;

              Print(Time[1] + " - " + Close[1] + " -- " + Time[0] + " - " + Close[0] + " -- " + mag.ToString("0.000000"));
              }
              Last edited by bluelou; 10-27-2013, 01:16 PM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by cmtjoancolmenero, 04-25-2024, 03:58 PM
              19 responses
              106 views
              0 likes
              Last Post cmtjoancolmenero  
              Started by nleitman, Yesterday, 11:46 AM
              10 responses
              28 views
              0 likes
              Last Post nleitman  
              Started by ccbiasi, 11-23-2017, 06:06 AM
              6 responses
              2,216 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by Pattontje, Yesterday, 11:54 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by Pattontje, Today, 12:10 AM
              1 response
              4 views
              0 likes
              Last Post NinjaTrader_Erick  
              Working...
              X