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

Why is this plotting only one line?

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

    Why is this plotting only one line?

    I'm trying to write a lot of 'simple' code modules for myself to get better at this.

    It's not working.

    Why does this only plot one line and not 3 nearly parallel ones? Actually, it seems to print all 3 lines right on top of each other...

    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.DarkGreen), PlotStyle.Line, "WaveHi"));
    Add(new Plot(Color.FromKnownColor(KnownColor.DimGray), PlotStyle.Line, "WaveMid"));
    Add(new Plot(Color.FromKnownColor(KnownColor.DarkRed), PlotStyle.Line, "WaveLow"));
    PriceTypeSupported = true;
    Overlay = true;
    }

    protected override void OnBarUpdate()
    {
    WaveHi.Set(CurrentBar == 0 ? High[0] : High[0] * (2.0 / (1 + wavePeriod)) + (1 - (2.0 / (1 + wavePeriod))) * Value[1]);
    WaveMid.Set(CurrentBar == 0 ? Close[0] : Close[0] * (2.0 / (1 + wavePeriod)) + (1 - (2.0 / (1 + wavePeriod))) * Value[1]);
    WaveLow.Set(CurrentBar == 0 ? Low[0] : Low[0] * (2.0 / (1 + wavePeriod)) + (1 - (2.0 / (1 + wavePeriod))) * Value[1]);

    }

    #2
    Hello Darth_Trader,

    Thank you for your post.

    The indicator code is plotting three separate lines on the Price Panel of the Input Series without issue on my end.

    Can you provide a screenshot of what you are seeing on your chart?

    I look forward to your response.

    Comment


      #3
      It DOES show 3 lines, but it should be the Raghee Horner 34 EMA wave of 3 34-EMAs one plotted to close[0], one to high[0] and one to low[0].


      These are all right on top of each other. My code is in the first post.

      How do you set the "WaveHi.Set" to the high[0]? I guessed, and it doesn't seem to be working.

      What it SHOULD look like is the second image.

      The point to this, btw, is not to download someone else's indicator...I'm sure this has been done over 1,000 times. I just want to program an easy thing myself...but it's never easy.
      Attached Files
      Last edited by Darth_Trader; 06-24-2015, 06:39 AM.

      Comment


        #4
        Hello,

        It looks like your code is working as expected from the standpoint of drawing the plots, but there may be something wrong with the formulas you are using for your wave calculations. When I set wavePeriod to 34 in my code, I'm seeing what you are seeing, but when I substitute a smaller number, such as 3 or 4, the waves look much more like your second screenshot.

        I believe I may have found the source of the issue, but I cannot be certain without knowing exactly what the formula should be for this type of wave pattern. I notice that the final step in all three formulas is to multiply by Value[1], which would be the value of the WaveHi plot one bar ago. When I changed this to represent the value of each specific plot one bar ago (Values[0][1] for WaveHi, Values[1][1] for WaveMid, Values[2][1] for WaveLow), then I'm seeing something much more smooth using 34 as the wavePeriod value.

        Below you can see a screenshot of my chart after making that change, with wavePeriod = 34:

        http://screencast.com/t/8z5YsQo5
        Dave I.NinjaTrader Product Management

        Comment


          #5
          the calculation is simply (3) 34-period EMA's

          1) set to High[0]
          2) set to Close[0]
          3) set to Low[0]

          That's it.

          Comment


            #6
            BTW, I simply cut n pasted those from the EMA indicator.

            Then changed Input{0] to either High/Close/Low.

            Comment


              #7
              It gives me an error.

              WaveHi.Set(CurrentBar == 0 ? High[0] : High[0] * (2.0 / (1 + wavePeriod)) + (1 - (2.0 / (1 + wavePeriod))) * Value[0][1]);
              WaveMid.Set(CurrentBar == 0 ? Close[0] : Close[0] * (2.0 / (1 + wavePeriod)) + (1 - (2.0 / (1 + wavePeriod))) * Value[1][1]);
              WaveLow.Set(CurrentBar == 0 ? Low[0] : Low[0] * (2.0 / (1 + wavePeriod)) + (1 - (2.0 / (1 + wavePeriod))) * Value[2][1]);

              Comment


                #8
                You should be using Values (plural), rather than Value. You can see more information about Value and Values at the links below:

                http://ninjatrader.com/support/helpG...nt7/?value.htm

                http://ninjatrader.com/support/helpG...t7/?values.htm

                If you really only need an EMA, then you might consider using the EMA() indicator method, instead, like so:

                Code:
                Edited:
                WaveHi.Set(EMA(High, 34)[0]);
                WaveMid.Set(EMA(Close, 34)[0]);
                WaveLow.Set(EMA(Low, 34)[0]);
                Last edited by NinjaTrader_DaveI; 06-24-2015, 11:57 AM.
                Dave I.NinjaTrader Product Management

                Comment


                  #9
                  New Errors...

                  THIS is my problem...no matter what I copy/paste/etc...I get errors and try to find out why in the manual...all to no avail usually.
                  Attached Files

                  Comment


                    #10
                    Originally posted by NinjaTrader_Dave View Post
                    You should be using Values (plural), rather than Value. You can see more information about Value and Values at the links below:

                    http://ninjatrader.com/support/helpG...nt7/?value.htm

                    http://ninjatrader.com/support/helpG...t7/?values.htm

                    If you really only need an EMA, then you might consider using the EMA() indicator method, instead, like so:

                    Code:
                    WaveHi.Set(EMA(High[0], 34));
                    WaveMid.Set(EMA(Close[0], 34));
                    WaveLow.Set(EMA(Low[0], 34));
                    Your indexer is misplaced.
                    Code:
                    WaveHi.Set(EMA(High, 34)[0]); //etc.

                    Comment


                      #11
                      Koganam is right, as usual. You will need to pass in the data series to the EMA method, then add the indexer at the end, the way that he shows below. The way that I had it, we were passing in an index of the data series, rather than the data series itself.
                      Dave I.NinjaTrader Product Management

                      Comment


                        #12
                        Thank You!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Skifree, Today, 03:41 AM
                        1 response
                        2 views
                        0 likes
                        Last Post Skifree
                        by Skifree
                         
                        Started by usazencort, Today, 01:16 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post usazencort  
                        Started by kaywai, 09-01-2023, 08:44 PM
                        5 responses
                        603 views
                        0 likes
                        Last Post NinjaTrader_Jason  
                        Started by xiinteractive, 04-09-2024, 08:08 AM
                        6 responses
                        23 views
                        0 likes
                        Last Post xiinteractive  
                        Started by Pattontje, Yesterday, 02:10 PM
                        2 responses
                        22 views
                        0 likes
                        Last Post Pattontje  
                        Working...
                        X