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 to plot total traded lot

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

    Volume indicator to plot total traded lot

    Volume indicator to plot total traded lot instead of total traded volume. how do i divide total traded volume with lot size as my broker gives total volume ( Lot size * total traded lots = total volume)
    How do i divide incoming volume with lot size to display total traded lots in volume panel ?
    ( for example : total traded volume at 1090 price is 5250 now i want to divide 5250 by lot size, lot size is 75 so i want to divide volume by 75 i.e 5250/75 = 70 lot, i want to display 70 in the volume panel)

    Thanks

    #2
    Hello Trader9,

    Thank you for the post.

    I am not certain I understand what specifically you are asking help with here. Are you asking how to do division in C# with the volume you are observing in a script?

    Code:
    double a = 5250; 
    double b = 75; 
    double c = a / b;
    Are you asking how to plot a value or do you already have an indicator plotting the volume as you noted?

    I see you have a second post with a very similar question, as the question is the same I will post here and just link to this post from that thread.

    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      kindly look the image. Click image for larger version

Name:	Volume panel.png
Views:	471
Size:	53.8 KB
ID:	1065430

      Comment


        #4
        Hello trader9,

        I understand the question from the original post, however I am not sure what part you are having difficulty with. Are you asking how to write the code for division in C#?

        To do what you are asking you would need to make an indicator to calculate your custom value, have you created an indicator at this point?

        If you have made an indicator, where in the code are you having trouble with the division you are asking about?

        The division syntax would look like I had shown in the last post:

        Code:
        double a = 5250;
        double b = 75;
        double c = a / b;
        The 5250 value would instead be the Volume value you are want to divide. if you have not yet created an indicator you could duplicate the VOL indicator as a starting point as that already has a plot and shows how to access the Volume.

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          I don't know where to make changes in Vol Indicator. can you guide me where i should put those lines.

          Comment


            #6
            can you help to make new Vol indicator which divide each quantity by 75 and plot in lower panel. ?

            Comment


              #7
              Hello trader9,

              Thank you for clarifying.

              I would suggest to first go through the NinjaScript editor webinar we offer to familiarize yourself with compiling and writing code in NinjaTrader. https://youtu.be/BA0W4ECyVdc

              Once you feel comfortable opening and using the editor, you can duplicate the VOL indicator. To duplicate an existing indicator, you can open the indicators code in the NinjaScript editor and then Right click -> save as. This makes a duplicate where you can experiment with changes. When making changes in the file, press F5 to save/compile. This also means in a chart you will need to press F5 to reload the script or you need re apply it to the chart to see changes.

              The volume indicator has 1 line of OnBarUpdate code which looks like the following:
              Code:
              Value[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];
              This is where you can change the calculation being done, if you wanted to do a division with the volume you could do that here. The VOL also already has a plot which is the Value[0] syntax. The value is being assigned to the Plot which is then shown on the chart. You can read more about plotting here:

              https://ninjatrader.com/support/help...ghtsub=addplot


              I would suggest trying to first duplicate the indicator and make sure you can see it in the list and apply it without errors. Next try editing the line for the calculation. If you are unable to edit the line correctly or have questions surrounding something specific there, please provide an example of what you tried and any errors you had seen so we can work through them.

              The syntax I had previously provided would be one way to do a division in C#, as noted you would replace the 5250 value with your volume value. The "c" variable in that sample is the result of the division. This can also be done inline or Volume[0] / 75.

              For more information about doing calculations in C#, I would suggest researching "C# mathematics" (google) for further examples. Here is one public resource that shows some division examples: https://www.ict.social/csharp/basics...t-math-library


              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                i have made some changes but can't plot anything please have a look.



                // This namespace holds indicators in this folder and is required. Do not change it.
                namespace NinjaTrader.NinjaScript.Indicators
                {
                /// <summary>
                /// Volume is simply the number of shares (or contracts) traded during a specified time frame (e.g. hour, day, week, month, etc).
                /// </summary>
                public class vol2 : Indicator
                {
                protected override void OnStateChange()
                {
                if (State == State.SetDefaults)
                {
                Description = Custom.Resource.NinjaScriptIndicatorDescriptionVOL ;
                Name = Custom.Resource.NinjaScriptIndicatorNameVOL;
                BarsRequiredToPlot = 0;
                Calculate = Calculate.OnEachTick;
                DrawOnPricePanel = false;
                IsSuspendedWhileInactive = true;

                double c = Volume[0]/75;

                AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Bar, Custom.Resource.VOLVolume);
                AddLine(Brushes.DarkGray, 0, Custom.Resource.NinjaScriptIndicatorZeroLine);
                }
                else if (State == State.Historical)
                {
                if (Calculate == Calculate.OnPriceChange)
                {
                Draw.TextFixed(this, "NinjaScriptInfo", string.Format(Custom.Resource.NinjaScriptOnPriceCh angeError, Name), TextPosition.BottomRight);
                Log(string.Format(Custom.Resource.NinjaScriptOnPri ceChangeError, Name), LogLevel.Error);
                }
                }
                }

                protected override void OnBarUpdate()
                {
                Value[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]/75;
                }
                }
                }

                Comment


                  #9
                  i request you to please do required changes, i am sure you can do that easily, i tried but if you can help that will be better.

                  Comment


                    #10
                    Hello trader9,

                    Thank you for the reply.

                    While our support is not able to provide custom development/debugging services we can provide educational information so that you can do this yourself. If you prefer to have something developed for you, I can have someone follow up with information on third party addon developers and how to find them. This area of the forum is otherwise for discussing custom development that you are doing yourself.

                    We can walk through the changes if you are unsure about some part I would just need more details about what you are unclear on.

                    In what you provided, you may not be assigning a value, Try changing the following line:

                    Code:
                    Value[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]/75;
                    to

                    Code:
                    Value[0] = Volume[0]/75;
                    Recompile and then re load the indicator. Does this display anything or do you see an error in the control center log?


                    You may be seeing an error, after further inspection I see you added more syntax than I had suggested. Please remove the following line:

                    Code:
                    double c = Volume[0]/75;
                    I look forward to being of further assistance.
                    Last edited by NinjaTrader_Jesse; 07-26-2019, 12:55 PM.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      ok i have made some changes but can't plot anything please have a look. Also i can't see it in indicator list, although it complies well without any error. where am i making mistake.?



                      // This namespace holds indicators in this folder and is required. Do not change it.
                      namespace NinjaTrader.NinjaScript.Indicators
                      {
                      /// <summary>
                      /// Volume is simply the number of shares (or contracts) traded during a specified time frame (e.g. hour, day, week, month, etc).
                      /// </summary>
                      public class vol2 : Indicator
                      {
                      protected override void OnStateChange()
                      {
                      if (State == State.SetDefaults)
                      {
                      Description = Custom.Resource.NinjaScriptIndicatorDescriptionVOL ;
                      Name = Custom.Resource.NinjaScriptIndicatorNameVOL;
                      BarsRequiredToPlot = 0;
                      Calculate = Calculate.OnEachTick;
                      DrawOnPricePanel = false;
                      IsSuspendedWhileInactive = true;

                      double c = Volume[0]/75;

                      AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Bar, Custom.Resource.VOLVolume);
                      AddLine(Brushes.DarkGray, 0, Custom.Resource.NinjaScriptIndicatorZeroLine);
                      }
                      else if (State == State.Historical)
                      {
                      if (Calculate == Calculate.OnPriceChange)
                      {
                      Draw.TextFixed(this, "NinjaScriptInfo", string.Format(Custom.Resource.NinjaScriptOnPriceCh angeError, Name), TextPosition.BottomRight);
                      Log(string.Format(Custom.Resource.NinjaScriptOnPri ceChangeError, Name), LogLevel.Error);
                      }
                      }
                      }

                      protected override void OnBarUpdate()
                      {
                      Value[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]/75;
                      }
                      }
                      }

                      Comment


                        #12
                        Thank you for the reply, it plots as expected. But i have given name vol2 to the indicator but in indicator window it shows two indicator with same name Vol. why am i not getting vol2 as name in indicator window.?

                        Comment


                          #13
                          ok it's done. Thank you for the support jesse.

                          Comment


                            #14
                            Hello trader9,

                            Thank you for posting the update, I am glad you were able to resolve the indicator.

                            Just to be complete, if you are still having trouble with the name please check that the script has the name you picked set:

                            Code:
                            Name = "My Custom Indicator";
                            Please let me know if I may be of additional assistance.
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              On a similar note, does anyone know of an indicator that can plot total volume divided by total trades? Thanks in advance.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by GussJ, 03-04-2020, 03:11 PM
                              11 responses
                              3,229 views
                              0 likes
                              Last Post xiinteractive  
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              14 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              441 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post FAQtrader  
                              Working...
                              X