Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

OnMarketData - OnBarUpdate

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

    OnMarketData - OnBarUpdate

    Hello,

    I cant find in the threads an information what might be the difference when placing conditons in OnMarketData or in OnBarUpdate-with-COBCfalse. And reason for not doing in one of them? Any differences for CPU or speed of script?

    Thank you!
    Tony

    #2
    Hello,

    Thank you for the post.

    It really depends on what you are trying to do in your script which would more or less delegate which you would possibly want to use. OnBarUpdate and OnMarketData are results of the same data being processed. It just would depend if you want to process each tick or have some structure to when your logic is executed. It may also depend if you need historical data processed or not, or could be that you want ask and bid data. There are quite a few reasons to use one or the other or both depending on your goal.

    General speaking, any difference in cpu or speed between overrides being used at a tick by tick basis would be negligible, your logic will still control the overall utilization of the CPU and speed of the script. As far as the frequency each are called, you could use a Print in each override to see this for the instrument you use.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      thank you for your reply. I dont need historical data. What you mean about ask and bid data? What is the difference for ask and bid data please when coding in onMarketdata or onBarUpdateCOBCfalse.

      Thank you!
      Tony

      Comment


        #4
        Hello,

        If you don't need historical data, you can still use either override. It would still relate to how you want the script to calculate the logic and what data sources are needed.

        The OnMarketData override gets called for ask bid and last events where OnBarUpdate uses the various input series you specify which could also be ask bid and last series. The main difference is that OnMarketData is specifically for realtime market data events in 1 tick intrevals, OnBarUpdate is specifically for historical or realtime "bar closed" events *except when processing for each tick, in that case, it processes each input series on a tick by tick basis. You could think of OnBarUpdate as a more specific market data event, for example, it is may be only called for each last tick opposed to OnMarketData which may be called for each ask bid or last event.

        In regard to getting the ask bid and last values, from OnBarUpdate you can either add an ask and bid series to access their values using the Closes collection, or use GetCurrentAsk()/GetCurrentBid().
        For OnMarketData please see the help guide example:


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello gplatis,

          Thank you for the post.

          First I would like to clarify that a Backtest and Market Replay are two different tools. You can Backtest a script in the Analyzer using Historical data, and you can Play forward a script over recorded Replay data in Market Replay. These two tools are going to work differently as the data used is different.

          In a Historical backtest where you use Historical data specifically, you cannot use COBC = false, a Backtest will always use COBC = true with the data. You have the OHLC of the bar to use, and you can use a 1 tick series to have the finest granularity in a backtest. This still is COBC=true meaning OnBarUpdate would be called once for each tick closed and OnMarketData is not called at all.

          In MarketReplay, the OnMarketData override is called in addition to OnBarUpdate because you are playing back through realtime data that was recorded. This could cause differences depending on how you write your logic. I would suggest testing both cases to see if your logic is executed differently.

          If you are only using Replay, and only comparing OnBarUpdate versus OnMarketData on 1 tick data, you may see differences although this is highly dependant on how you wrote your logic. OnMarketData is called for each update ask bid or last, if you are only using Last events it should be very close to OBU COBC = false in terms of when the platform calls this event.

          I can suggest using Prints to better visualize any differences between the various tools in the platform as well, this would be a good case to Print from each override without any conditions to see when they are called.


          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Hello Jesse,

            I want to ask please if this structure is OK and will it trigger with bool set true from BIP1 or/and BIP2

            Initialize
            CalculateOnBarClose = false;
            Add(PeriodType.Tick,144);
            Add(PeriodType.Range,3);

            OnbarUpdate
            {
            if (Historical)return;
            If(BarsInProgress==1 && FirstTickOfBar && conditionsentry[1] true) BIP1=true;
            If(BarsInProgress==1 && FirstTickOfBar && conditionsreset[1] true) BIP1=false;

            If(BarsInProgress==2 && FirstTickOfBar && conditionsentry[2] true) BIP2=true;
            If(BarsInProgress==2 && FirstTickOfBar && conditionsreset[2] true) BIP2=false;

            If(BIP1==true && BIP2==false) EnterShort(1);
            If(BIP1==false && BIP2==true) EnterShort(2);
            If(BIP1==true && BIP2==true) EnterShort(3);
            }

            I´m running this script to test and debug in a 144 Tick Chart and in a 1 min Chart and for debugging I show the bools and values in the chart.
            In the 144 tick chart the entry is triggered, in the 1 min chart the entry is not triggered and the bools and values are not plotted correctly in the chart.

            Thank you!
            Tony
            Last edited by tonynt; 12-15-2017, 11:30 AM. Reason: translation error, clearifying

            Comment


              #7
              Hello,

              Thank you for the post.

              I couldn't really say as all of the details are not present here. I don't see that you are utilizing BarsInProgress 0 which may relate to the 1 minute series in case that is the primary.

              You had also noted that the bools and values are not plotted correctly, this is likely where I would start debugging. In case the data needed for the remainder of your calculations are not being calculated correctly, that may be another contributing factor.

              If the data being plotted is coming from an indicator, I would suggest debugging only the indicator first to see how it plots on a 1 minute chart. If it is not correct, address that first before moving on to your order methods in a strategy.


              Please let me know if I may be of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Hello Jesse,

                thank you for your reply from which I found a bug in my script immediately. Its plotting the values correctly now in the 1 min chart as well and triggering the entry.

                But a question referring BarsInProgress 0 you mentioned: do I have utilizing BIP 0 in the script also when I dont use this dataseries in the code? I only run the script in a 1 min chart. But I have no condition with 1 min in the code. Or would I have to add if (Historical || CurrentBars[0]<1 || CurrentBars[1]<1 || CurrentBars[2]<1) return?

                And another question in this context please: when running this sample script with Initialize COBCtrue in the 1 min chart would this work same with BIP1 asnd BIP2 (of course I do not need FirstTickOfBar then and have to change adressing Bars[1] to Bars[0]), but from the idea. Or is the COBCtrue fixing every action to the close of the BIP0 bar of my 1 min chart?

                Thank you!
                Tony
                Last edited by tonynt; 12-15-2017, 12:42 PM. Reason: translation error, clearifying

                Comment


                  #9
                  Hello,

                  Thank you for the reply.

                  I had only mentioned that you are not using BIP 0, you don't need to use this but in this case, without all the details it was something else for you to check.

                  Regarding CalculateOnBarClose, this is tied to all series you are using. If you use false, all series are calculating tick by tick. If you are using true, you can utilize the bar close events which are called for the various timeframes you are using.

                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by ScottWalsh, Today, 04:52 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post ScottWalsh  
                  Started by ScottWalsh, Today, 04:29 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post ScottWalsh  
                  Started by rtwave, 04-12-2024, 09:30 AM
                  2 responses
                  22 views
                  0 likes
                  Last Post rtwave
                  by rtwave
                   
                  Started by tsantospinto, 04-12-2024, 07:04 PM
                  5 responses
                  70 views
                  0 likes
                  Last Post tsantospinto  
                  Started by cre8able, Today, 03:20 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post cre8able  
                  Working...
                  X