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 bc24fl, 08-30-2019, 01:58 PM
        3 responses
        253 views
        0 likes
        Last Post PaulMohn  
        Started by tradingnasdaqprueba, 04-09-2024, 09:52 AM
        6 responses
        26 views
        0 likes
        Last Post tradingnasdaqprueba  
        Started by PaulMohn, Today, 02:06 AM
        1 response
        3 views
        0 likes
        Last Post PaulMohn  
        Started by Mindset, Today, 01:27 AM
        0 responses
        5 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by EB Worx, 03-07-2023, 05:05 AM
        4 responses
        99 views
        1 like
        Last Post cls71
        by cls71
         
        Working...
        X