Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Horizontal Line at Contract Volume

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

    Horizontal Line at Contract Volume

    Hi,

    I'm a bit new to NinjaScript, and trying to figure out how to plot contract volume on a chart.

    I was able to create a template with the wizard that plots a line, and now I need to calculate max volume at any given price in order to incert that value into this template.

    I was looking at the VolumeProfile indicator for ideas, but not certain how to convert this function to return the price level with maximum recorded volume for the duration of the contract.

    Code:
            private void OnMarketData(object sender, MarketDataEventArgs e)
            {
                if (e.MarketDataType == MarketDataType.Ask)
                {
                    askPrice = e.Price;
                    return;
                }
                else if (e.MarketDataType == MarketDataType.Bid)
                {
                    bidPrice = e.Price;
                    return;
                }
                else if (e.MarketDataType != MarketDataType.Last || ChartControl == null || askPrice == 0 || bidPrice == 0)
                    return;
    
                if (allHours == 0)
                {
                    if (ChartControl.SessionBegin.Hour == 0 && ChartControl.SessionBegin.Minute == 0 && ChartControl.SessionEnd.Hour == 0 && ChartControl.SessionEnd.Minute == 0)
                        allHours = 1;
                    else
                        allHours = 2;
                }
                
                if (allHours == 2)
                {
                    long currentTimeTicks = DateTime.Now.TimeOfDay.Ticks;
                    if (currentTimeTicks < ChartControl.SessionBegin.TimeOfDay.Ticks || currentTimeTicks > ChartControl.SessionEnd.TimeOfDay.Ticks)
                        return;
                }
    
                double    price    = e.Price;
                int        volume    = e.Volume;
    
                if (!volumeInfo.ContainsKey(price))
                    volumeInfo.Add(price, new VolumeInfoItem());
    
                VolumeInfoItem volumeInfoItem = volumeInfo[price];
    
                if (price >= askPrice) 
                    volumeInfoItem.up += volume;
                else if (price <= bidPrice)
                    volumeInfoItem.down += volume;
                else
                    volumeInfoItem.neutral += volume;
            }
    Could someone help please.

    #2
    Hello,

    Is this a "real-time only" indicator like the power volume indicators? Or are you trying to make this work in historical data?

    You will likely wannt to use Math.Max():


    Or MAX():
    DenNinjaTrader Customer Service

    Comment


      #3
      I need it to work on historical data as well...

      Luckily I already found one that should do the trick:


      Seek and you shall find!

      Cheers

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      576 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      334 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      553 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X