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

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​
    Chris L.NinjaTrader Customer Service

    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 xepher101, 05-10-2024, 12:19 PM
        9 responses
        112 views
        0 likes
        Last Post jeronymite  
        Started by tkaboris, Today, 07:53 PM
        0 responses
        1 view
        0 likes
        Last Post tkaboris  
        Started by JGriff5646, Yesterday, 05:47 PM
        2 responses
        21 views
        0 likes
        Last Post JGriff5646  
        Started by lezlebric, Today, 06:32 PM
        0 responses
        12 views
        0 likes
        Last Post lezlebric  
        Started by TheTechnician86, Today, 05:47 PM
        0 responses
        9 views
        0 likes
        Last Post TheTechnician86  
        Working...
        X