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

Getting the daily volume MA from within a minute script

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

    Getting the daily volume MA from within a minute script

    I have been trying to do this all day, and seem to just be getting further away and confusing myself further....??!!!

    I have a strategy which is on a 5 minute timeframe.

    I need an average of the volume over e.g. the last 100 days. Only for today. That is all.

    I have tried adding a Add(PeriodType.Daily, 1). However, it doesn't seem to work right. Am I not loading sufficient historic bars? Do I need to overload a dataseries object?

    An easier way would be if I could call the VOLMA indicator, but instead of using the DataSeries from which I called it, could I not call the VOLMA indicator specifying a daily timeframe?

    Thanks in advance

    #2
    Hello antimatter,

    You're likely on the right track with making sure you have enough historical bars loaded.

    Once you add the series with this:
    Add(PeriodType.Day, 1);

    Accessing the 100 day volume average is:
    double myDouble = SMA(Volumes[1], 100)[0];

    You'll have to make sure you load enough days on your chart, and check the log tab for any error messages.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      How about if I want to put it in a strategy, and load that strategy from the control centre?

      Comment


        #4
        These principles work in an indicator or a strategy. There is a sample multiTime frame strategy built into the platform. Click Tools > Edit NinjaScript > Strategy > SampleMultiTimeFrame. Documentation is available here:
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          OK, so something like this...
          Run my strategy with Paramater "Days to Load" = 100

          Then:

          protected override void Initialize()
          {

          Add(PeriodType.Day, 1);

          .....etc


          Later....


          protected override void OnBarUpdate()
          {

          double vol = ( VOLMA(BarsArray[1], 100)[0]);


          ...etc


          Should be the 100 day MA?

          Comment


            #6
            Yes, that should work as well. To confirm the value is what you expect, print it.

            Print(vol);

            View in the Tools > output window. Additional help for debugging is available here:
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Getting there, thanks for the help....

              What I really want to do, is just run this bit of code once at the start of each code.
              I want to find the 100 day MA of the volume for the last 100 days, on this day (today).

              Then if the volume is below a certain quantity, I can kill the strategy.

              At the moment, I am running this on each bar update. Ideally, I just want to do this once, but only on the most current bar. But I want to access the latest bar from the when the script is started..... rather than cycling through all the last 100 days....???!!

              Comment


                #8
                You can custom code the conditions for calculating this indicator, but must be objective about what you want to express. If you only wanted the calculated value on historical data (data prior to starting the strategy), you could enclose the calculations in a block like this:

                if (Historical)
                {
                //indicatorCalcs here
                }
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  How would I know it was the last historical bar? e.g. the most recent data?

                  Comment


                    #10
                    You can store bar values with CurrentBar.

                    if (Historical)
                    int myBar = CurrentBar.

                    That will update myBar with the last historical, CurrentBar value.
                    Ryan M.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by chartchart, 05-19-2021, 04:14 PM
                    3 responses
                    577 views
                    1 like
                    Last Post NinjaTrader_Gaby  
                    Started by bsbisme, Yesterday, 02:08 PM
                    1 response
                    15 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by prdecast, Today, 06:07 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post prdecast  
                    Started by i019945nj, 12-14-2023, 06:41 AM
                    3 responses
                    60 views
                    0 likes
                    Last Post i019945nj  
                    Started by TraderBCL, Today, 04:38 AM
                    2 responses
                    18 views
                    0 likes
                    Last Post TraderBCL  
                    Working...
                    X