• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Rising/falling

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

    Rising/falling

    "Checks for a rising condition which is true when the current value is greater than the value of 1 bar ago."

    The definition of the built in rising NT function is above. What I'm trying to do is check to see if the slope of the regression channel is rising or falling. The above works most of the time, but sometimes, the major trend (I'm using 2 hour bars) is falling, but the 1 bar ago vs current bar is rising. Hence, the indicator does what it's suppose to do, check 1 bar ago, but for my purpose, it gives the wrong trading signal. What I want to be able to do is:

    If most of the regression slope values for the past 100 bars on a 2 hour chart is falling; enter long/ short. How can I do this?

    #2
    i think i can help with the mathematics involved, but i'm sure i can't help with the programming at all.

    if i understand correctly, you could posit your problem in the following way:

    you have a regression channel slope with more than 100 values. you want to know whether most of the last 100 values are rising or falling. if a majority is rising you want the strategy to do something, if a majority is falling, do something else.

    you could define a hundred substractions:

    srch[0] - srch[1] (srch stands for slope of the regression channel for short) if this is positive, create a list that adds up all rising values and add 1 to it. if it is negative, create a list that adds up all falling values and add 1 to it. then repeat these operations through srch[98] - srch[99].

    then, you could compare the rising and falling columns and if rising > falling code action 1, if rising < falling code action 2.

    hope that can be of help.

    Comment


      #3
      Hello calhawk01,

      Thank you for your post.

      You can perform this with a for loop. Below I have included an example of how this could be performed.
      Code:
       protected override void OnBarUpdate()
              {
      			if (CurrentBar <= period)
      				return;
      			
      			int midup = 0;
      			int middn = 0;
      			int upup = 0;
      			int updn = 0;
      			int loup = 0;
      			int lodn = 0;
                  for (int i = period-1; i > 0; i--)
      			{
      				if (RegressionChannel(20, 1)[i] <  RegressionChannel(20, 1)[i-1])
      					midup++;
      				if (RegressionChannel(20, 1)[i] >  RegressionChannel(20, 1)[i-1])
      					middn++;
      				if (RegressionChannel(20, 1).Upper[i] <  RegressionChannel(20, 1).Upper[i-1])
      					upup++;
      				if (RegressionChannel(20, 1).Upper[i] >  RegressionChannel(20, 1).Upper[i-1])
      					updn++;
      				if (RegressionChannel(20, 1).Lower[i] <  RegressionChannel(20, 1).Lower[i-1])
      					loup++;
      				if (RegressionChannel(20, 1).Lower[i] >  RegressionChannel(20, 1).Lower[i-1])
      					lodn++;
      			}
      			Print(midup + " " + middn);
      			Print(upup + " " + updn);
      			Print(loup + " " + lodn);
      			
      			if (midup > middn)
      				Print(Time[0] + " Mid line has more rising.");
      			else if (midup < middn)
      				Print(Time[0] + " Mid line has more falling.");
      			
      			if (upup > updn)
      				Print(Time[0] + " Upper line has more rising.");
      			else if (upup < updn)
      				Print(Time[0] + " Upper line has more falling.");
      			
      			if (loup > lodn)
      				Print(Time[0] + " Lower line has more rising.");
      			else if (loup < lodn)
      				Print(Time[0] + " Lower line has more falling.");
              }
      You would need to define period as a user defined parameter: http://ninjatrader.com/support/forum...ead.php?t=5782
      Patrick H.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_PatrickH View Post
        Hello calhawk01,

        Thank you for your post.

        You can perform this with a for loop. Below I have included an example of how this could be performed.
        Code:
         protected override void OnBarUpdate()
                {
                    if (CurrentBar <= period)
                        return;
                    
                    int midup = 0;
                    int middn = 0;
                    int upup = 0;
                    int updn = 0;
                    int loup = 0;
                    int lodn = 0;
                    for (int i = period-1; i > 0; i--)
                    {
                        if (RegressionChannel(20, 1)[i] <  RegressionChannel(20, 1)[i-1])
                            midup++;
                        if (RegressionChannel(20, 1)[i] >  RegressionChannel(20, 1)[i-1])
                            middn++;
                        if (RegressionChannel(20, 1).Upper[i] <  RegressionChannel(20, 1).Upper[i-1])
                            upup++;
                        if (RegressionChannel(20, 1).Upper[i] >  RegressionChannel(20, 1).Upper[i-1])
                            updn++;
                        if (RegressionChannel(20, 1).Lower[i] <  RegressionChannel(20, 1).Lower[i-1])
                            loup++;
                        if (RegressionChannel(20, 1).Lower[i] >  RegressionChannel(20, 1).Lower[i-1])
                            lodn++;
                    }
                    Print(midup + " " + middn);
                    Print(upup + " " + updn);
                    Print(loup + " " + lodn);
                    
                    if (midup > middn)
                        Print(Time[0] + " Mid line has more rising.");
                    else if (midup < middn)
                        Print(Time[0] + " Mid line has more falling.");
                    
                    if (upup > updn)
                        Print(Time[0] + " Upper line has more rising.");
                    else if (upup < updn)
                        Print(Time[0] + " Upper line has more falling.");
                    
                    if (loup > lodn)
                        Print(Time[0] + " Lower line has more rising.");
                    else if (loup < lodn)
                        Print(Time[0] + " Lower line has more falling.");
                }
        You would need to define period as a user defined parameter: http://ninjatrader.com/support/forum...ead.php?t=5782

        Pat you are the man! Thanks for the above code. I will test it when I get back home. Im curious what your thoughts are on a simpler solution:

        Use price variable such as Close[0] but the input is a regression channel data. And then offset the close. So for example

        Close[0] (input regressional channel) now is less than Close[0][10 bar ago] (input regressional channel)

        and

        Close[10 bars ago w/ regressional channel data] is less than close[50 bars ago w/ regression channel data]

        Comment


          #5
          Hello calhawk01,

          You should not be accessing historical values for the Regression Channel.

          Per the help guide section for the Regression Channel indicator: https://ninjatrader.com/support/help...on_channel.htm

          You should not access historical values of this indicator since the values can change from bar to bar. The values from n bars ago does not reflect what the values of the current bar really are. It is suggested that you only access the current bar value for this indicator.
          Zachary G.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by rontronimous, Today, 05:55 PM
          0 responses
          8 views
          0 likes
          Last Post rontronimous  
          Started by bcgeek, Today, 03:43 PM
          2 responses
          6 views
          0 likes
          Last Post bcgeek
          by bcgeek
           
          Started by Mberg, Today, 04:05 PM
          0 responses
          9 views
          0 likes
          Last Post Mberg
          by Mberg
           
          Started by dkbyond, Today, 03:52 PM
          0 responses
          5 views
          0 likes
          Last Post dkbyond
          by dkbyond
           
          Started by Newtrader101, Today, 03:09 PM
          2 responses
          7 views
          0 likes
          Last Post Newtrader101  
          Working...
          X