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

Volume indicator

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

    #16
    Hereyou go. I did it differently this time bc it was really gettin frustrateting the other way. I checked it, and it should work like a charm.

    the way it works is. If ur dailytimeframe closes it will then add together the last X (60 in your case) minute bars.

    i hope that should finally be what ur looking for. .cs included

    EDIT: Note that u wont get any intradayupdates for that days volume. only after the close of the daily you will get the update for that day.

    NOTE: as u can see, the way you present what you wanna do actually makes a great diffrence how you(or anybody) will tackle the problem of gettin it done in code. if you had provided all the information in the first place it wouldve been much easier (and less timeconsuming) to help you. so try next time and always to be as specific as possible when tryin to describe what u actually want or need the indicator to do.


    if you find an error or something is not the way u want it to, still feel free to ask tho
    Code:
    using System.Collections.Generic;
    using System.Linq;
    
    namespace NinjaTrader.Indicator
    {
    
        [Description("")]
        public class VolumeSum : Indicator
        {
            #region Variables
            private List<double> volumelist = new List<double>();
            private int period = 60;
            
            #endregion
    
    
            protected override void Initialize()
            {
                Add(new Plot(Color.Green, "VolumeRange"));
                Overlay                =     false;
                BarsRequired         =     1;
                Add(PeriodType.Minute, 1);
                CalculateOnBarClose = true;
            }
    
     
            protected override void OnBarUpdate()
            {
                if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
                        return;
                if (BarsInProgress == 1){
                    volumelist.Add(Volume[0]);
                    }
                }
                if (BarsInProgress == 0){
                    double volumesum = volumelist.Skip(volumelist.Count-period).Take(period).Sum();
                    Value.Set(volumesum);
                }
            }
    
            #region Properties
            [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove        
            [GridCategory("Timeframe"), Description("")]
            public int LookBackPeriod
            {
                get { return period; }
                set { period = value; }
            }
            [Browsable(false)]
            public DataSeries Default
            {
                get { return Values[0]; }
            }        
    
    
            #endregion
        }
    }
    Attached Files
    Last edited by BigRo; 12-07-2015, 10:42 AM.

    Comment


      #17
      Bigro, thanks again for your help with this.

      based on my initial trials today it seems that the indicator sum is correct for the most recent trading
      however for lprevious trading days i have found small discrepancies between the value give in the indicator and the actual figure if you look at the last 60min bar or add the last two 30 mins bar. id be interested to know if you had this occur also? is there a logical explanation for this based on the coding?

      Comment


        #18
        Well like i said. the way it works is, whenever there is an update on the minute bar the volume of the last candle gets listed. when we then get an update on the dailybar it just takes the sum of the last X listentries. this is done by this line

        volumelist.Skip(volumelist.Count-period).Take(period).Sum(); Value.Set(volumesum);
        so for every minute bar the volume gets listed and the count of the list goes up +1, so the count is 1 at the very first minute candle 2 at the next and so on.

        the command
        listname.Take(int).Sum()

        takes the first X entries of the list and sums them up. so that would be wrong. to take the last X entries you would first need to skip the amount of listentries - X and then take the sum of the next X listentries. this is how this command works.

        so if you have 10 values listed and want to add the first 2 you can use.

        listname.Take(2).Sum()

        if however you want to add the last 2 (so 9 and 10) you would need to skip the first 8, so

        listname.Skip(10-2).Take(2).Sum()


        this is how this all works. the debugging is your job now. i dont have the time for that. hope that helps finding the problem (if you think the problem is big enough that it need fix).

        ofc u can always ask someone else for help or maybe open a new thread including a more specific description of the problem, bc this is kinda blown up already.

        Comment


          #19
          hey BigRo

          how can i print out the elements of the list of the take list given by the below code?

          volumelist.Skip(volumelist.Count - period).Take(period)

          Comment


            #20
            you could use something like that to figure out whats happening
            that will howyou what volumes are added to the list and when, and when the summing progress happens.
            Code:
                        if (BarsInProgress == 1){
                            volumelist.Add(Volume[0]);
                            Print(Time[0].ToString()+ "---" + Volume[0]);
                        }
                        if (BarsInProgress == 0){
                            double volumesum = volumelist.Skip(volumelist.Count-period).Take(period).Sum();
                            Value.Set(volumesum);
                            Print("Take sum at --- " + Time[0]);
                        }
            if you want direct access to the listed values you can use Print(volumelist[volumelist.Count-1); for the most recent listentry and 2,3,4 for the second, third ... most recent. but that wont provide more information as my code i think.

            if you wanna output all X listentries at a time i suggest u look into this thread

            but i dont feel the need to do that for debugging purposes. the error most likly lays in some weird time isses regarding dailyclose and minute close and or volume value diffrences.

            just accept that fact that its a bit of a painfull progess to check it and there might not even be a fix for it. however if you wanna start i suggest you add together the last 60 entries b4 "take sum" is printed and compare it to the indicator value you get on the daily chart. also compare those to the originalvolume values on the minute chart. over that period. important here are especially the timestamps. so is the 4:00 candle included, is the 3:59 candle included and so on. is everydays last minutebar included.
            there are potential spots for errors.
            Last edited by BigRo; 12-10-2015, 07:58 AM.

            Comment


              #21
              hey BigRo, i found the issue
              the indicator is not grabbing the last minute bar when the day finishes
              As such it is missing the volume from the last minute bar of the session, but including an additional bar at the start of the period.

              Comment


                #22
                ok cool. did you fix it?

                if you need me to help with the fix can u provide a few copys of you output window prints to show me a bit how and where u found that error so i can understand it a bit better. bc i dont have stockcharts so cant reproduce that.

                Comment


                  #23
                  i trying to fix it atm. havent solved it yet. if u have any suggestions would be great.

                  ive attached the output window of the print i did,

                  it shows each of the 60 components of the indicator for 10/12 which sum to 6031k - i have attached a daily chart to show this corresponds to the indicator value

                  you can see in the output that last volume included (count1) is 431k.
                  This aligns with the " second last minute" . see chart

                  The volume does not include the last minute volume of 669k. as shown in the chart "last minute vol" chart

                  The output window count 60 has volume of 79327 which aligns with the attached chart "1 min prior to period"
                  Attached Files

                  Comment


                    #24
                    ah, ok so i misunderstood your post. the error is basicly if 5:00 is the close it sums from 3:59 till 4:59 rather than 4:00 till 5:00 right?

                    Comment


                      #25
                      yes that is correct. it doesnt include the very last minute

                      Comment


                        #26
                        ok that ofc is awkward, have u tried something like this. so basicly we wait for the next 1 min update after the daily close to take the sum. at least thats how i want it to work
                        dont forget to add a private bool waitforupdate=false; to the variables

                        Code:
                                protected override void OnBarUpdate()
                                {
                                    if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
                                            return;
                                    if (BarsInProgress == 1){
                                        volumelist.Add(Volume[0]);
                                        if (waitforupdate){
                                            double volumesum = volumelist.Skip(volumelist.Count-period).Take(period).Sum();
                                            Value.Set(volumesum);
                                            waitforupdate=false;
                                        }
                                    }
                                    if (BarsInProgress == 0){
                                        waitforupdate= true;
                                    }
                                }

                        Comment


                          #27
                          thanks has worked. thanks for your help and patience

                          Comment


                            #28
                            no problemo, was fun to figure it out after all

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by inanazsocial, Today, 01:15 AM
                            1 response
                            5 views
                            0 likes
                            Last Post NinjaTrader_Jason  
                            Started by rocketman7, Today, 02:12 AM
                            0 responses
                            10 views
                            0 likes
                            Last Post rocketman7  
                            Started by dustydbayer, Today, 01:59 AM
                            0 responses
                            1 view
                            0 likes
                            Last Post dustydbayer  
                            Started by trilliantrader, 04-18-2024, 08:16 AM
                            5 responses
                            23 views
                            0 likes
                            Last Post trilliantrader  
                            Started by Davidtowleii, Today, 12:15 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post Davidtowleii  
                            Working...
                            X