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

Detrended Price Oscillator

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

    Detrended Price Oscillator

    I am surprised this isn't a built in NT7 indicator. I have been using this with ThinkOrSwim and Multicharts EasyLanguage. The formula is pretty simple, but I don't understand the way NinjaScript handles series well enough to make it work. I do write C# for a living so I will figure it out, but I hope someone can save me some time.

    Here is where I am:

    [thinkscript]
    input length = 14;
    input price = close;
    plot DPO = price - Average(price[length / 2 + 1], length);

    I programmed this in ninjascript but nothing comes back:
    Code:
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] smooth = len/[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]DPOsc.Set(Close[[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] - SMA(Close, smooth)[len]);[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [/SIZE][/FONT]
    Anyone have an idea where I am off here?
    Last edited by tupchurch; 11-11-2012, 11:37 AM.

    #2
    Hello,

    I actually made something like this last week as someone else asked for the same tool.

    Adam P.NinjaTrader Customer Service

    Comment


      #3
      I downloaded that, but it is not the same thing. Maybe it is simlilar, but it plots differently on the chart.

      Comment


        #4
        Hello,

        I can see you are doing this : len/2 + 1;

        What is this len value? The code you have there looks ok for the most part, are you getting a compiling error?
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          I agree, I think it should work, althought I think my len and smooth might be backwards.

          It compiles, but if I put an offest value on the SMA of 8, then the indicator comes back empty (nothing plots), if I use 0 I get a plot but its not the correct one. Plugging constants in it would look like...

          DPOsc.Set(Close[0]-SMA(Close, 14)[8]);


          I started the debugger in VS2008, but the breakpoint isnt hit.

          Comment


            #6
            I need to offset the dataseries by 8 and get an SMA of length 14. then subtract that from Close[0]

            Comment


              #7
              Looks like I get an exception when I offset the SMA.

              'SMA(Close, 14)[8]' threw an exception of type 'System.ArgumentOutOfRangeException' double {System.ArgumentOutOfRangeException}

              I need to wait 8 bars before calculating I guess? Should this cause the whole plot to refuse to draw?

              How would I wait 8 bars? Not sure how to handle this.
              Last edited by tupchurch; 11-11-2012, 02:06 PM.

              Comment


                #8
                Originally posted by tupchurch View Post
                I need to offset the dataseries by 8 and get an SMA of length 14. then subtract that from Close[0]
                That means that you are accessing a barIndex 8 values back. You need to escape the correct number of bars, so that you are always accessing valid values.

                Code:
                if (CurrentBar < 8) return;
                at the top of the OnBarUpdate() event handler.

                Comment


                  #9
                  Yes. I put this in a try catch and it worked, your solution looks better, i will do that.

                  Comment


                    #10
                    Originally posted by NinjaTrader_AdamP View Post
                    Hello,

                    I actually made something like this last week as someone else asked for the same tool.

                    http://www.ninjatrader.com/support/f...d=4&linkid=556


                    Hi.
                    Actually I used this indicator but when I save the Workspace, show it a message that say "There was an error generating the XML document" and when I close and after open NinjaTrader8 the indicator don´t appear.

                    Maybe you know a solution?.

                    Thnaks!

                    Comment


                      #11
                      Hello b14sanabria,

                      Thanks for your post.

                      The link to the indicator mentioned is leading me to the home page of the User App Share Center.

                      Are you referring to the Detrend Oscillator indicator for NinjaTrader 8 linked below?

                      I had a request from a client for a detrending oscillator and couldn&#8217;t find one in our forum (though one may exist). I decided it&#8217;s a good thing to add so I made this for anyone to use. Detrending creates an oscillator by using the formula Current Price &#8211; Detrending Value. The detrending value is [&#8230;]


                      If so, I have tested importing this indicator, applying it to a chart, and saving a Workspace and do see the error message you are referring to.

                      Since the NinjaTrader 8 version of this indicator was not created by NinjaTrader, please reach out to the developer of the indicator regarding this error message. The developer of the indicator could be found in the User App Share page linked above next to the 'Created By' field.

                      Note to the developer that this error likely means that an input likely is not properly serialized.

                      Here is a link to a forum post that has an example of a properly serialized input.https://ninjatrader.com/support/foru...t=2#post677575

                      Let us know if we may assist further.
                      Brandon H.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Barry Milan, Today, 10:35 PM
                      1 response
                      6 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by WeyldFalcon, 12-10-2020, 06:48 PM
                      14 responses
                      1,427 views
                      0 likes
                      Last Post Handclap0241  
                      Started by DJ888, Yesterday, 06:09 PM
                      2 responses
                      9 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by jeronymite, 04-12-2024, 04:26 PM
                      3 responses
                      40 views
                      0 likes
                      Last Post jeronymite  
                      Started by bill2023, Today, 08:51 AM
                      2 responses
                      16 views
                      0 likes
                      Last Post bill2023  
                      Working...
                      X