Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy with COBC = true needs Opening price

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

    Strategy with COBC = true needs Opening price

    I have a multi-series strategy that needs to run with COBC = true. One series is 5 min and the other is a range bar type. I would like to get the Opening price, but I dont want to wait 5 mins to check the 9:35 bar for the Open[0].

    What are my options please?

    #2
    Hello Laserdan,
    Thanks for writing in and I am happy to assist you.

    You can use the Opens[<bars array index>][0] to get the opening price of the 5 minute bar. http://www.ninjatrader.com/support/h...html?opens.htm
    For example if your primary data series is a range bar and the secondary data series is a 5 minute data series and you want to get the opening price of the 5 minute bar when the range bars gets updated then you can use the following code

    Code:
    if (BarsInProgress == 0)	//range bar updates
    {
    	double open5 = Opens[1][0];	//gets the open of the 5 minute data series
    	//rest of code
    }
    Alternatively you can also open the OnMarketData steam and get update from there.


    You could also set COBC to false and check the all relevant codes in the FirstTickOfBar while get the opening value from the OnBarUpdate method as it updates. Please refer to this sample code to get more idea on it http://www.ninjatrader.com/support/f...ad.php?t=19387

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Since my strategy HAS to run with COBC = true
      AND i do not wish to wait 5 mins or until a range bar is complete (could be 10 mins or more)

      Then my only option is the OnMarketData stream which would be CPU intensive.

      is this correct?

      Comment


        #4
        Hello Laserdan,
        Yes it will eat up resource, but it depends on how much code you expose in the OnMarketData event. For example you could set your entry logic in the OnBarUpdate event while the exit logic is coded in the OnMarketData event. This way you can optimize resource utilization.

        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          I just need the Opening price (the 1st tick) to store in a local variable...thats all i need it for. Just once a day, just the opening tick. seems like a lot of CPU cycles for just that one data point.

          Just wondering if I had any other options.

          Comment


            #6
            Hello Laserdan,
            If you only need the opening price of the then no need to set COBC to false. Please use the following code

            Set COBC to false and use the following code
            Code:
            protected override void OnBarUpdate()
            {
            	if (BarsInProgress == 0 && FirstTickOfBar && BarsArray[0].FirstBarOfSession)
            	{
            		//get open price
            	}
            	else if (FirstTickOfBar)
            	{
            		//rest of the code
            	}
            		
            }

            Alternatively you can also use the following code with COBC set to true. But do note the OnMarketData stream will remain open which will consume some resource and OnMarketData is for realtime only. It cannot be backtested.
            in variable
            Code:
            bool gotOpenPrice = true;
            Code:
            protected override void OnMarketData(MarketDataEventArgs e)
            {
            	if (BarsInProgress == 0 && BarsArray[0].FirstBarOfSession && e.MarketDataType == MarketDataType.Last && gotOpenpricee == false)
            {
            		//get open price;
            		gotOpenPrice = true;
            	}
            }
            If it is a multi timeframe strategy (i.e. instrument is same but different timeframe) then the opening price of the day will be same for all data series as such we pull it from any one series.

            Please let me know if I can assist you any further.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Thank you for your time JoyDeep. I was afraid that was the case.

              Please remember I HAVE TO RUN WITH COBC = true for various other reasons in this complex strategy I have written.

              So my only option is to access a datastream in the OnMarketUpdate method. Which will only be used on live data , no backtesting.

              If I wanted to backtest I guess i could I use another dataseries of 1 tick & check that when the market opens. I am using range bars anyways, so I need tick data to build the range bars. I guess it wont slow it down that much...

              Comment


                #8
                Hello Laserdan,
                Yes you can create an additional data series of higher granularity and backtest the same. Since you will be using bar granularity of 1 tick bar, backtest time will be longer.

                Please let me know if I can assist you any further.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Thank you, I will take it from here.

                  Great support once again!

                  Comment


                    #10
                    Hello Laserdan,
                    Good luck and please let me know if I can assist you any further.
                    JoydeepNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    647 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    369 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    108 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    572 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    573 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X