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

How to calculate total Volume@ForEachPrice in a given period?

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

    How to calculate total Volume@ForEachPrice in a given period?

    Hi everyone.

    I'd like to know how I can calculate the correct volume@price for a given period.
    So for instance, I'd like to calculate the total volume for each price that was traded during 9.30-16.15.

    I've tried the following for each bar:

    Dictionary<string, double> d_prices = new Dictionary<string, double>();
    private bool get_all_price_volume_pairs_for_current_bar()
    {

    double ticksize = Bars.Instrument.MasterInstrument.TickSize;
    double high = Bars.GetHigh(CurrentBar);
    double low = Bars.GetLow(CurrentBar);
    double theprice = 0;

    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = BarsArray[2].BarsType as//Bars.BarsSeries.BarsType as
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;


    for(double price = high;price >= low; price -= ticksize)
    {

    double volume = barsType.Volumes[CurrentBar].GetTotalVolumeForPrice(price);

    if (volume == 0)
    continue;

    if(d_prices.ContainsKey(price.ToString()))
    {
    d_prices[price.ToString()] += volume;

    } else {
    d_prices.Add(price.ToString(),volume);
    }

    }
    return true;
    }


    However, this doesn't seem to get me exactly the correct volume for say 200 bars if I measure with other indicators.

    Anyone who can help me please?

    Thanks!

    Bo

    #2
    Hello bohenriksen,

    Welcome to the NinjaTrader support forums.

    From what is provided I am not sure what difference you are seeing to really suggest anything. Have you tried a very short period to output values and see where it specifically deviates? Is this different on every bar or is this happening in a specific area?

    How are you currently doing the comparison? it looks like you are adding the volumetric data as a secondary series, are you comparing that against another volumetric chart? Have you also tried to use the volumetric the primary series and apply this directly to the volumetric chart as shown in the help guide sample? Does that make a different in accumulation?

    Another thought that goes along with the secondary series would be that you have no filtering shown in the sample, are you using BarsInProgress and calling this during a specific BarsInProgress or just all the time?

    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jesse; 12-10-2019, 08:03 AM. Reason: spelling edits
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,
      thanks so much for your answer.

      I found out that I was doing it correct, but had wrong session info loaded :-).

      Thank you

      Best,
      Bo

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by algospoke, Yesterday, 06:40 PM
      2 responses
      22 views
      0 likes
      Last Post algospoke  
      Started by ghoul, Today, 06:02 PM
      3 responses
      14 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      45 views
      0 likes
      Last Post jeronymite  
      Started by Barry Milan, Yesterday, 10:35 PM
      7 responses
      21 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by AttiM, 02-14-2024, 05:20 PM
      10 responses
      181 views
      0 likes
      Last Post jeronymite  
      Working...
      X