• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plot Average Daily Volme in Chart

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

    Plot Average Daily Volme in Chart

    Hi,

    I'm learning to write Ninjascrpts, These forum posts have been very helpful.

    I'm looking to plot avg daily volume in the chart. I have a 1 Min and in that I need to plot to avg daily volume for the last 30 days (multi-time frame indicator)

    Here's what I have... but it won't plot

    public class MyVOL : Indicator
    {
    #region Variables
    private int days1 = 30; // Default setting for Period

    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.OrangeRed), PlotStyle.Line, "Plot0"));
    CalculateOnBarClose = true;
    Overlay = false;
    PriceTypeSupported = false;


    // Add Daily Bars object - BarsInProgress index = 1
    Add(PeriodType.Day, Days1);
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 1 )
    return;

    // Calculate the volume average
    double average = SMA(VOL(BarsArray[1]), Days1) [0];
    double average = SMA(Volumes[1], Days1)[0];
    double average = VOLMA(BarsArray[1], Days1)[0];
    Print("The current SMA value is " + average.ToString());
    Plot0.Set(average);
    }

    ____

    I've tried different options in //Calcualte the volume average section above.

    It give me "Error on calling 'OnBarUpdate' method for indicator 'AAeSPVOL' on bar 0" error.

    Could someone please look into this.

    Thanks,
    Mike

    #2
    Hello unjha,
    Thanks for posting today.

    As I am reviewing the code sample you provided and I am seeing several errors that are beyond the error that you received. Can you send the indicator you are working on so I can further investigate?

    1. From the Control Center window select the menu File > Utilities > Export NinjaScript to open the "Export NinjaScript" dialog window
    2. Select the option "Export selected source files"
    3. Enter a user defined file name
    4. Select all of the files that you want to export and either double click on them or press the ">" button
    5. A list of all files that will be exported
    6. Press the "Export" button to export the selected files
    7. A NinjaScript Archive File (.zip) file will be created in My Documents\<NinjaTrader Folder>\bin\Custom\ExportNinjaScript

    Attach it to this forum post or you email it into platformsupport[at]ninjatrader.com

    If you email in please reference this thread http://www.ninjatrader.com/support/f...ad.php?t=73272

    I look forward to your reply.
    Alex G.NinjaTrader Customer Service

    Comment


      #3
      Hi Alex,

      Please see attached. I only get following error:

      Error on calling 'OnBarUpdate' method for indicator 'AAeSPVOL' on bar 0
      Attached Files

      Comment


        #4
        Hi - was wondering if anything else was required from me.

        Thanks.

        Comment


          #5
          Hello unjha,
          Thanks for the reply.

          When you are adding the data series using the Add() method with

          Code:
          Add(PeriodType.Day, Days1);
          you are creating a data series with Daily bars consisting of Daily bars with Days1 of days in each bar. So the error you are seeing is from a lack of data being loaded. The

          Code:
          Add(PeriodType periodType, int period)
          method uses the second parameter to set the period length. The way you have it set up will determine the length of the bars. You are using a user defined input for this value. Since you default to 5 you are loading a 5 day daily bar and will need many days of information for your indicator to process the information.

          If you wish only to add a 1 day series you can change that line of code to
          Code:
          Add(PeriodType.Day, 1)
          which will create a 1 day series.

          This will have to be changed or you will need to load enough data to process these 5 day bars.

          Please let us know if we may be of further assistance for anything NinjaTrader.
          Alex G.NinjaTrader Customer Service

          Comment


            #6
            Hi Alex,

            Essentially I'm looking for 30 day average volume in Market Analyzer. I started coding that indicator with data series to look back Daily bars to calculate average volume. My Indicator will run on close of bar every 1 minute but I need the Average average for the last 30 days.

            Is this possible to do in Market Analyzer? Is there a better/different way to do this?

            Thanks.

            Comment


              #7
              Hi Alex,

              Additionally, I tested this again and there is more than 5 days of data in the chart. I tried even with 1 day and keep getting error message.

              So there seems to be some other issue as it keeps giving me
              Error on calling 'OnBarUpdate' method for indicator 'AAeSPVOL' on bar 0: You are ac.....

              Can you please try the code on your end and let me know the results.

              Thanks,

              Comment


                #8
                Hello unjha,
                Thanks for the reply.

                I did test the code on my end and would receive the error you are seeing. You will need to add a check to make sure enough data is loaded. If not then you receive the error when enough data is not loaded.
                Code:
                if (CurrentBars[1] < Days1)
                			return;
                This will check to make sure that we have loaded enough bars on the secondary data series [1]. You will then need to make sure that you load a minimum number of days for this information to calculate.

                Depending on your data provider this could vary. For example if I do not receive weekend information and I load the past 14 days I may receive only 9 days of data depending on which day of the week I loaded. You may need to load more than 10 days to account for this weekend lack of data being provided.

                You can do this from the Data Series settings
                • Right mouse click Data Series...
                • Locate Data>Days to Load
                • Change this number to load enough days for your indicator


                Please let us know if we may be of further assistance for anything NinjaTrader.
                Alex G.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Alex,

                  Thanks for the prompt reply.

                  My data is coming from TDA. Like I said, I do have enough data loaded (10 days via the dataseries) and am looking back only 1 day in the indicator but it still won't work.

                  So, if this failed on your end, how do you make it work?

                  I believe the issue is something else in the code. I have enough data loaded in the chart.

                  Comment


                    #10
                    Hello unjha,
                    Thanks for the reply.

                    If I changed the Add(PeriodType.Day, Days1); to create a 1 day bar and changed my days loaded to 20 days or more I was able to get your indicator to plot. The
                    Code:
                    private int days1 = 10;
                    will set this to create a 10 day daily bar. Where each bar is 10 days.

                    If this is left unchanged you would need to load 10 10day bars which would required over 100 days of data to load.

                    10 days from with in the data series may not be providing 10 actual days of data. If you requested 10 days of data from today (Wednesday) that will load up to last Sunday.

                    Your provider may only provide 7 days of data. M-F and M-W. So looking back 10 days only leads to 7 days of data. This check
                    Code:
                    if (CurrentBars[1] < Days1)
                    			return;
                    will not plot until a enough days are loaded.

                    Please let us know if I can provide further clarification or further assistance.
                    Alex G.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Alex,

                      Thank you for working on this with me. Your explanation helped a lot. I understand this now i.e. I get it. It worked now.

                      Mike

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by srbdoc, Today, 11:21 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post srbdoc
                      by srbdoc
                       
                      Started by TazoTodua, Today, 11:20 AM
                      1 response
                      4 views
                      0 likes
                      Last Post NinjaTrader_Jim  
                      Started by TazoTodua, Today, 11:19 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post TazoTodua  
                      Started by sdauteuil, Today, 10:22 AM
                      3 responses
                      9 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by bc24fl, Today, 10:03 AM
                      1 response
                      11 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Working...
                      X