Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMarketData IB LastClose

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

    OnMarketData IB LastClose

    Hi,

    I have been trying to get the close price for the previous day with OnMarketData, but I never get (e.MarketDataType == MarketDataType.LastClose). My broker is interactive brokers.

    Is this an IB limitation? If yes how can I get the previous day's close? It must be published somewhere since I see a value appearing in the market analyzer under last close....

    Thanks a lot.

    #2
    Unfortunately this is a fundamental data type that IB does not support.

    You could still get the prior close through other methods in OnBarUpdate() such as GetDayBar()


    Or using Close[] http://www.ninjatrader.com/support/h...html?close.htm

    Please let me know if I can be of further assistance.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Well I am using minute bar for multiple instruments. So I guess I could use Close[] but then would have to add a day bar just for that...

      I actually tried the following, but it always return null. Am I supposed to download historical data for the previous day manually?

      Code:
      BarsArray[BarsInProgress].GetDayBar(1)
      Thanks
      Last edited by benoirat; 04-03-2013, 11:12 AM.

      Comment


        #4
        You would have to ensure you're in the correct BIP


        If you are then you should be able to use:

        Code:
        // Print the prior trading day's close
        if (Bars.GetDayBar(1) != null)
            Print("The prior trading day's close is: " + Bars.GetDayBar(1).Close.ToString());
        You would need the historical data available on your chart.
        LanceNinjaTrader Customer Service

        Comment


          #5
          Ok, so even in this case, I am getting null for evey bar. I currently have 4 minute bars (2 instruments with bid and ask each).

          I am not using a chart, my strategy is running from the strategies tab. Is this an issue? I have days to load parameter set to 2, and minimum bars to zero. I do have the minute data for yesterday, I can see it in the historical data manager and I can simulate over it.

          Comment


            #6
            Could you please post your source file or simplified version that replicates the error?

            I tested this on my end and it seems to work properly when using two instruments on a minute chart

            Code:
            			if (BarsInProgress == 0)
            			{
            				// Print the prior trading day's close
            if (Bars.GetDayBar(1) != null)
                Print("The prior trading day's close is: " + Bars.GetDayBar(1).Close.ToString());
            			}
            			else
            			{
            				// Print the prior trading day's close
            if (Bars.GetDayBar(1) != null)
                Print("The prior trading day's close is: " + Bars.GetDayBar(1).Close.ToString());
            			}
            LanceNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by love2code2trade, Yesterday, 01:45 PM
            4 responses
            28 views
            0 likes
            Last Post love2code2trade  
            Started by funk10101, Today, 09:43 PM
            0 responses
            7 views
            0 likes
            Last Post funk10101  
            Started by pkefal, 04-11-2024, 07:39 AM
            11 responses
            37 views
            0 likes
            Last Post jeronymite  
            Started by bill2023, Yesterday, 08:51 AM
            8 responses
            45 views
            0 likes
            Last Post bill2023  
            Started by yertle, Today, 08:38 AM
            6 responses
            26 views
            0 likes
            Last Post ryjoga
            by ryjoga
             
            Working...
            X