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

Counting Occurences

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

    #16
    Hi Koganam, you are welcome to see any code. The only code I have written is in respect of the tick so far as follows:

    double tickupcount = CountIf(delegate {return High[0] >highcount;}, Bars.BarsSinceSession);
    double tickdowncount = CountIf(delegate {return Low[0] <lowcount*-1;}, Bars.BarsSinceSession);

    The plan is it will take a multitude of market internal data from TICK, TRIN, VIX, ADD and sector data and then derive a Long or Short score based on the strength/weakness of the internals. Having said that the tick is probably the only one where countif will be used which is the most critical and this criteria must be satisfied first before any of the other criteria is even tested. If you look at the chart in my last post to Ryan you will see the countif giving the figures on the top and bottom right for a tick of +800 or -800. Once this test is carried out it will then test the other market internals based on a weighting I'm assigning to them.

    Please let me know if this makes sense now. I appreciated Ryan's ideas on this given barrsarray won't work but will have to figure out how that works.

    Cheers
    DJ

    Comment


      #17
      Originally posted by djkiwi View Post
      Hi Koganam, you are welcome to see any code. The only code I have written is in respect of the tick so far as follows:

      double tickupcount = CountIf(delegate {return High[0] >highcount;}, Bars.BarsSinceSession);
      double tickdowncount = CountIf(delegate {return Low[0] <lowcount*-1;}, Bars.BarsSinceSession);

      The plan is it will take a multitude of market internal data from TICK, TRIN, VIX, ADD and sector data and then derive a Long or Short score based on the strength/weakness of the internals. Having said that the tick is probably the only one where countif will be used which is the most critical and this criteria must be satisfied first before any of the other criteria is even tested. If you look at the chart in my last post to Ryan you will see the countif giving the figures on the top and bottom right for a tick of +800 or -800. Once this test is carried out it will then test the other market internals based on a weighting I'm assigning to them.

      Please let me know if this makes sense now. I appreciated Ryan's ideas on this given barrsarray won't work but will have to figure out how that works.

      Cheers
      DJ
      It sounds like a BarsInProgress filter is what you need.

      if (BarsInProgress == IndexOfTICKInBarsArray)
      {
      // do stuff
      }

      Given the code that you showed this should translate to:

      Code:
      private int tickupcount = 0;
      private int tickdowncount = 0;
      
      protected override void OnBarUpdate()
      {
      if (BarsInProgress == 1)
      {
      // do TICK stuff
      tickupcount = CountIf(delegate {return High[0] >highcount;}, Bars.BarsSinceSession);
      tickdowncount = CountIf(delegate {return Low[0] <lowcount*-1;}, Bars.BarsSinceSession);
      }
      }
      In general, never use a double if you are representing an integer. It takes more resources, no matter how infinitesmal, for the computer to handle doubles than it does to handle integers. A count will always be an integer, and CountIf() signature does show it returning an integer.

      Comment


        #18
        BarSInProgress

        Hi Koganam, thanks for the tip on the doubles and the code you posted. I have them all over the place so will look at switching them. On the code you posted the part where you have:

        if (BarsInProgress ==1 didn't produce any results but once I got rid of that it worked ok and produced the same results as the bools.

        I did have one other question in relation to this if you or Ryan have the time. I've attached a picture of a screen that shows market internals. One nagging issue which is causing some grief with market internals is the application of moving averages and I was thinking this Bars.BarsSinceSession may fix it but not sure how to implement it.

        Now if you look at the VIX chart on the bottom left you will the VIX at 17.4 at yesterdays close. On open though it started at about 16.30 . The problem is the VMA 5 (the green/red line) continued from the close so the VMA was distorted. I've also included a similar example for the ADD on 4/1 where it finished

        So the question is how do I start an indicator to start plotting from the opening session bar and not take into account yesterday which distorts the issue? Thanks. DJ
        Attached Files

        Comment


          #19
          if (BarsInProgress ==1 didn't produce any results ...
          1. Are you sure that "^TICK" was the first equity DataSeries that you added?
          2. What error, if any, is in your log?

          Comment


            #20
            So the question is how do I start an indicator to start plotting from the opening session bar and not take into account yesterday which distorts the issue?
            You can pass Bars.BarsSinceSession + 1 as a period input, so that it starts calculating the indicator new at each session. The draw text statement is included only to illustrate exactly what value is used for the Period input for each bar.
            Code:
            Value.Set(SMA(Close, Bars.BarsSinceSession + 1)[0]);
            DrawText("BSS" + CurrentBar, (Bars.BarsSinceSession + 1).ToString(), 0, High[0] + TickSize * 2, Color.Black);
            Ryan M.NinjaTrader Customer Service

            Comment


              #21
              Counting occurrences and doubles

              Thanks guys for the responses. I am still working through your ideas. I'm still a little confused on doubles and ints etc and what to use. For example I've made some custom indicators but they seem to work differently based on the type of number I'm using above integer one or below integer 1. For example the first chart I need to input in numbers less than 1. Eg:

              private double top = 0.68;

              In Region properties I put in:

              [Description("Inputs.")]
              [Gui.Design.DisplayNameAttribute("Top")]
              public double Top
              {
              get { return top; }
              set { top = Math.Max(0.0001, value);
              }

              Now the second chart I have a larger number:

              private double top = 300;

              In Region properties I put in:

              [Description("Inputs.")]
              [Gui.Design.DisplayNameAttribute("Top")]
              public double Top
              {
              get { return top; }
              set { top = Math.Max(0.0001, value);
              }

              Now the first chart plots the colors of the lines ok but the second one they don't plot all the lines only the extreme blue line. So basically I'm not sure what to put in variable public double, int etc and region properties so anything below integer 1 plots and above 1 plot ok. I have attached the entire code if you want to see the whole thing. Thanks. DJ
              Attached Files

              Comment


                #22
                Generally integers are used when you're working with whole numbers only (1, 2, 45, etc) and doubles will have a decimal value (.345, 6.27, etc).

                If you're having trouble with your code, start simplifying the specific plots you're having trouble with and check log tab of control center for any error messages.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #23
                  Originally posted by djkiwi View Post
                  Thanks guys for the responses. I am still working through your ideas. I'm still a little confused on doubles and ints etc and what to use. For example I've made some custom indicators but they seem to work differently based on the type of number I'm using above integer one or below integer 1. For example the first chart I need to input in numbers less than 1. Eg:

                  private double top = 0.68;

                  In Region properties I put in:

                  [Description("Inputs.")]
                  [Gui.Design.DisplayNameAttribute("Top")]
                  public double Top
                  {
                  get { return top; }
                  set { top = Math.Max(0.0001, value);
                  }

                  Now the second chart I have a larger number:

                  private double top = 300;

                  In Region properties I put in:

                  [Description("Inputs.")]
                  [Gui.Design.DisplayNameAttribute("Top")]
                  public double Top
                  {
                  get { return top; }
                  set { top = Math.Max(0.0001, value);
                  }

                  Now the first chart plots the colors of the lines ok but the second one they don't plot all the lines only the extreme blue line. So basically I'm not sure what to put in variable public double, int etc and region properties so anything below integer 1 plots and above 1 plot ok. I have attached the entire code if you want to see the whole thing. Thanks. DJ
                  After looking at your code, I am surprised that anything plots at all.

                  For one thing, you have used the reserved word value as a variable, albeit local. That is a general no-no. You never know if you may later decide to make that a global variable, at which point you will have a circular reference for sure.

                  The reason your second scenario does not plot is most likely a display issue, as 300 is so far removed from the other values that you are plotting.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by benmarkal, Yesterday, 12:52 PM
                  3 responses
                  22 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by helpwanted, Today, 03:06 AM
                  1 response
                  16 views
                  0 likes
                  Last Post sarafuenonly123  
                  Started by Brevo, Today, 01:45 AM
                  0 responses
                  11 views
                  0 likes
                  Last Post Brevo
                  by Brevo
                   
                  Started by aussugardefender, Today, 01:07 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post aussugardefender  
                  Started by pvincent, 06-23-2022, 12:53 PM
                  14 responses
                  244 views
                  0 likes
                  Last Post Nyman
                  by Nyman
                   
                  Working...
                  X