Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Updating the High of Bar on every tick

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

    Updating the High of Bar on every tick

    I am trying to learn how to use OnMarketData() to gain access to tick data in my scripts. As a test, I've used the BuySellVolume example to try to learn. My test script tries to put a dot on the High of a bar by setting the values inside of OnMarketData(). The dots appear to be showing up on the Low of the bar at times. Also the first 2 bars don't print anything. A very simple example is attached. Just looking for any guidance as to what I am doing wrong. Here it is:

    HighsFromTickData.zip

    #2
    Hello swooke,

    Thanks for your post.

    Your example is written correctly. For this approach, we should note that NinjaScripts always process OnMarketData after OnBarUpdate, so in OnBarUpdate, we should be assigning the previous BarsAgo for the plot instead of the current slot. ( I.E. MyPlot[1] = tmpVal; instead of MyPlot[0] = tmpVal; )

    1) OnBarUpdate occurs
    2) OnMarketData is called after that tick and High is calculated here.
    3) OnBarUpdate is called again, and when the bar changes, the previous plot value is assigned the value that was developing.

    Please note that OnMarketData will not work for historical data unless Tick Replay is used. The indicator will also be forced to use Calculate.OnBarClose for historical data processing unless Tick Replay used. BuySellVolume and BuySellPressure both require Tick Replay for historical processing.

    Please let us know if we can be of further assistance.

    Comment


      #3
      Jim,

      I am using MyHighs[1] and not MyHighs[0] inside of OnBarUpdate. Can you run it and test? Also, can you be a little more specific about this statement you made:
      Please note that OnMarketData will not work for historical data unless Tick Replay is used

      I have enabled Tick Replay at Tools > Options > Market Data > "Show Tick Replay." Is that all that is required other than adding an OnMarketData() function?

      Comment


        #4
        Hello swooke,

        I have made a demonstration video explaining further and showing how you can assign the plot as it is developing as opposed to when CurrentBar changes. OnMarketData only works for realtime data. It will not process with historical data unless Tick Replay is used.

        Demo - https://drive.google.com/file/d/1MR9...w?usp=drivesdk

        Please let me know if you have any additional questions.
        Last edited by NinjaTrader_Jim; 03-05-2019, 11:37 AM.

        Comment


          #5
          Jim,

          Thank you so much for the video. That was really helpful. However, if I enable Tick replay and just load 1 day's data, the chart never loads. It just shows a message that it is Loading Tick replay and that message never goes away. I am using IQFeed and I have a real time entitlement for ES. This has nothing to do with the Indicator itself. This is happening when I open a new chart and check the box for Tick replay.
          Last edited by swcooke; 03-05-2019, 01:32 PM.

          Comment


            #6
            Hello swooke,

            I do not see this issue on my end when testing with Kinetick or IQFeed. I may suspect that an instrument thread has gotten locked while the NinjaScript assembly was recompiling.

            Could you confirm that you are unable to open a Tick Replay chart with 1 day to load after restarting the platform?

            If you are still seeing issues with Tick Replay charts loading, could you send me a message at platformsupport [at] ninjatrader [dot] com and include a phone number or Skype ID and a time we can get connected to investigate further? (Please include a time zone.) Our regular support hours are 8:30am to 6pm US Eastern, Monday through Friday.

            I look forward to being of further assistance.

            Comment


              #7
              Thanks again for your help on this. I have changed the code slightly to draw the dot on the close of the bar instead of the High. If you run this indicator, you will see that at times, the dot on the last bar that is updating in real time goes out of sync with the last price of the candlestick. Any ideas?

              ClosesFromTickData.zip

              Comment


                #8
                Hello swooke,

                Since OnBarUpdate occurs, OnMarketData then occurs for that data, and then we update the plot on the next OnBarUpdate, we will be 1 tick behind in the plot's assignment in OnBarUpdate. If you test the following, your MyCloses plot will be in sync because we are not updating the plot with a value that was calculated after the first OnBarUpdate iteration where it would be synchronized.

                Code:
                if (CurrentBar != activeBar)
                {
                    MyCloses[1] = Close[1];
                    tmpClose = Close[0];
                    activeBar = CurrentBar;
                }else{
                    MyCloses[0] = Close[0];
                }
                Please let me know if I can be of further assistance.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                657 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                373 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                109 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                574 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                579 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X