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

    Volume indicator

    i am trying to create an indicator that shows the volume during a set time period each day.
    this is what i am currently using

    if (ToTime(Time[0]) >= 40000
    && ToTime(Time[0])<= 51500)

    {
    VOLCL.Set(Volume[0]);
    }

    i am trying to view this on a daily chart so i can visually see the change in volume on a daily basis during a specific time.

    The above code isnt quite working, when i display the indicator on a minute chart it correctly shows the volume bars during the time range

    However when i select a daily time period no data is displayed.
    what i require is a sum of all volume bars displayed on the minute chart to be displayed as one bar on the daily chart

    Any suggestions would be helpful
    Last edited by fiddy; 12-06-2015, 01:43 AM.

    #2
    the problem with your code is that the [0] timestamp after totime refers to close of the candle (at least for calculate on bar close) so if you apply this to a daily timeframe, you either have ur if statment to be never true (bc the close of the daily candle is outside your range) or if you are having a weird closetime for your dailycandle it would just take the full daily volume. in any case it would be wrong.

    you would have to add another timeframe with

    Add(PeriodType.Minute, 1);
    and work from there.

    you would also need an additional dataseries for the sum (although you could also do it with 1 depending how you want your last/current day to be calculated) looking something like this...

    VOLsum.Set(Volume[0] + VOLsum[1] );
    ...that works within your timeperiod and without the addition afterwards...

    VOLsum.Se(VOLsum[1] );
    ...to maintain the value till the (in your case daily) maintimeframe closes. that is nessesary bc dataseries points that arent called at a specfic bar would be set to 0 (i think) for that bar and that would fk up your sum.

    for your daily timeframe candle update you would just need to set your regular dataseries to the value of your volsum dataseries like this.
    VOLCL.Set(VOLsum[0])
    in the end would need to reset the VOLsum back to 0 for the next day to come, so u dont add multiple days together.

    more information regarding multitimeframe stuff here


    hope that helps
    Last edited by BigRo; 12-06-2015, 10:29 AM.

    Comment


      #3
      Thanks BigRo.

      Hello fiddy,

      If you require further clarification on how to proceed or if you have any questions at all, please let us know.
      Michael M.NinjaTrader Quality Assurance

      Comment


        #4
        hey Micahael, thanks also BigRo , very generous to assist others with less knowledge.

        I do not quite follow the hows these should/would work. can you please provide further clarification on this part

        VOLsum.Set(Volume[0] + VOLsum[1] );
        VOLCL.Set(VOLsum[0])
        VOLCL.Set(VOLsum[0])

        Comment


          #5
          Ok this will a bit of a stretch, but whatever.

          Originally posted by fiddy View Post
          VOLsum.Set(Volume[0] + VOLsum[1] );
          VOLCL.Set(VOLsum[0]) - im assuming this was meant to be VOLsum.Set(VOLsum[1] )
          VOLCL.Set(VOLsum[0])
          1) is just a dataseries for the sum, that should do the work inside ur timeperiod so 4-5:15

          for the first candle where the timeperiod is true(4:00 candle) it sets the VOLsum to the Volume[0](lets just say its 100) of the current(4:00) candle and adds the VOLsum[1] so the previous candle(3:99), which should be 0 at that point.

          so the result would be just the volume of the first minute candle, so 100.

          for the second candle(4:01) it now adds together again the Volume[0](lets just say its 150) of the current(4:01) candle with the VOLsum[1] of the previous candle(4:00)(which was 100).

          the result would be 250.

          and so on and so on

          that way we will add together all the volumevalues of the specific candles within the 4-515 timeperiod.

          2) after that timeperiod we now have to maintain the sum (we came up with) till the close of the dailytimeframe, where we wanna use it to plot it.

          thats why we have to use VOLsum.Set(VOLsum[1]) after 515. without the Volume[0] since we dont wanna include the volume of those candles in the sum. but we still wanna maintain the value of the sum.

          that is nessesary bc a Dataseries that isnt updated on every specfic bar would be set to 0 for all bars that arent included - and we dont want that.

          3) once the dailytimeframe closes we can now use the dataseries of the Plot to assign the sum to it. i used your dataseriesname for that, so
          VOLCL.Set(VOLsum[0])
          but generally if you are using the primary plot (or you are only using 1 plot at all) u can simply refer to the plot with "Value.Set" - doesnt matter what the name is

          so
          Value.Set(VOLsum[0]);



          the problem is now, to put all of that together on a multitimeframe setup. this can become a little bit tricky if you dont know how this works. Since we have to make sure everything is done on the right candleupdates. further dataseries can behave a bit strange on multitimeframe setups

          for example, you wouldnt be able to use VOLsum[1] as simply as u would for a one timeframe indicator. mainly because VOLsum[1] has to refer to the secondary (minute) timeframe.
          in order to do that, we have to bind the Dataseries VOLsum to the secondary timeframe which is done using (BarsArray[1]) - 1 referring to the secondary timeframe(its not timestamp here).
          But since we cant use BarsArray while we are setting up the dataseries that easily, we instead have to use an arbitrary indicator (SMA for example) to bind the dataseries to it. that would need to be done in the OnBarUpdate section and ofc before everything else is done, so we already have the dataseries setup, when we need to use it.

          it would look something like this
          Code:
          if (VOLsum == null){
                          VOLsum = new DataSeries(SMA(BarsArray[1], 50));
          }
          after we have done that we can just simply set the dataseries to 0.1(or any other small value) and use it from there. but we have to set it to 0.1 before, bc currently it still includes a SMA value, which we dont want and again would mess up our summing progress. also we cant use 0 because then the if statement (VOLsum == null) would be true and we would do the same thing all over again.

          Because i was bored, i already did the programming of that indicator. it should work as u want it to, if you add it to a daily timeframe.
          However i only did a mediocre check, to ensure that, so u might wanna doublecheck that.
          further i think my post will become a lot clearer once u see everything in place. i also included the .cs of that indicator if you wanna use that instead of copypaste. just put in in your indicator folder and compile

          EDIT - SIDENOTE: this indicator only works properly if your daily candle close is outside of the range you are looking at (which should be self-explanatory, but still)

          Code:
          namespace NinjaTrader.Indicator
          {
          
              [Description("")]
              public class VolumeRange : Indicator
              {
                  #region Variables
                  private DataSeries VOLsum;
                  private int starthour = 4;
                  private int    startminute    = 0;
                  private int endhour = 5;
                  private int endminute = 15;
                  private bool additionprogress = false;
                  
                  #endregion
          
          
                  protected override void Initialize()
                  {
                      Add(new Plot(Color.Green, "VolumeSet"));
                      Overlay                =     false;
                      BarsRequired         =     1;
                      Add(PeriodType.Minute, 1);
                      CalculateOnBarClose = true;
                  }
          
           
                  protected override void OnBarUpdate()
                  {
                      if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
                              return;
                      if (VOLsum == null){
                          VOLsum = new DataSeries(SMA(BarsArray[1], 50));
                      }
                      if (BarsInProgress == 1){
                          
                          if (ToTime(Time[0]) >= ToTime(starthour, startminute, 0) && ToTime(Time[0]) <= ToTime(endhour, endminute, 0)){
                              VOLsum.Set(Volume[0] + VOLsum[1]);
                              additionprogress = true;
                          }
                          else {
                              VOLsum.Set(VOLsum[1]);
                          }
                          if (additionprogress == false)
                              VOLsum.Set(0.1);
                      }
                      if (BarsInProgress == 0 && additionprogress){
                          Value.Set(VOLsum[0]);
                          additionprogress = false;
                      }
                  }
          
                  #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 StartingHour
                  {
                      get { return starthour; }
                      set { starthour = value; }
                  }
                  [GridCategory("Timeframe"), Description("")]
                  public int StartingMinute
                  {
                      get { return startminute; }
                      set { startminute = value; }
                  }
                  [GridCategory("Timeframe"), Description("")]
                  public int EndingHour
                  {
                      get { return endhour; }
                      set { endhour = value; }
                  }
                  [GridCategory("Timeframe"), Description("")]
                  public int EndingMinute
                  {
                      get { return endminute; }
                      set { endminute = value; }
                  }
                  [Browsable(false)]
                  public DataSeries Default
                  {
                      get { return Values[0]; }
                  }        
          
          
                  #endregion
          Attached Files
          Last edited by BigRo; 12-07-2015, 05:45 AM.

          Comment


            #6
            thanks heaps for you help BigRo

            i dont think it is working correctly. when i put on a daily chart it displayed a line that continially increased, as if cumulative added the volume from each day to each other. rather than displaying the individual days
            also it seemed to be displaying just the SMA line rather than bars of each individual days

            any further assistance you could provide would be great. ill keep trying to work it out myself in meantime also. if i have any luck ill let u know

            Comment


              #7
              uh. ur that new to this? ok

              first, this error with an increasing line would occur if the close of your dailytimeframe is inside of your range.the script has basicly no chance of setting the value back to 0.1 because its already tryin to sum up the values again. if you wanna sum up values right before and beyond the daily candle close, the code would need to be changed.

              but

              can you tell me to what instrument ur tryin to add this and what the daily close time is - u can see this by looking at the timestamp of any candle in the databox(CTRL+D). and further if your "startinghour" "endinghour" settings in your indicator window are setup correctly?

              also in order to give it the "normal look" you would need to go to ur indicator settings down to "plots" click on the "+" and change "line" to "bar" and also width "1" to "2".

              here a picture of me adding the indcator to the ES daily. 23:15 candle close with your range (so 4:00 to 5:15) applied

              looks perfectly fine to me
              Attached Files
              Last edited by BigRo; 12-07-2015, 06:48 AM.

              Comment


                #8
                startinghour 4 startingminute 0 endinghour 5 endingminute 15

                would represet ur setting that u stated in the first post
                if (ToTime(Time[0]) >= 40000
                && ToTime(Time[0])<= 51500)
                also. now that i know that ur fairly new to this. are u aware that those settings would be 4 am to 5:15 am. so rather irrelevant times in most markets (ofc it all depends on what timezone u are running ninjatrader on)
                is that intentional?

                just in case its not:
                4 pm to 5.15 pm would be startinghour 16 startingminute 0 endinghour 17 endingminute 15
                if its that what u were looking for.

                Comment


                  #9
                  thanks BigRo

                  im trying to use this for US stocks
                  the ending hour for US stocks for me is 4.00am to 5.00am

                  attached is how the it looks to me
                  Attached Files

                  Comment


                    #10
                    well yeah, like i said. with that close the code wont reset. so the close is 5 am?.

                    cant u just use the 4:00 am to 4:59 range then? do u really need the last 16 minutes?

                    if you really them, i can later make the changes. but i would really need the exact close time.

                    Comment


                      #11
                      if the Close however is 4:00 you can just set the range to 4:01-5:15 and it should fix the problem.

                      Comment


                        #12
                        i tried to use 400 to 459 but this didnt work either - i have attached the chart
                        this may be because the end time changes from 4am to 5am at start of dec due to daylight savings changing in the US then
                        Attached Files

                        Comment


                          #13
                          ok, but shouldnt you be looking at the range relative to the close. so at 4am close from 4:00-5:15 and at 5am close from 5:00to6:15 or something like that
                          because that would make things alot easier.

                          its best to clarify one time again (with the new information what you wanna do)

                          if the close is 5am. what range of volumes do you wanna sum up
                          if the close is 4am. what range of volumes do you wanna sum up then
                          Last edited by BigRo; 12-07-2015, 08:03 AM.

                          Comment


                            #14
                            i always want to sum up the last hour
                            if the close is 5am: 0400 - 0500
                            if the close is 4am: 0300 - 0400

                            Comment


                              #15
                              ok. i will make the needed changes when i come back in ~1 hour

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by f.saeidi, Today, 08:01 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post f.saeidi  
                              Started by Rapine Heihei, Today, 07:51 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post Rapine Heihei  
                              Started by frslvr, 04-11-2024, 07:26 AM
                              5 responses
                              96 views
                              1 like
                              Last Post caryc123  
                              Started by algospoke, 04-17-2024, 06:40 PM
                              6 responses
                              49 views
                              0 likes
                              Last Post algospoke  
                              Started by arvidvanstaey, Today, 02:19 PM
                              4 responses
                              11 views
                              0 likes
                              Last Post arvidvanstaey  
                              Working...
                              X