Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to mix indicators requiring COBC = false in a strategy requiring bars

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

    How to mix indicators requiring COBC = false in a strategy requiring bars

    I'm trying to combine an indicator which uses both ticks and bars (COBC = false and FirstTickOfBar) with a strategy that has multiple BarsInProgress.

    My question is the following:
    If I set the strategy with COBC = false but have specified the BarsInProgress then won't that mean that my indicator will run properly since it now has tick data given that COBC = false but my strategy will still run on bars since I've specified the BarsInProgress.

    Are my assumptions correct? Or, is there a better way to do this?

    #2
    Hi Bluelou,

    Thank you for your post.

    There are two ways to do this.

    The first is the method is to use a intrabar granularity which you will then use BarsInProgress to separate out the logic of which bar event is calling the OnBarUpate() method.

    If however, you do not need to separate that kind of logic out then you can just use the FirstTickOfBar for this.
    Essentially, you will have all the code you want to calculate on every tick in the top half of the OnBarUpdate() and then the second half calculate on only the first tick. At the half-way point add this condition check in -

    Code:
    OnBarUpdate()
    {
    //Code that calculates on every incoming tick
    
    if(!FirstTickOfBar)
    return;
    
    //Code that will calculate only on FirstTickOfBar
    
    }
    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Cal,
      It's still not 100% clear to me.

      Here's what you wrote:
      "The first is the method is to use a intrabar granularity which you will then use BarsInProgress to separate out the logic of which bar event is calling the OnBarUpate() method."

      Here's what I want:
      1) If I have an indicator which uses COBC = false and FTOB and I include it in a strategy. Then, I'm presuming that I must have COBC = false in the strategy. Is this correct?

      2) The rest of the strategy requires only bars and to effect that it uses different BarsInProgress as needed. So, my next question is if the strategy has COBC = false but uses only BarsInProgress (with the exception of the one indicator, then I will in fact get 1000-volume bars and not ticks if my code looks like this: Add(Instrument.FullName, PeriodType.Volume, 1000, MarketDataType.Ask). Is this correct?

      Comment


        #4
        Bluelou,

        1) If I have an indicator which uses COBC = false and FTOB and I include it in a strategy. Then, I'm presuming that I must have COBC = false in the strategy. Is this correct?
        Correct, you will need to set the strategy to false in order for the strategy to call the indicator on a tick by tick basis.

        2) The rest of the strategy requires only bars and to effect that it uses different BarsInProgress as needed. So, my next question is if the strategy has COBC = false but uses only BarsInProgress (with the exception of the one indicator, then I will in fact get 1000-volume bars and not ticks if my code looks like this: Add(Instrument.FullName, PeriodType.Volume, 1000, MarketDataType.Ask). Is this correct?
        You can you use the BarsInProgress to check when the Volume bar event is taking place. This BarsInProgress is more of a filter to help determine when a tick comes in and to which bars it is coming from. With COBC set to false this will update the OnBarUpdate() with every added data series that has an incoming tick of data.
        If you just want the bar then you would want to use the BarsInProgress and if it is the FirstTickOfBar, that way it only calculates at each new bar.

        Let me know if this clears things up
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Cal,
          I think we're getting closer.

          In the BIP case with COBC = false I'm still not sure what you're telling me. Here are my guesses:
          a.] BIP doesn't work and instead I will get an update on every tick instead of every bar despite using BIP
          b.] BIP does work but the BIP will provide some sort of commingled bar and intra-bar data. I'm not sure how that would affect bar based logic. any ideas?
          c.] BIP will update literally "on bar" if I condition it with the FTOB property.

          Which of a, b, or c is correct?

          If c.] is the correct choice can you provide a short sample code? Also, how would this work since I add a BIP series in Initialize() but can only use FTOB in OnBarUpdate?

          In other words what's the cleanest way to do this. How do I set COBC = false AND use BIP AND have my bar based code not get screwed up with tick data.


          Originally posted by NinjaTrader_Cal View Post
          Bluelou,



          Correct, you will need to set the strategy to false in order for the strategy to call the indicator on a tick by tick basis.



          You can you use the BarsInProgress to check when the Volume bar event is taking place. This BarsInProgress is more of a filter to help determine when a tick comes in and to which bars it is coming from. With COBC set to false this will update the OnBarUpdate() with every added data series that has an incoming tick of data.
          If you just want the bar then you would want to use the BarsInProgress and if it is the FirstTickOfBar, that way it only calculates at each new bar.

          Let me know if this clears things up

          Comment


            #6
            Bluelou,

            The answer is A.

            Consider the following scenario,
            We have the primary data series we are charting and adding two additional time frames for a grand total of 3 data series.

            When COBC is set to false, any incoming tick of data from any of those three data series will call OnBarUpdate(), However NS doesn't know which data series the tick came from, just that there is a tick and to call OnBarUpdate(). This is where BIP comes into play.

            When you use BIP in the OnBarUpdate() that tick is attached the particular BIP in this scenario it will be 1 or the second data series.

            BIP will allow you to filter out the incoming tick and to which BIP has called it.

            The FirstTickOfBar, when used with the BIP, will allow you to determine when a new bar is being made from that BIP.

            Example -
            Code:
            if(BarsInProgess == 1 && FirstTickOfBar)
            {
            //calculate something here
            }
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              What happens when COBC = false and BIP are used in methods like OnExecution(), OnMarketData(), and OnOrderUpdate()? I use all of these.

              Comment


                #8
                OnExecution will only get called when an execution takes place.
                http://www.ninjatrader.com/support/h...nexecution.htm

                OnOrderUpdate will get called when an order gets an update from the broker, such as a filled, accepted, working and so forth.
                http://www.ninjatrader.com/support/h...rderupdate.htm

                OnMarketData is going to get called on any incoming data. This is the only method that you would use the BIP for your data check. The other two methods are mainly IOrder object handling.
                http://www.ninjatrader.com/support/h...marketdata.htm
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  I understand that. Let's use an OnExecution() example.

                  Given within OnExecution() I confirm if I get a fill/partial fill on an entry position. Then, within OnExecution I set a stop based on the BIP. For instance, I call a custom stop function that uses the close of the BIP as the denominator in calculating a stop in percentage terms. This is all done within OnExecution() currently.

                  So, what happens now if COBC = false. How do I set a bar-based stop in OnExecution if BIP is no longer a true BIP but I can only use FTOB inside of OnBarUpdate?




                  Originally posted by NinjaTrader_Cal View Post
                  OnExecution will only get called when an execution takes place.
                  http://www.ninjatrader.com/support/h...nexecution.htm

                  OnOrderUpdate will get called when an order gets an update from the broker, such as a filled, accepted, working and so forth.
                  http://www.ninjatrader.com/support/h...rderupdate.htm

                  OnMarketData is going to get called on any incoming data. This is the only method that you would use the BIP for your data check. The other two methods are mainly IOrder object handling.
                  http://www.ninjatrader.com/support/h...marketdata.htm

                  Comment


                    #10
                    Bluelou,

                    Just to make sure we are on the right page,

                    Are you using multiple instruments with this script or just the primary?
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      Cal,
                      No, just one instrument. The strategy includes 3 BIP. But, I only run the strategy on one data series at a time. The other BIP are just there in case I want to run on different data series; e.g., volume bars instead of time bars. I could rewrite the strategy so that only the primary bar series is required.

                      Nonetheless, the indicator requires COBC = false, while the rest of the strategy uses bars and a bar is used in methods other than OnBarUpdate(). For instance, in the OnExecution() + stop example I gave.

                      ~Lou

                      Comment


                        #12
                        Bluelou,

                        If you are using one instrument, then the BIP would not be necessary for the OnExecution and OnOrderUpdate, as when one of the updates comes through it will be for all the bar series.

                        You can use Closes. Highs, Lows, Opens, Volumes to separate out the logic in the OnExecution on where to place the Stop order and to which data series you want to use.

                        Example, I want the closing price of the 3rd data series in my script -

                        Closes[2][0]

                        The first index, 2, will access the 3rd data series since the index value starts at 0.
                        The second index,0, will be the bars ago.

                        http://www.ninjatrader.com/support/h...tml?closes.htm
                        Cal H.NinjaTrader Customer Service

                        Comment


                          #13
                          Cal,
                          I know. The BIP was there to give me some additional flexibility in working with different bar types (i.e., volume, tick, time). If I strip out BIP then I think I'll be okay.

                          It's likely going to take some rewriting since I didn't realize the limitations of BIP when COBC = false. It would probably help others to mention in the BIP documentation that this is just a convenience feature and that it won't work with COBC = false (i.e., real-time market data).

                          Thanks for walking me through the issue.

                          ~Lou

                          Originally posted by NinjaTrader_Cal View Post
                          Bluelou,

                          If you are using one instrument, then the BIP would not be necessary for the OnExecution and OnOrderUpdate, as when one of the updates comes through it will be for all the bar series.

                          You can use Closes. Highs, Lows, Opens, Volumes to separate out the logic in the OnExecution on where to place the Stop order and to which data series you want to use.

                          Example, I want the closing price of the 3rd data series in my script -

                          Closes[2][0]

                          The first index, 2, will access the 3rd data series since the index value starts at 0.
                          The second index,0, will be the bars ago.

                          http://www.ninjatrader.com/support/h...tml?closes.htm

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by argusthome, 03-08-2026, 10:06 AM
                          0 responses
                          88 views
                          0 likes
                          Last Post argusthome  
                          Started by NabilKhattabi, 03-06-2026, 11:18 AM
                          0 responses
                          48 views
                          0 likes
                          Last Post NabilKhattabi  
                          Started by Deep42, 03-06-2026, 12:28 AM
                          0 responses
                          30 views
                          0 likes
                          Last Post Deep42
                          by Deep42
                           
                          Started by TheRealMorford, 03-05-2026, 06:15 PM
                          0 responses
                          34 views
                          0 likes
                          Last Post TheRealMorford  
                          Started by Mindset, 02-28-2026, 06:16 AM
                          0 responses
                          68 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Working...
                          X