Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

is EMA above the current pps bool

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

    #16
    Hello chris8sirhc,
    Are you trying to compare data with the preious bars, if so then please try the below code to do it.

    Code:
    if (MAX(High, 3)[1] > MAX(EMA(14), 3)[1])
    {
      //do soemthing
    }
    JoydeepNinjaTrader Customer Service

    Comment


      #17
      Is there a link that describes what each part of that MAX function means? I'm confused about the syntax for it? Do you use a -1 to indicate that you are working with the previous candle?? or do you use 1 to indicate that you are working with the previous candle. What is the 3 for? Can you convert my line of code to using the max function instead of the close for the bar?

      if ( (EMA(9)[0] < Close[0]) && (EMA(9)[-1] < Close[-1]) && (EMA(9)[-2] < Close[-2]) )
      {
      Plot0.Set(1);
      }

      Comment


        #18
        Hello

        Yes, you can refer to our help guide to know more about the MAX function.

        3 is the look back period.


        You use only 1 (one) and not -1 (minus one) to refer to the previous bars.

        You code using the MAX function will be
        Code:
        if (MAX(Close, 3)[0] > MAX(EMA(9), 3)[0])
        {
          //do something
        }
        JoydeepNinjaTrader Customer Service

        Comment


          #19
          ok, so that will give the max for the candle that is 2 back, not a compilation of the current bar and the previous 2, right?

          ie, the high within the bar that is 2 back, not the high of the last 2 bars and the current one?

          if 3 is the looking back period, then what is the 0 for?
          Last edited by chris8sirhc; 01-18-2013, 03:18 PM.

          Comment


            #20
            Hello chris8sirhc,
            It will compare the currentbar, previous bar and the candle 2 bars back.

            0 (zero) is the current MAX values. If you append 1 (one) instead of 0 (zero) then the current bar will be not evaluated.
            JoydeepNinjaTrader Customer Service

            Comment


              #21
              no, im just trying to test to see if the stock price has stayed above the EMA line for three candles in a row, I think i just need to use the High function not the max function.

              Here is what I have:

              protected override void OnBarUpdate()
              {
              // Use this method for calculating your indicator values. Assign a value to each

              if ( (EMA(9)[0] < Low[0]) && (EMA(9)[1] < Low[1]) && (EMA(9)[2] < Low[2]) )
              {
              Plot0.Set(1);
              }
              else
              {
              Plot0.Set(0);
              }

              Comment


                #22
                Hello chris8sirhc,
                You can use both the codes. Ultimately its upto you on which code you are comfortable with.
                JoydeepNinjaTrader Customer Service

                Comment


                  #23
                  Hello,

                  I'm a newbie to NT and coding in C#. After searching the forum for simple code to practice plotting a condition with a custom indicator in the Market Analyzer I came across this thread with a code snippet that seemed simple enough.

                  protected override void Initialize()
                  {
                  Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                  Overlay = false;
                  }

                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                  if(CurrentBar < BarsRequired)
                  {
                  return;
                  }
                  // Use this method for calculating your indicator values. Assign a value to each
                  // plot below by replacing 'Close[0]' with your own formula.
                  if ( EMA(9)[0] > Close[0])
                  {
                  Plot0.Set(1);
                  }
                  else
                  {
                  Plot0.Set(0);
                  }
                  }

                  I cut and pasted the code example provided, but it does not compile? I get an error "The name 'Plot0' does not exist in the current context" Why am I getting this error? how do I fix it?

                  Thanks

                  Comment


                    #24
                    I fixed the compile issue by adding a data series to the properties, forgot about that.

                    However another issue, I now get a message in Market Analyzer in the custom EMA9 column that says "#check log#'

                    All I want to do is have the background color green when the close goes above the EMA and red when it goes below. I know how to do this for stock indicators but am stumped with what should be a very simple example.

                    Comment


                      #25
                      gapmeister,

                      What does the Log Tab in the Control Center report?
                      Cal H.NinjaTrader Customer Service

                      Comment


                        #26
                        It says Error on accessing plot series'Plot0' for indicator 'EMA9':Exception has been thrown by the target of an invocation.

                        Also see some with added text Failed to call 'OnBarUpdate' method for market analyzer column EMA9.
                        Last edited by gapmeister; 11-05-2014, 08:44 AM.

                        Comment


                          #27
                          gapmeister,

                          Can you send me your full script so I can test this on my end.

                          You can attach it here or send me a note to platformsupport [at] ninjatrader [dot] com and put ATTN Cal in the subject
                          Cal H.NinjaTrader Customer Service

                          Comment


                            #28
                            Gapmeister,

                            You will need to set the DataSeries Values property to use Values[0] and not Values[2] as there is only one plot being used.

                            [Browsable(false)]
                            [XmlIgnore()]
                            public DataSeries Lower
                            {
                            get { return Values[0]; }
                            }

                            Let me know if I can be of further assistance.
                            Cal H.NinjaTrader Customer Service

                            Comment


                              #29
                              OK,

                              I'm not understanding the logic behind Ninja Script I guess, all I want to do based on the following code

                              protected override void Initialize()
                              {
                              Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                              Overlay = false;
                              }

                              /// <summary>
                              /// Called on each bar update event (incoming tick)
                              /// </summary>
                              protected override void OnBarUpdate()
                              {
                              if(CurrentBar < BarsRequired)
                              {
                              return;
                              }
                              // Use this method for calculating your indicator values. Assign a value to each
                              // plot below by replacing 'Close[0]' with your own formula.
                              if ( EMA(9)[0] > Close[0])
                              {
                              Plot0.Set(1);
                              }
                              else
                              {
                              Plot0.Set(0);
                              }
                              }



                              have the background turn green with Yellow text,when the close crosses above the EMA9,
                              Black with green text as long as the Close stays above the 9 EMA. Instead all I'm getting is a black background with "0" for everything true or false?

                              I know how to use cell conditions in Market Analyzer, but not with custom indicators which is important to me to learn.
                              Last edited by gapmeister; 11-05-2014, 02:00 PM.

                              Comment


                                #30
                                Gapmeister,

                                You indicated this error message -
                                Error on accessing plot series'Plot0' for indicator 'EMA9':Exception has been thrown by the target of an invocation.

                                This was due to the wrong Values[2] being used, and need to adjust to Values[0].

                                If you corrected the code, you will have access to the Plot0 from the Market Analyzer column and be able to set your cell conditions to check for 0 or 1.
                                Cal H.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                625 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                359 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                105 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                562 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                567 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X