Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem in coding of Calculating sum of Volume of multiple symbols

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

    Problem in coding of Calculating sum of Volume of multiple symbols

    Hello Readers,

    I was trying to write code for calculating sum of volume of multiple symbols.

    program complied successfully but it doesn't draw or plot anything.

    if you can look at it and let me know where I am going wrong , can be great help to me.

    I am using ninja 8

    here is the code,

    if (CurrentBars[0] == 0)
    {
    // Get the master instrument associated with the current chart or data series
    List<Instrument> instrumentList = new List<Instrument>();

    foreach (Instrument instrument in Instruments)
    {
    if (instrument.FullName.Contains("BankNifty") && instrument.FullName.Contains("CE"))
    {
    instrumentList.Add(instrument);
    }
    }
    foreach (Instrument instrument in instrumentList)
    {
    Print(instrument.FullName);
    }


    foreach (Instrument instrument in instrumentList)
    {
    sumVolumeDict[instrument.FullName] = 0;
    }
    }
    else
    {

    // Loop through the filtered instruments and calculate the sum of volume
    //foreach (Instrument instrument in instrumentList)
    foreach (string symbol in sumVolumeDict.Keys)
    {

    double sumVolume = 0;

    for (int i = BarsRequiredToPlot; i < CurrentBars[0]; i++)
    {
    if(symbol == Instrument.FullName && symbol.Contains("CE"))
    {
    sumVolume += Volume[i];
    }
    }
    sumVolumeDict[symbol] = sumVolume;
    Print("Symbol: " + symbol + ", Sum Volume: " + sumVolume);
    Draw.TextFixed(this, "tag_" + symbol, symbol + ": " + sumVolume, TextPosition.TopLeft);
    }


    Tried to print too but not one print statement printed anything in output window

    #2
    Hi svadukia, thanks for posting. Unfortunately, the support team will not be able to debug any code so another member of the forum would need to volunteer for this. Some things that can help are, first, check the Log tab of the Control Center for any run time errors and you can also use Visual Studio debugging to step through your code:

    https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?visual_studio_debugg ing.htm
    Kind regards,

    -ChrisL​

    Comment


      #3
      Hi svadukia...were you ever able to resolve this? I've been trying to do the same thing.

      Comment


        #4
        Hello ekpalmer,

        Welcome to the NinjaTrader forums!

        Use prints to understand the behavior.

        Below is a link to a support article that demonstrates using Print() to debug and understand behavior.


        When looping through the collection, print each element in the collection. Are the elements printed the expected values?

        Save the output from the NinjaScript Output window to a text file and include this with your next post.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        595 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        343 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        556 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        554 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X