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

A little transformation

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

    #16
    Hello Arthur,

    Thank you for your response.

    The HighestBar() method will search all bars within the period for the highest bar found. There is no method to make it find the second highest bar.

    The following code will work for your purposes:
    Code:
    //Highest Volume
    			int vol1 = HighestBar(Volume, Bars.BarsSinceSession-1);
    			
    			//Second Highest Volume
    			int vol2 = 0;
    			for(int j = 0; j < Bars.BarsSinceSession-1; j++)
    			{
    				if(Volume[j] > Volume[vol2] && Volume[j] < Volume[vol1])
    					vol2 = j;
    			}
    			
    			///Color the plots appropriately
    			PlotColors[0][vol1] = Color.Red;
    			PlotColors[0][vol2] = Color.Yellow;
    Please let me know if I may be of further assistance.
    Last edited by NinjaTrader_PatrickH; 10-22-2013, 02:15 PM.

    Comment


      #17
      Patrick-


      Thank you, last thing to clarify:

      Is this the right way to find a first lower volume since the session start (very first decline in volume)?

      int FirstLowerVol = LRO(delegate {return Volume[-1] < Volume[0];}, 1, Bars.BarsSinceSession);


      Thanks a lot,
      Arthur
      Last edited by FxInception; 10-22-2013, 02:07 PM.

      Comment


        #18
        Hello Arthur,

        Thank you for your response.

        It would be the following:
        Code:
        int FirstLowerVol = LRO(delegate {return Volume[0] < Volume[1];}, 1, Bars.BarsSinceSession-1);
        For information on how bar data is referenced please visit the following link: http://www.ninjatrader.com/support/h...nstruments.htm

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

        Comment


          #19
          Patrick-


          Any ideas why this is not working then?

          //Second Highest Volume

          int FirstLowerVol = LRO(delegate {return Volume[0] < Volume[1];}, 1, Bars.BarsSinceSession-1);

          for(int j = 0; j < Bars.BarsSinceSession-1; j++)
          {
          if ((Volume[j] > Volume[FirstLowerVol]) && (Volume[j] < Volume[vol1]))
          FirstLowerVol = j;
          }

          It just shows an empty window..


          Arthur

          Comment


            #20
            Hello Arthur,

            Thank you for your response.

            I would need to see the full use of the code here, this small snippet does not show what you do with the FirstLowerVol int once it has been returned.

            Comment


              #21
              Patrick-


              Sorry, here it is:

              //Highest Volume
              int vol1 = HighestBar(Volume, Bars.BarsSinceSession+1);
              for(int i = 0; i < Bars.BarsSinceSession+1; i++)
              {
              if (Volume[i] > Volume[vol1])
              vol1 = i;
              }

              //Second Highest Volume

              int FirstLowerVol = LRO(delegate {return Volume[0] < Volume[1];}, 1, Bars.BarsSinceSession-1);

              for(int j = 0; j < Bars.BarsSinceSession-1; j++)
              {
              if ((Volume[j] > Volume[FirstLowerVol]) && (Volume[j] < Volume[vol1]))
              FirstLowerVol = j;
              }

              ///Color the plots appropriately
              PlotColors[0][vol1] = Color.Red;
              PlotColors[
              0][FirstLowerVol] = Color.Yellow;


              I'm fully satisfied with the first part and it works fine without the second one. But once I add a second part, indicator shows only an empty window..


              Thank you,
              Arthur

              Comment


                #22
                A second part, which you provided earlier to me, doesn't work the way I want unfortunately..
                I can show it on pictures if you would like.

                Arthur

                Comment


                  #23
                  Hello Arthur,

                  Thank you for your response.

                  Is there an error message listed in the Log tab of the NinjaTrader Control Center? If so, what does this error report?

                  I look forward to your response.

                  Comment


                    #24
                    Sure, it shows:

                    < Error on calling 'OnBarUpdate' method for indicator 'Arthur Vol' on bar 0: 'lookBackPeriod' parameter on 'LRO' method must be greater/equal 0 >


                    Arthur

                    Comment


                      #25
                      Does it mean that I cannot use Bars.BarsSinceSession in LRO method?


                      Arthur

                      Comment


                        #26
                        Hello Arthur,

                        Thank you for your response.

                        You will need a null check of the Bars so that you are not subtracting 1 from 0. So at the beginning of your OnBarUpdate() place the following:
                        Code:
                        if(Bars == null)
                        return;
                        Please let me know if I may be of further assistance.

                        Comment


                          #27
                          It still reports the same and the indicator window remains empty..

                          Arthur

                          Comment


                            #28
                            Hello Arthur,

                            Thank you for your response.

                            Please attach the full indicator .cs file to your response. You will find the indicator in the following directory on your PC: (My) Documents\NinjaTrader 7\bin\Custom\Indicator

                            Comment


                              #29
                              Patrick-


                              Please find the indicator attached. I want to mention again that the problem is in a second highest volume only.


                              Many thanks,
                              Arthur
                              Attached Files

                              Comment


                                #30
                                Hello Arthur,

                                Thank you for your response.

                                For the LRO() we will need to remove the -1 at the end of the period for the Bars.BarsSinceSession so that it reflects the following:
                                Code:
                                int FirstLowerVol = LRO(delegate {return Volume[0] < Volume[1];}, 1, Bars.BarsSinceSession);
                                Please let me know if I may be of further assistance.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by tkaboris, Today, 05:13 PM
                                0 responses
                                2 views
                                0 likes
                                Last Post tkaboris  
                                Started by GussJ, 03-04-2020, 03:11 PM
                                16 responses
                                3,281 views
                                0 likes
                                Last Post Leafcutter  
                                Started by WHICKED, Today, 12:45 PM
                                2 responses
                                19 views
                                0 likes
                                Last Post WHICKED
                                by WHICKED
                                 
                                Started by Tim-c, Today, 02:10 PM
                                1 response
                                10 views
                                0 likes
                                Last Post NinjaTrader_ChelseaB  
                                Started by Taddypole, Today, 02:47 PM
                                0 responses
                                5 views
                                0 likes
                                Last Post Taddypole  
                                Working...
                                X