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

Volumetric Tick Charts not reflecting proper trade counts via IsFirstTickOfBar

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

    Volumetric Tick Charts not reflecting proper trade counts via IsFirstTickOfBar

    *** UPDATE 1: *** I partially figured it out...

    The variable Trades is set when the strategy is started. If it's started in the middle of a bar being created, it just assigns the first trade to whatever is going on in that volumetric bar.

    What I need is for the below code to start counting when the first tick of the new bar is registered, and not when the strategy is started. Hope that makes sense!

    ==========

    Hi there!

    I have IWM loaded up on a 20 tick volumetric chart, and it doesn't seem to sync with the IsFirstTickOfBar part of my code. When the chart creates a new 20 tick bar, the 'Trades' variable is at 10. (barsType.Volumes[CurrentBar].Trades)

    Here's the code I took from the Guide to see the available variables produced by the volumetric bars. For reference, volCount is a local variable I created to verify that the script is not starting at the proper Trade count when a new bar is created in the chart:

    Code:
    protected override void OnBarUpdate()
    {
    if (Bars == null)
    return;
    
    // This sample assumes the Volumetric series is the primary DataSeries on the chart, if you would want to add a Volumetric series to a
    // script, you could call AddVolumetric() in State.Configure and then for example use
    // NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = BarsArray[1].BarsType as
    // NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
    
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
    
    if (IsFirstTickOfBar) // If this is the first tick of a new bar, start all this material
    {
    volCount = 1;
    
    } // End of First Tick of Bar
    
    Print("=========================================== ==============================");
    Print("VolCount = " + volCount);
    Print("Bar: " + CurrentBar);
    Print("Trades: " + barsType.Volumes[CurrentBar].Trades);
    Print("Total Volume: " + barsType.Volumes[CurrentBar].TotalVolume);
    Print("Total Buying Volume: " + barsType.Volumes[CurrentBar].TotalBuyingVolume);
    Print("Total Selling Volume: " + barsType.Volumes[CurrentBar].TotalSellingVolume);
    Print("Delta for bar: " + barsType.Volumes[CurrentBar].BarDelta);
    Print("Delta for bar (%): " + barsType.Volumes[CurrentBar].GetDeltaPercent());
    Print("Delta for Close: " + barsType.Volumes[CurrentBar].GetDeltaForPrice(Close[0]));
    Print("Ask for Close: " + barsType.Volumes[CurrentBar].GetAskVolumeForPrice(Close[0]));
    Print("Bid for Close: " + barsType.Volumes[CurrentBar].GetBidVolumeForPrice(Close[0]));
    Print("Volume for Close: " + barsType.Volumes[CurrentBar].GetTotalVolumeForPrice(Close[0]));
    Print("Maximum Ask: " + barsType.Volumes[CurrentBar].GetMaximumVolume(true, out price) + " at price: " + price);
    Print("Maximum Bid: " + barsType.Volumes[CurrentBar].GetMaximumVolume(false, out price) + " at price: " + price);
    Print("Maximum Combined: " + barsType.Volumes[CurrentBar].GetMaximumVolume(null, out price) + " at price: " + price);
    Print("Maximum Positive Delta: " + barsType.Volumes[CurrentBar].GetMaximumPositiveDelta());
    Print("Maximum Negative Delta: " + barsType.Volumes[CurrentBar].GetMaximumNegativeDelta());
    Print("Max seen delta (bar): " + barsType.Volumes[CurrentBar].MaxSeenDelta);
    Print("Min seen delta (bar): " + barsType.Volumes[CurrentBar].MinSeenDelta);
    Print("Cumulative delta (bar): " + barsType.Volumes[CurrentBar].CumulativeDelta);
    
    volCount++;
    
    }

    Hope this is clear, but let me know if you have any questions.
    Last edited by Spiderbird; 01-11-2022, 01:09 PM.

    #2
    Hello Spiderbird,

    Thanks for your post.

    We would need to allow the first realtime bar to complete before Trades can match the number of ticks counted with Calculate.OnEachTick.

    If you apply the attached indicators to a Volumetric 150 tick chart and allow the first realtime bar to close, you may see the counts matching after that.

    We look forward to assisting.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim!

      Thank you very much for the response.

      Originally posted by NinjaTrader_Jim View Post
      We would need to allow the first realtime bar to complete before Trades can match the number of ticks counted with Calculate.OnEachTick.
      That's what I figured. However, when I looked at the code, won't tickCount always be equal to 1 at the start of every bar?
      I'm referencing this:

      Code:
      protected override void OnBarUpdate()
      {
      NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as
      NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
      
      if (barsType == null)
      return;
      
      if (IsFirstTickOfBar)
      tickCount = 0;
      
      tickCount++;
      
      Print("");
      Print(tickCount);
      
      
      try
      {
      double price;
      Print("Trades: " + barsType.Volumes[CurrentBar].Trades);
      }
      catch{}
      }
      Because that's what I had been doing in the code I attached in my original message with volCount, only I was updating that variable with every trade.
      Also, I didn't see any reference to Calculate.OnEachTick in the indicator code you attached. I was searching for it but wondered if I misunderstood something.

      So I guess my question at this point is:
      How do I use Calculate.OnEachTick to properly reset the trade count to 1 at the start of a new bar displayed on a 20 tick volumetric chart (so it matches volumetric data in the output screen)?

      Hope that makes more sense than my first post.

      - R

      Comment


        #4
        Hello Spiderbird,

        Calculate would be set to OnEachTick in the Indicators dialog when applying to a chart.

        tickCount is reset to 0 on the first tick of a new bar, and then it is incremented with tickCount++;

        Then the value is printed.

        If you check tickCount after tickCount++; and the value is 1, This is still the first tick of the bar, and the tick count is at 1.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hi Jim!

          Unfortunately, your indicator didn't work either. I have it loaded up in the following video and the trade / bar count is still out of sync with the volumetric chart I have up for IWM. For reference, I'm using the code from the NT8 Guide to showcase what's being shown in the Output window at the upper left.



          Please let me know if I'm missing anything.

          Comment


            #6
            Hello Spiderbird,

            I don't see my prints in your video. I only see the prints from Volumetric Bars output.

            If you reimport my test indicator and let the first bar form, you will see my tickCount print matches the Volumetric Trades print.

            Bar from the Volumetric Bars print is CurrentBar, which would be the current bar on the chart that is being processed.

            Trades is the number of ticks in that bar.
            JimNinjaTrader Customer Service

            Comment


              #7
              Hi Jim,

              So to be clear in terms of process, you're advising me to:

              1. Start Ninjatrader 8
              2. Connect to my provider
              3. Create a new volumetric tick chart (I'll stick with IWM)
              4. Re-import the indicator you attached in this thread.
              5. Apply that indicator to the new volumetric chart (in a new panel, which is what was shown in the video)
              6. Enable the strategy I'm using to print the outputs available in the Volumetric example from the NT8 Guide
              7. See the tickCount print match the Volumetric Trades print.

              Let me know if the above looks good.
              Also, let me know if I'm supposed to add some code to the strategy in order to showcase data from the indicator you provided.

              Thanks in advance!

              Comment


                #8
                Hello SpiderBird,

                Yes, if you connect to your provider, open a volumetric chart, re-import the indicator posted in post #2, and apply it to the chart, you will see the prints from my test indicator in the output window.

                After the first realtime bar completes, the Trades print and tickCount print are aligned.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Hi Jim,

                  I got the indicator to work and it's printing in the output window (yay!). Thank you very much for your guidance there. Here's an updated video showing how the indicators' data and the volumetric chart script are in sync:



                  So from here, how do I use the correct Trades and tickCount data from the indicator to sync with the volumetric chart variables?

                  Is it a matter of including the indicator in the strategy, taking the correct Trades and tickCount data from it and replacing the existing CurrentBar variable so that the rest of the volumetric chart data lines up properly?

                  If so, I would really appreciate a small example of how to call the indicator data and integrate it with the volumetric chart data. I can do the rest once I know the proper way of calling everything.

                  Thanks in advance. You've been a great help.

                  Comment


                    #10
                    Hello Spiderbird,

                    You could do the following:
                    1. Implement the tickCount code in a strategy
                    2. Add a plot to the indicator and assign the tickCount value to the plot.
                    For adding plots and assigning values to the plot, please see below.

                    AddPlot - https://ninjatrader.com/support/help...ml?addplot.htm

                    If you need more in depth guide on plotting, our Indicator tutorials can be referenced.

                    Indicator tutorials - https://ninjatrader.com/support/help...indicators.htm

                    When the indicator plots a value, it can be accessed by the strategy. You can then even use the Strategy Builder to create syntax for reading the plot.

                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      Hi Jim!

                      I'm sorry. I didn't phrase the question correctly in my last post. Let me try to rephrase my problem.

                      What I'm trying to do is sync up the data coming from volumetric charts with what I'm seeing in my strategy. Right now, the output from the strategy (using the volumetric example in the help guide) is dependent entirely on when my strategy is enabled.

                      The indicator you provided helps to reset both Trades and tickCount data, but I need to be able to bring that into a strategy to re-align the output I'm seeing from the volumetric data. Otherwise, the volumetric data/information from the strategy will not reflect the volumetric chart accurately.

                      For reference, I do not need to plot anything on a chart.

                      In the past, I've gotten help on accessing variables coming from indicators. Here are a few examples:

                      Code:
                      // Variables related to Bollinger Bands
                      double BUpper,
                      BMiddle;
                      
                      // etc.
                      
                      if (FirstTickOfBar)
                      {
                      
                      // All Bollinger Band values are set here
                      BUpper = Math.Round(Bollinger(2,12).Upper[1],2);
                      BMiddle = Math.Round(Bollinger(2,12).Middle[1],2);
                      
                      // All DoubleStochastics variables are set here
                      stoch = Math.Round(DoubleStochastics(15)[1],2);
                      
                      //  All HeikenAshi variables are set here
                      HA_Open = HeikenAshiSmoothed(.7,HAMA.SMA,HAMA.SMMA,1,2).HAOp en[1];
                      HA_Close = HeikenAshiSmoothed(.7,HAMA.SMA,HAMA.SMMA,1,2).HACl ose[1];
                      }
                      So, in order for me to try and correct the volumetric data to align with the data coming from your indicator, I'm wondering what variables to reference from your indicator to do so.

                      Let me know if that makes more sense.


                      Comment


                        #12
                        Hello Spiderbird,

                        The indicator just shows how Trades could be counted. Let's take a step back:

                        If you apply a strategy or indicator to a volumetric chart, and you reference the the Volumetric bars as described in the Help Guide, you would be reading the volumetric bars on the chart.

                        The prints would then match what you see in the chart whenever the script processes OnBarUpdate. If you want the realtime prints to match what is on the chart, use Calculate.OnEachTick. See demonstration below:



                        Please test the same to see that your prints match what is seen on the chart when you apply the script to a volumetric chart.

                        After testing, please clarify, what is out of sync between the what you see with the strategy prints and what you see with the chart.

                        JimNinjaTrader Customer Service

                        Comment


                          #13

                          Hi Jim!

                          Thank you very much for the video and running through your environment to show how everything was matching up. It was really interesting to hear your voice explain what you were looking at.

                          Having watched your video, I was determined to figure it out. So, this problem kept me up last night and I worked on it really late. It turns out it was a simple solution after all.

                          The steps were:
                          1. Start Ninjatrader 8
                          2. Start Market Replay
                          3. Create a new volumetric chart (20 ticks, etc.) using the default template.
                          4. Load the strategy I was working on from the chart (and not from the Control Center)
                          5. Enable your indicator (for reference)
                          6. Enable the strategy and start market replay.
                          7. Stare in amazement as everything works

                          The solution:
                          The volumetric chart I was using was over two weeks old. Between tons of restarts, connection drops and other NT8 functions and actions over different sessions, the BarCount between the strategy and the chart was miscalculating.

                          So, the solution was to create a brand new chart, apply a template to keep the previous settings, and everything synched up.

                          =====

                          Very much appreciate you person being patient with me, and I hope the rest of your week goes well.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by funk10101, Today, 09:43 PM
                          0 responses
                          4 views
                          0 likes
                          Last Post funk10101  
                          Started by pkefal, 04-11-2024, 07:39 AM
                          11 responses
                          36 views
                          0 likes
                          Last Post jeronymite  
                          Started by bill2023, Yesterday, 08:51 AM
                          8 responses
                          44 views
                          0 likes
                          Last Post bill2023  
                          Started by yertle, Today, 08:38 AM
                          6 responses
                          26 views
                          0 likes
                          Last Post ryjoga
                          by ryjoga
                           
                          Started by algospoke, Yesterday, 06:40 PM
                          2 responses
                          24 views
                          0 likes
                          Last Post algospoke  
                          Working...
                          X