Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Displacement/offset for Linear Regression.. how?

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

    Displacement/offset for Linear Regression.. how?

    I'm trying to setup a strategy to use a linear regression line w/ Period 24, offset: 2..

    I was able to setup this fine in the indicators (they apply to my chart), but if I apply both at the same time, they use 2 different offsets.

    Any ideas? (see pictures)
    Attached Files
    Last edited by theoreticaLee; 07-22-2010, 11:29 AM.

    #2
    theoreticaLee,

    In your indicators dialogue you are using Displacement. Displacement is not the same as the Offset being used in the Condition Builder.

    Displacement is a visual concept of just having the indicator plotted either a few bars in front of where it normally would or a few bars behind. Offset is a concept to actually change the values of the indicator. Offsetting by 2 ticks means take the Linear Regression value and add two ticks to it.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      theoreticaLee,

      Displacement is a visual concept of just having the indicator plotted either a few bars in front of where it normally would or a few bars behind.
      Fantastic description. The big question is, is it "codeable"? Any suggestion I've read in the forum gives me a coding error, including this from the help menu ...

      // Initialize method of a custom indicator
      protected override void Initialize()
      {
      Add(new Plot(Color.Orange, "SMA"));
      Displacement = 2; // Plots the indicator value from 2 bars ago on the current bar
      }
      Thanks David

      Comment


        #4
        Hi David,

        Displacement = 2;

        This line compiles in an indicator here. Hopefully can track down why it's not working for you. Can you please let us know the following:
        • Are you using in an indicator?
        • What is the descriptive error message you're getting when using it?
        • Does it list the errors related to the script you're working with or a different script?
        • Did you copy that whole block or just add Displacement to an indicator's existing Initialze() method?
        • What version of NinjaTrader are you using? Check with Help > About.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_RyanM View Post
          Hi David,

          Displacement = 2;



          This line compiles in an indicator here. Hopefully can track down why it's not working for you. Can you please let us know the following:
          • Are you using in an indicator?
          • What is the descriptive error message you're getting when using it?
          • Does it list the errors related to the script you're working with or a different script?
          • Did you copy that whole block or just add Displacement to an indicator's existing Initialze() method?
          • What version of NinjaTrader are you using? Check with Help > About.
          I guess before I go any further, I must qualify that I'm still on training wheels regarding C coding. The NT version I'm using 7.0.1000.6. Is it possible to code say, a SMA(20) crossing above/below a SMA(20) with a 2 bar displacement? Maybe this is something for the Condition Builder in the next version?
          The Image displays what I'm getting. What am I doing wrong?
          Thanks David
          Attached Files
          Last edited by ES Larrikin; 06-13-2011, 09:23 PM.

          Comment


            #6
            You're trying to use Displacement in a strategy. It's for indicator plots only.

            To code this in a strategy wizard, you want to work with the bars ago value for an indicator when creating your condition.

            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Thanks Ryan,
              The other question I have is, " Is it possible to code say, a SMA(20) crossing above/below a SMA(20) with a 2 bar displacement?". If it's not possible then I won't waste my time trying to figure it out.
              Thanks David

              Comment


                #8
                David,

                SMA(20) with a 2 bar displacement is just moving the old SMA values forward. This would be equivalent to just accessing SMA(20)[2] instead of [0]. You can check for that double value to do such a comparison.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Josh View Post
                  David,

                  You can check for that double value to do such a comparison.
                  Please pardon my ignorance but I don't understand what you're saying. I have tried coding in a SMA(20)[5]CrossbelowSMA(20) but nothing happens. In the example, the blue SMA has been displaced 5 bars ahead of the current gold SMA.
                  Can you tell me the context in which I should use the code below from the HELP menu so as not to get a coding error?

                  // Initialize method of a custom indicator
                  protected override void Initialize()
                  {
                  Add(new Plot(Color.Orange, "SMA"));
                  Displacement = 2; // Plots the indicator value from 2 bars ago on the current bar
                  }

                  Where do I set the SMA value? Feeling like a dunce but if I don’t ask, I don’t learn.
                  Thanks David
                  PS I've added the conditionbuilder image if it helps. This code only plots a single SMA.
                  Attached Files
                  Last edited by ES Larrikin; 06-15-2011, 12:02 AM. Reason: Added 'conditionbuilder' image

                  Comment


                    #10
                    Displacement does not belong in a strategy. It's a visual setting that shifts plot values forward. It belongs in indicator scripts only. It won't compile and has no place anywhere in your strategy code.

                    You can reference prior bar values by applying a bars ago value (if you're working in the condition builder), or using [] if you're working with code.

                    See here for help working with the condition builder. Whenever you select an indicator or price data value, you have a bars ago setting you can specify.

                    See here for help working with [ ] to reference prior bar values:
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_RyanM View Post
                      Displacement does not belong in a strategy. It's a visual setting that shifts plot values forward. It belongs in indicator scripts only. It won't compile and has no place anywhere in your strategy code.

                      You can reference prior bar values by applying a bars ago value (if you're working in the condition builder), or using [] if you're working with code.

                      See here for help working with the condition builder. Whenever you select an indicator or price data value, you have a bars ago setting you can specify.

                      See here for help working with [ ] to reference prior bar values:
                      http://www.ninjatrader.com/support/f...ad.php?t=19346
                      So, the simple answer to my question, " Is it possible to code say, a SMA(20) crossing above/below a SMA(20) with a 2 bar displacement?" is no, it cant. Is that correct?
                      David

                      Comment


                        #12
                        No, displacement cannot be used in a strategy.

                        Displacement is the visual representation of accessing prior bar values though. If you review the last few posts by us, it may start to make sense why we're telling you about bars ago and [ ] brackets.

                        if (CrossAbove(SMA(20), SMA(20)[2], 1))
                        {
                        }
                        Last edited by NinjaTrader_RyanM1; 06-15-2011, 04:00 PM.
                        Ryan M.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        648 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        369 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        108 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        572 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        573 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X