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

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 judysamnt7, 03-13-2023, 09:11 AM
      4 responses
      56 views
      0 likes
      Last Post DynamicTest  
      Started by ScottWalsh, Today, 06:52 PM
      4 responses
      35 views
      0 likes
      Last Post ScottWalsh  
      Started by olisav57, Today, 07:39 PM
      0 responses
      7 views
      0 likes
      Last Post olisav57  
      Started by trilliantrader, Today, 03:01 PM
      2 responses
      19 views
      0 likes
      Last Post helpwanted  
      Started by cre8able, Today, 07:24 PM
      0 responses
      8 views
      0 likes
      Last Post cre8able  
      Working...
      X