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

Help needed for EMA Indicator

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

    Help needed for EMA Indicator

    I'm trying to develop an indicator that will print up or down triangles if the 15 EMA 4 bars ago is 4 ticks greater or less than the current bar. It compiles but doesn't print the triangles. Here's the code:

    protected override void OnBarUpdate()
    {
    // Condition set 1
    if ((EMA(25)[4] + Value) <= EMA(25)[0])
    Plot0.Set(Close[0]);

    // Condition set 2
    if ((EMA(25)[4] - Value) >= EMA(25)[0])

    Plot1.Set(Close[0]);
    }

    Plot0 and Plot1 are:

    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Lime), PlotStyle.TriangleUp, "Plot0"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.TriangleDown, "Plot1"));
    Overlay = false;
    }

    Any help solving my problem would be appreciated!

    #2
    Originally posted by pjwinner View Post
    I'm trying to develop an indicator that will print up or down triangles if the 15 EMA 4 bars ago is 4 ticks greater or less than the current bar. It compiles but doesn't print the triangles. Here's the code:

    protected override void OnBarUpdate()
    {
    // Condition set 1
    if ((EMA(25)[4] + Value) <= EMA(25)[0])
    Plot0.Set(Close[0]);

    // Condition set 2
    if ((EMA(25)[4] - Value) >= EMA(25)[0])

    Plot1.Set(Close[0]);
    }

    Plot0 and Plot1 are:

    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Lime), PlotStyle.TriangleUp, "Plot0"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.TriangleDown, "Plot1"));
    Overlay = false;
    }

    Any help solving my problem would be appreciated!
    What is the error in your log?

    Comment


      #3
      There are 2 error messages:

      Failed to set property 'Value' for indicator 'AngleEMA': Exception has been thrown by the target of an invocation.
      Error on calling 'OnBarUpdate' method for indicator 'AngleEMA' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

      I could do without the Value = 4. I re-wrote the indicator without the Input Parameter "Value" with default of 4 but thatndidn't seem to help.

      Comment


        #4
        Originally posted by pjwinner View Post
        There are 2 error messages:

        Failed to set property 'Value' for indicator 'AngleEMA': Exception has been thrown by the target of an invocation.
        Error on calling 'OnBarUpdate' method for indicator 'AngleEMA' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

        I could do without the Value = 4. I re-wrote the indicator without the Input Parameter "Value" with default of 4 but thatndidn't seem to help.
        Where and how did you declare Value?

        Comment


          #5
          I'd like to take "Value" out of this indicator. I know what I want "Value" to be and it's just adding confusion. I will also simplify the indicator. So the indicator becomes:

          protected override void OnBarUpdate()
          {
          // Condition set 1
          if ((EMA(25)[3] + 3) <= EMA(25)[0])
          Plot0.Set(Close[0]);
          }

          Plot0 is:

          {
          Add(new Plot(Color.FromKnownColor(KnownColor.Lime), PlotStyle.TriangleUp, "Plot0"));

          Overlay = false

          When I do this I get a bunch of errors:

          Indicator\AngleX.cs Invalid expression term '>=' CS1525 - click for info 43 26
          Indicator\AngleX.cs ; expected CS1002 - click for info 43 29
          Indicator\AngleX.cs ; expected CS1002 - click for info 43 39
          Indicator\AngleX.cs Invalid expression term ')' CS1525 - click for info 43 39
          Indicator\AngleX.cs ; expected CS1002 - click for info 43 40
          Indicator\AngleX.cs ; expected. 43 39

          Now my questions become: Can I use the Condition 1 expression with the Plot0.Set? If so, how do I get rid of the errors? Or do I need to somehow place Condition 1 in place of the (Close[0])?

          Comment


            #6
            Originally posted by pjwinner View Post
            I'd like to take "Value" out of this indicator. I know what I want "Value" to be and it's just adding confusion. I will also simplify the indicator. So the indicator becomes:

            protected override void OnBarUpdate()
            {
            // Condition set 1
            if ((EMA(25)[3] + 3) <= EMA(25)[0])
            Plot0.Set(Close[0]);
            }

            Plot0 is:

            {
            Add(new Plot(Color.FromKnownColor(KnownColor.Lime), PlotStyle.TriangleUp, "Plot0"));

            Overlay = false

            When I do this I get a bunch of errors:

            Indicator\AngleX.cs Invalid expression term '>=' CS1525 - click for info 43 26
            Indicator\AngleX.cs ; expected CS1002 - click for info 43 29
            Indicator\AngleX.cs ; expected CS1002 - click for info 43 39
            Indicator\AngleX.cs Invalid expression term ')' CS1525 - click for info 43 39
            Indicator\AngleX.cs ; expected CS1002 - click for info 43 40
            Indicator\AngleX.cs ; expected. 43 39

            Now my questions become: Can I use the Condition 1 expression with the Plot0.Set? If so, how do I get rid of the errors? Or do I need to somehow place Condition 1 in place of the (Close[0])?
            I think we would both be better served if you simply posted the .cs file itself. As it is, you are posting the parts of the code that you think are relevant. However, without seeing the other parts of the code on which this is dependent, it is impossible to say what your errors mean. Considering that you posted barely 6 lines of code, "line 43" really is essentially incapable of being deciphered.
            Last edited by koganam; 12-02-2012, 08:11 PM.

            Comment


              #7
              Originally posted by koganam View Post
              I think we would both be better served if you simply posted the .cs file itself. As it is, you are posting the parts of the code that you think are relevant. However, without seeing the other parts of the code on which this is dependent, it is impossible to say what your errors mean. Considering that you posted barely 6 lines of code, "line 43" really is essentially incapable of being deciphered.
              How do I post the .cs file? Simply cut and paste? Or is there a better way?

              Comment


                #8
                Originally posted by pjwinner View Post
                How do I post the .cs file? Simply cut and paste? Or is there a better way?
                Use the Advanced Reply option. There is a section below the box to Manage Attachments, among other options.

                Comment


                  #9
                  Hello pjwinner,
                  Please follow koganam's isntruction to post an attachment. In addition please refer to the the attached screenshot which further demonstrates it.
                  Attached Files
                  JoydeepNinjaTrader Customer Service

                  Comment


                    #10
                    Sorry, I had to use a .doc format because AngleEMA wouldn't compile an therefore had 0 contents. I hope this helps. Thanks for your patience!
                    Attached Files

                    Comment


                      #11
                      Hello,

                      This was caused by some syntax errors.

                      Please change to the following:
                      Code:
                                  // Condition set 1
                               [B]   if ((EMA(25)[3]) + 3 >= EMA(25)[0])[/B]
                                  {
                                      //draw triangle as desired
                                  }
                      
                                  // Condition set 2
                               [B]   if ((EMA(25)[3]) - 3 <= EMA(25)[0])[/B]
                                  {
                                      //draw triangle as desired
                                  }


                      Please let me know if I can be of further assistance.
                      LanceNinjaTrader Customer Service

                      Comment


                        #12
                        Lance B - It finally compiled! :-) However, when I actually applied it I didn't see any triangles being printed. I'm including the whole file (again in .doc form). The Draw Triangle is straight from the Strategy Wizard. Can you see anything that might keep the program from working properly? Thanks for all your help.
                        Attached Files

                        Comment


                          #13
                          Hello,

                          I've attached the .cs file with updated code, it needed the following to ensure enough bars have been loaded.
                          if (CurrentBars[0] < BarsRequired)
                          return;


                          Also your draw function is set to draw down at 0 when you may not want this. I set autoscale to true so that they would display.

                          Please let me know if I can be of further assistance.
                          Attached Files
                          LanceNinjaTrader Customer Service

                          Comment


                            #14
                            Voila! That worked! I changed the < and> signs so that it actually did what I wanted and re-did the Y axis coordinates to print above and below the bars. Thanks for your help!

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by ruudawakening, Today, 12:58 AM
                            1 response
                            8 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Started by i019945nj, 12-14-2023, 06:41 AM
                            5 responses
                            64 views
                            0 likes
                            Last Post i019945nj  
                            Started by thread, Yesterday, 11:58 PM
                            1 response
                            8 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by stafe, Yesterday, 08:34 PM
                            1 response
                            16 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by jclose, Yesterday, 09:37 PM
                            1 response
                            11 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Working...
                            X