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

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"12FontStyle.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.TopRighttextColortextFontoutlineColorareaColor,opacity );
                
    DrawTextFixed ("testa1",     Volume[5].ToString(),                     TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                
    DrawTextFixed ("testb",     "\nBar -4:\t\t",                         TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                
    DrawTextFixed ("testb1",    "\n"+Volume[4].ToString(),                 TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );        
                   
    DrawTextFixed ("testc",     "\n\nBar -3:\t\t",                         TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                
    DrawTextFixed ("testc1",    "\n\n"Volume[3].ToString(),             TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );                                    
                
    DrawTextFixed ("testd",     "\n\n\nBar -2:\t\t",                     TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                
    DrawTextFixed ("testd1",    "\n\n\n"Volume[2].ToString(),         TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                
    DrawTextFixed ("teste",     "\n\n\n\nBar -1:\t\t",                     TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                
    DrawTextFixed ("teste1",    "\n\n\n\n"Volume[1].ToString(),         TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                
    DrawTextFixed ("testf",     "\n\n\n\n\nTest  \t\t",                 TextPosition.TopRighttextColortextFontoutlineColorareaColor,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.TopRighttextColortextFontoutlineColorareaColor,opacity );
                
    DrawTextFixed ("teste1",    "\n\n\n\n\n\n"AvFBV.ToString(),         TextPosition.TopRighttextColortextFontoutlineColorareaColor,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.
    Chris L.NinjaTrader Customer Service

    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:	257
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"12FontStyle.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.TopRighttextColortextFontoutlineColorareaColor,opacity );
                  
      DrawTextFixed ("testa1",     Volume[5].ToString(),                     TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                  
      DrawTextFixed ("testb",     "\nBar -4:\t\t",                         TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                  
      DrawTextFixed ("testb1",    "\n"+Volume[4].ToString(),                 TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );        
                     
      DrawTextFixed ("testc",     "\n\nBar -3:\t\t",                         TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                  
      DrawTextFixed ("testc1",    "\n\n"Volume[3].ToString(),             TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );                                    
                  
      DrawTextFixed ("testd",     "\n\n\nBar -2:\t\t",                     TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                  
      DrawTextFixed ("testd1",    "\n\n\n"Volume[2].ToString(),         TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                  
      DrawTextFixed ("teste",     "\n\n\n\nBar -1:\t\t",                     TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                  
      DrawTextFixed ("teste1",    "\n\n\n\n"Volume[1].ToString(),         TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );

                  
      // empty line
                  
      DrawTextFixed ("testf",     "  \t\t",                                 TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                  
      // Average Volume
                  
      DrawTextFixed ("teste",     "\n\n\n\n\n\nAVG:\t\t",                 TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                  
      DrawTextFixed ("teste1",    "\n\n\n\n\n\n"AvFBV.ToString(),         TextPosition.TopRighttextColortextFontoutlineColorareaColor,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.
        Chris L.NinjaTrader Customer Service

        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:	294
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"12FontStyle.Regular);
                  private 
          Font textFontBold        = new Font("Arial"12FontStyle.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.TopRighttextColortextFontoutlineColorareaColor,opacity );
                      
          DrawTextFixed ("testa1",     String5,                             TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                      
          DrawTextFixed ("testa2",     String4,                             TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                      
          DrawTextFixed ("testa3",     String3,                             TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                      
          DrawTextFixed ("testa4",     String2,                             TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );
                      
          DrawTextFixed ("testa5",     String1,                             TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );

                      
          // empty line
                      
          DrawTextFixed ("testa6",     "\t",                                     TextPosition.TopRighttextColortextFontoutlineColorareaColor,opacity );

                      
          // Average Volume
                      
          DrawTextFixed ("testa7",    StringAverage,         TextPosition.TopRighttextColortextFontBoldoutlineColorareaColor,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.
            JimNinjaTrader Customer Service

            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

                Chris L.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by sidlercom80, 10-28-2023, 08:49 AM
                166 responses
                2,234 views
                0 likes
                Last Post sidlercom80  
                Started by thread, Yesterday, 11:58 PM
                0 responses
                1 view
                0 likes
                Last Post thread
                by thread
                 
                Started by jclose, Yesterday, 09:37 PM
                0 responses
                6 views
                0 likes
                Last Post jclose
                by jclose
                 
                Started by WeyldFalcon, 08-07-2020, 06:13 AM
                10 responses
                1,414 views
                0 likes
                Last Post Traderontheroad  
                Started by firefoxforum12, Yesterday, 08:53 PM
                0 responses
                11 views
                0 likes
                Last Post firefoxforum12  
                Working...
                X