Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Referencing Volume Question

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

    Referencing Volume Question

    Hello,

    I want a solution to print the volume of the last 5 bars and the average vol. of these Bars in the Top Right Corner of the Chart.
    This was my solution. But the volume Numbers are not right. So there is a error in referencing the Volume and Displaying the Numbers of the Chart.
    Maybe you have some suggestions?

    Kind Regards, Nick

    PHP Code:
      #region Variables
    
            private TextPosition tpos    = TextPosition.BottomRight;
            private Font textFont        = new Font("Arial", 12, FontStyle.Regular);
            private Color textColor        = Color.DarkGray;
            private Color outlineColor    = Color.Transparent;
            private Color areaColor        = Color.Black;
            private int opacity            = 5;
    
            private double AvFBV;
    
            #endregion
    
            private string versionInfo = "PrintVolumeNumbers_V3_NT7";
    
            protected override void Initialize()
            {
                Overlay                = true;
                CalculateOnBarClose    = true;
                DrawOnPricePanel    = true;
            }
    
    
            protected override void OnStartUp ()
            {
    
            }
    
    
            protected override void OnBarUpdate()
            {
                AvFBV = ((Volume[1] + Volume[2] + Volume[3] + Volume[4] + Volume[5]) / 5);
                //DrawTextFixed("tt", str, tpos, textColor, textFont, outlineColor, areaColor, opacity);    
                DrawTextFixed ("testa",     "Bar -5:\t\t",                             TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                DrawTextFixed ("testa1",     Volume[5].ToString(),                     TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                DrawTextFixed ("testb",     "\nBar -4:\t\t",                         TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                DrawTextFixed ("testb1",    "\n"+Volume[4].ToString(),                 TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );        
                   DrawTextFixed ("testc",     "\n\nBar -3:\t\t",                         TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                DrawTextFixed ("testc1",    "\n\n"+ Volume[3].ToString(),             TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );                                    
                DrawTextFixed ("testd",     "\n\n\nBar -2:\t\t",                     TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                DrawTextFixed ("testd1",    "\n\n\n"+ Volume[2].ToString(),         TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                DrawTextFixed ("teste",     "\n\n\n\nBar -1:\t\t",                     TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                DrawTextFixed ("teste1",    "\n\n\n\n"+ Volume[1].ToString(),         TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                DrawTextFixed ("testf",     "\n\n\n\n\nTest  \t\t",                 TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                //DrawTextFixed ("testf1",    "\n\n\n\n\n"+ Volume[0].ToString(),     TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                DrawTextFixed ("teste",     "\n\n\n\n\n\nAVG:\t\t",                 TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                DrawTextFixed ("teste1",    "\n\n\n\n\n\n"+ AvFBV.ToString(),         TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
            } 
    

    #2
    Hi futurenick, thanks for your post.

    You are accessing the volume values correctly. Place a current bar check at the beginning of OnBarUpdate to ensure there are at least 5 volume slots to check e.g.:
    Code:
    OnBarUpdate()
    {
        if(CurrentBar < 5) return;
    }
    Please let me know if I can assist any further.
    Last edited by NinjaTrader_ChrisL; 02-25-2020, 11:22 AM.

    Comment


      #3
      Hi Chris, Thank you very much for your help. I integrated your suggestion and it looks much better. But look on the screenshot. Bar -1 is not there. It is a litte bit weird but one more idea is needed.

      Thank you, Nick

      Click image for larger version

Name:	2020-02-25_183300.png
Views:	353
Size:	37.2 KB
ID:	1088365


      PHP Code:
      namespace NinjaTrader.Indicator
      {
          [Description("Plots the Volume of the last Five Bars and the Average Volume of these Bars in the Top Right Corner of the Chart")]
          public class PrintVolumeNumbers_V3_NT7 : Indicator
          {
              #region Variables
      
              private TextPosition tpos    = TextPosition.BottomRight;
              private Font textFont        = new Font("Arial", 12, FontStyle.Regular);
              private Color textColor        = Color.DarkGray;
              private Color outlineColor    = Color.Transparent;
              private Color areaColor        = Color.Black;
              private int opacity            = 5;
      
              private double AvFBV;
      
              #endregion
      
              private string versionInfo = "PrintVolumeNumbers_V3_NT7";
      
              protected override void Initialize()
              {
                  Overlay                = true;
                  CalculateOnBarClose    = true;
                  DrawOnPricePanel    = true;
              }
      
      
              protected override void OnStartUp ()
              {
      
              }
      
      
              protected override void OnBarUpdate()
              {
                  if(CurrentBar < 5) return;
      
                  AvFBV = ((Volume[1] + Volume[2] + Volume[3] + Volume[4] + Volume[5]) / 5);
                  //DrawTextFixed("tt", str, tpos, textColor, textFont, outlineColor, areaColor, opacity);    
      
                  // Bars 1 to 5
                  DrawTextFixed ("testa",     "Bar -5:\t\t",                             TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                  DrawTextFixed ("testa1",     Volume[5].ToString(),                     TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                  DrawTextFixed ("testb",     "\nBar -4:\t\t",                         TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                  DrawTextFixed ("testb1",    "\n"+Volume[4].ToString(),                 TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );        
                     DrawTextFixed ("testc",     "\n\nBar -3:\t\t",                         TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                  DrawTextFixed ("testc1",    "\n\n"+ Volume[3].ToString(),             TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );                                    
                  DrawTextFixed ("testd",     "\n\n\nBar -2:\t\t",                     TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                  DrawTextFixed ("testd1",    "\n\n\n"+ Volume[2].ToString(),         TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                  DrawTextFixed ("teste",     "\n\n\n\nBar -1:\t\t",                     TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                  DrawTextFixed ("teste1",    "\n\n\n\n"+ Volume[1].ToString(),         TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
      
                  // empty line
                  DrawTextFixed ("testf",     "  \t\t",                                 TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                  // Average Volume
                  DrawTextFixed ("teste",     "\n\n\n\n\n\nAVG:\t\t",                 TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                  DrawTextFixed ("teste1",    "\n\n\n\n\n\n"+ AvFBV.ToString(),         TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
              } 
      

      Comment


        #4
        Hi futurenick, thanks for your reply.

        It looks like you have identical tag names "teste1". Make sure all of the tag names are unique and you should get a text print out.

        Best regards.

        Comment


          #5
          Hi Chris, you have a sharp eye ;-) Thank You.

          I rearranged everything ab bit and included the Spread of the Bars. Do you know a way to format the strings a bit better, like Rows maybe?

          Click image for larger version

Name:	2020-02-25_200853.png
Views:	392
Size:	7.7 KB
ID:	1088388


          PHP Code:
          namespace NinjaTrader.Indicator
          {
              [Description("Plots the Volume of the last Five Bars and the Average Volume of these Bars in the Top Right Corner of the Chart")]
              public class PrintVolumeNumbers_V3_NT7 : Indicator
              {
                  #region Variables
          
                  private TextPosition tpos    = TextPosition.BottomRight;
                  private Font textFont        = new Font("Arial", 12, FontStyle.Regular);
                  private Font textFontBold        = new Font("Arial", 12, FontStyle.Bold);
                  private Color textColor        = Color.DarkGray;
                  private Color outlineColor    = Color.Transparent;
                  private Color areaColor        = Color.Black;
                  private int opacity            = 5;
          
                  private double AverageVolume;
                  private double AverageSpread;
                  private string String1;
                  private string String2;
                  private string String3;
                  private string String4;
                  private string String5;
                  private string StringAverage;
          
                  #endregion
          
                  private string versionInfo = "PrintVolumeNumbers_V3_NT7";
          
                  protected override void Initialize()
                  {
                      Overlay                = true;
                      CalculateOnBarClose    = true;
                      DrawOnPricePanel    = true;
                  }
          
          
                  protected override void OnStartUp ()
                  {
          
                  }
          
          
                  protected override void OnBarUpdate()
                  {
                      if(CurrentBar < 5) return;
          
                      // Average Calculation
                      AverageVolume = ((Volume[1] + Volume[2] + Volume[3] + Volume[4] + Volume[5]) / 5);
                      AverageSpread = (((High[1]-Close[1]) + (High[2]-Close[2]) + (High[3]-Close[3]) + (High[4]-Close[4]) + (High[5]-Close[5])) / 5);
                      StringAverage = ("\n\n\n\n\n\nAVR:     " + AverageVolume.ToString() + "      " + AverageSpread.ToString());    
          
          
                      String5 = ("Bar -5:     " + Volume[5].ToString() + "      " + (High[5]-Close[5]).ToString());
                      String4 = ("\nBar -4:     " + Volume[4].ToString() + "      " + (High[4]-Close[4]).ToString());
                      String3 = ("\n\nBar -3:     " + Volume[3].ToString() + "      " + (High[3]-Close[3]).ToString());
                      String2 = ("\n\n\nBar -2:     " + Volume[2].ToString() + "      " + (High[2]-Close[2]).ToString());
                      String1 = ("\n\n\n\nBar -1:     " + Volume[1].ToString() + "      " + (High[1]-Close[1]).ToString());
          
          
                      //DrawTextFixed("tt", str, tpos, textColor, textFont, outlineColor, areaColor, opacity);
          
                      //Drawing Text Bars 1 to 5
                      DrawTextFixed ("testa",     " \t\t",                             TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                      DrawTextFixed ("testa1",     String5,                             TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                      DrawTextFixed ("testa2",     String4,                             TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                      DrawTextFixed ("testa3",     String3,                             TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                      DrawTextFixed ("testa4",     String2,                             TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
                      DrawTextFixed ("testa5",     String1,                             TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
          
                      // empty line
                      DrawTextFixed ("testa6",     "\t",                                     TextPosition.TopRight, textColor, textFont, outlineColor, areaColor,opacity );
          
                      // Average Volume
                      DrawTextFixed ("testa7",    StringAverage,         TextPosition.TopRight, textColor, textFontBold, outlineColor, areaColor,opacity );
                  } 
          

          Comment


            #6
            Hello futurenick,

            Thanks for your post.

            "\t" can be used for tabbing in a string, but if you want more direct control over where the text is drawn, custom plotting can be used to do so. This is goes beyond the level of support that we provide for NinjaTrader 7, but you can reference the CustomPlotSample indicator and the Pivots indicator for further direction on how custom drawing can be done in NinjaTrader 7. GDI+ graphics would be used here.

            Please let us know if you have any questions.

            Comment


              #7
              Hello Ninjatrader, is there a possibility to check the script performance or the chart lag in NT7?

              Comment


                #8
                Hi futurenick, thanks for your post.

                Not really anything in NinjaTrader 7 that can be used for performance profiling. In NinjaTrader 8 we introduced the NinjaScript utilization monitor where a print out of the total resource time of all NinjaScript objects is displayed:



                Kind regards.

                -ChrisL

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                587 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                342 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                103 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                555 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                552 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X