• 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

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:
    protectedoverridevoid OnBarUpdate()
    {
    int smooth = len/2 + 1;
    DPOsc.Set(Close[0] - SMA(Close, smooth)[len]);
    }
    
    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.

    http://www.ninjatrader.com/support/f...d=4&linkid=556
    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

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by edmata1109, Yesterday, 10:36 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post edmata1109  
                  Started by StevenNelson, 10-11-2019, 05:51 AM
                  2 responses
                  14 views
                  0 likes
                  Last Post ManIp
                  by ManIp
                   
                  Started by TazoTodua, Yesterday, 12:29 PM
                  2 responses
                  24 views
                  0 likes
                  Last Post TazoTodua  
                  Started by sdauteuil, Yesterday, 03:16 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post sdauteuil  
                  Started by Zenersev, Yesterday, 02:11 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post Zenersev  
                  Working...
                  X