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 bars in a startegy

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

    Volumetric bars in a startegy

    Hello

    I am trying to code a strategy that would need to use data from the volumetric bars (such as imbalances), but I am unable to find the right code to make the strategy plot the volumetric bars to begin with.
    The code below from the help guide doesn't do the job, unfortunately.

    Thank you

    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 (barsType == null)
    return;


    try
    {
    double price;
    Print("=========================================== ==============================");
    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);
    }
    catch{}

    #2
    Hello itrader46,

    Thank you for the post.

    You mentioned:
    but I am unable to find the right code to make the strategy plot the volumetric bars to begin with.
    This sample assumes that you have opened a volumetric chart and have applied the script to that chart. There is no means to re plot the volumetric data yourself, that is a BarsType/ChartStyle combination which creates the visual you see.

    If you are using this with a different primary series, you would need to make the modifications in the comments you copied. You could use AddVolumetric and BarsArray[1].


    Can you confirm you have applied this to a volumetric series chart?


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

    Comment


      #3
      I am trying to get the strategy to apply the volumetric bars because I understood that for the strategy to work well, the indicators have to be call by the strategy.
      Anyway, I'm running into two issues with the the AddVolumetric:
      1. I have to hard code into the strategy the instrument I want the volumetric bars applied to, so I think that means I have to build a custom strategy for every instrument I apply it to, unless there is a different way I did not discover yet
      2. Even when I apply the strategy to a chart with another instrument (for instance I apply the strategy coded for CL on a ES chart), the volumetric bars still don't show for the data series to which I apply the strategy with volumetric bars

      It looks I did not understand how to use AddVolumetric, so I could use all the help I could get

      Comment


        #4
        Hello itrader46,

        I am trying to get the strategy to apply the volumetric bars because I understood that for the strategy to work well, the indicators have to be call by the strategy.
        I am not certain I understand what you have said, are you saying that in order to use some indicators you require volumetric data?

        Anyway, I'm running into two issues with the the AddVolumetric:
        1. I have to hard code into the strategy the instrument I want the volumetric bars applied to, so I think that means I have to build a custom strategy for every instrument I apply it to, unless there is a different way I did not discover yet
        Correct, you need to hard code the values in. There is currently no overload which uses the primary instrument for AddVolumetric so this needs to be hard coded.

        2. Even when I apply the strategy to a chart with another instrument (for instance I apply the strategy coded for CL on a ES chart), the volumetric bars still don't show for the data series to which I apply the strategy with volumetric bars
        Correct, you won't see anything visually. This adds a dataseries you can access in code but nothing visual. The visual for the volumetric requires you to change the chart series to volumetric and use the volumetric chart style.


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

        Comment


          #5
          I am trying to code a strategy that will use some data from the volumetric bars (like the imbalances). Is there actually a way to do that?

          Comment


            #6
            Hello itrader46,

            The code you are trying to use is what would be needed to access the volumetric data. You won't visually see the data but could access it from code.

            Are you currently not able to Print the values shown in the sample you provided? You noted that you were having trouble with the sample, what specifically did you try with the sample and what series was it applied to? Again we wont see anything except Prints to the NinjaScript output window when using this sample.



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

            Comment


              #7
              When I apply the strat to a volumetric bars chart the bars disappear, but I can get the values printed in the output window.
              What I'm looking for though, is to see the volumetric bars when I run the strategy, otherwise I will have to just let it run blindly.
              Also, the prints given out by this bar type don't seem to include the bid/ask volume at every price, but at the close. How can I extract the imbalances inside the candles?

              Comment


                #8
                Hello itrader46,

                Thank you for the reply.

                When I apply the strat to a volumetric bars chart the bars disappear, but I can get the values printed in the output window.
                Are you doing any other drawing from the strategy which may create a large scale on the chart? I would not be certain why this would occur without testing the specific script you had in the same way to observe this result. There is nothing specific in the volumetric sample that would cause this to happen, it is only reading data and printing it.

                What I'm looking for though, is to see the volumetric bars when I run the strategy, otherwise I will have to just let it run blindly.
                You would need to apply your strategy to a volumetric chart to view the bars as well.

                Also, the prints given out by this bar type don't seem to include the bid/ask volume at every price, but at the close. How can I extract the imbalances inside the candles?
                This sample only shows one use of each method. If you wanted to access the values at other prices you could supply other prices besides the close price. You could do a loop betwen the range of prices you wanted to check and collect the values needed. The methods that mention "ForPrice" in their name are for collecting a value from a price.

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

                Comment


                  #9
                  This is the strategy copied from the help guide and it hides my volumetric bars

                  Comment


                    #10
                    Hello itrader46,

                    I tried this on my end and see this works as expected, I can see the prints and nothing on the chart changes.

                    There is nothing in the script which would control the bars on the chart, do you have anything else applied to the chart?

                    Are you seeing any errors in the control center log tab when this happens?

                    To be clear, are you specifically creating a chart with one volumetric series and then applying the strategy directly to the volumetric series? It may also help to provide an image of what you are seeing.



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

                    Comment


                      #11
                      Yes, I am applying the strategy to a volumetric series chart and the bars vanish, as in the attachment

                      I've made a short video of what is happening, but I can't attach it, as it is in .wav format



                      Click image for larger version  Name:	Volumetric.PNG Views:	1 Size:	858.4 KB ID:	1072209
                      Last edited by itrader46; 09-26-2019, 01:10 PM.

                      Comment


                        #12
                        Hello itrader46,

                        From the video I cannot see anything that would cause this, I do see that you are using custom settings for the chart and volumetric bars. Could you try making a new chart with no customization to see if the same occurs?

                        You can do this by going to the control center -> New -> Chart
                        In the window that opens make sure the top of the window has <None> selected for templates.
                        Next in the lower right click Preset Volumetric -> Restore, this will restore the defaults for the bars type.
                        Create the chart and apply the strategy
                        Do you see the same result?

                        If you no longer see this happen, I would still like to collect details from you so we can identify what the cause was.



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

                        Comment


                          #13
                          I tried removing the Volumetric bars preset and it works fine now, even when I modify the default values, but it doesn't like to work with changed default presets.

                          One more question about this strategy I am trying to code: am I gonna be able to do that as a strategy, or would I need to create an ad-on with Visual Studio?

                          Comment


                            #14
                            Hello itrader46,

                            Thank you for confirming that solved the issue. I would like to collect the preset from you so I can check that out further. Could you email our platform support [at] ninjatrader.com and attach the link to this post and the file: Documents\NinjaTrader 8\templates\ChartSeries\Volumetric.xml

                            You can create an addon for the use you have described in this thread, the chart going blank was an unexpected item which we can review. A strategy can utilize the volumetric data.

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

                            Comment


                              #15
                              I'm not sure I understand what you mean by 'I would like to collect the preset from you so I can check that out further'.

                              It plays up when you set other presets than the platform default ones for the Volumetric bars

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by quicksandatl, Today, 01:39 PM
                              1 response
                              1 view
                              0 likes
                              Last Post quicksandatl  
                              Started by md4866, 05-01-2024, 08:15 PM
                              2 responses
                              18 views
                              0 likes
                              Last Post md4866
                              by md4866
                               
                              Started by samish18, Today, 12:20 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post samish18  
                              Started by thread, 04-15-2024, 11:58 PM
                              3 responses
                              48 views
                              0 likes
                              Last Post Georg1o
                              by Georg1o
                               
                              Started by leojimenezp, 04-20-2024, 05:49 PM
                              4 responses
                              50 views
                              0 likes
                              Last Post leojimenezp  
                              Working...
                              X