Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator for price above/ below MA?

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

    Indicator for price above/ below MA?

    Hi,

    just started using NT today and trying to get the market analyzer set up.

    Is there any way to add a column which will tell me at a glance if the current price is 'Above' or 'Below' a defined moving average?

    I have the moving average columns set up, and would be happy to use a colour condition in this column in reference to the price (e.g. MA cell is green if below price, red if above), but it seems I can only set the colour conditions against a value (which obviously isn't practical versus a moving price), as opposed to the price.

    Thanks in advance.
    Last edited by monkey_boy; 09-03-2009, 04:33 AM.

    #2
    Hello monkey_boy,

    Unfortunately such a column is not supported and your findings are correct; color conditions can only use a numeric value.

    However, you could create a custom indicator that uses the condition you mention. Subsequently load it in the Market Analyzer using an Indicator column.

    More information regarding custom creating indicators can be found at the link below.
    JasonNinjaTrader Customer Service

    Comment


      #3
      Jason,

      thanks for your quick reply.

      I had already looked at the custom indicator route, but don't find the tutorial explanation particularly helpful at all, as I have only the most basic programming skills.

      Is there any way to get the wizard to produce what I am looking for without having to start messing about with the code?

      Thanks

      Comment


        #4
        Yes, you should be able to setup such a condition using the Strategy Wizard. Please see the link below for information.


        Instead of the numeric value, you would use the Close price.
        JasonNinjaTrader Customer Service

        Comment


          #5
          Jason,

          But if monkey_boy wanted to add an indicator to the Market Analyzer, this would not work, right? That is since you are suggesting creating a strategy instead of an indicator. Just trying to understand your solution. Thanks.

          Joe

          Comment


            #6
            Hello Joe,

            Unfortunately the NinjaScript wizard to create indicators does not allow you to create such a condition. That is why I referred to a strategy - the NinjaScript wizard upon creating a strategy does allow you to create such a condition. He could subsequently run the strategy in a chart.

            You can create indicators that use such a condition as well, however you would need to create it outside the wizard.
            JasonNinjaTrader Customer Service

            Comment


              #7
              Jason,

              I thought about using something like this in the indicator code:

              if CrossAbove(High[0], SMA(50), 1) to determine if a crossover occurs.
              But how would I pass back the result? I thought I could just use Value.Set = true but this gives me an error?

              Comment


                #8
                fosch, the Value.Set would expect a non boolean value, so try for example 1 for a CrossAbove and -1 for a CrossBelow.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Thanks Bertrand. I tried your suggestion with the following code:

                  protectedoverridevoid OnBarUpdate()
                  {
                  Value.Set = -
                  1;
                  // Use this method for calculating your indicator values. Assign a value to each
                  // plot below by replacing 'Close[0]' with your own formula.
                  if (CrossAbove(High[0], SMA(50), 1) || CrossBelow(Low[0], SMA(50), 1))
                  Value.Set =
                  1;
                  else
                  Value.Set = -1;
                  }

                  But the result when I tried to compile was the following error:
                  "Cannot assign to 'Set' becuase it is a 'method group'"

                  I could not find a description of the error, so I wanted to ask you what my error appears to be. Thanks.

                  Joe

                  Comment


                    #10
                    You would need to assign a value differently when using the DataSeries.Set() method, my change below should compile well -

                    Code:
                     
                    {
                    Value.Set(-1);
                    // Use this method for calculating your indicator values. Assign a value to each
                    // plot below by replacing 'Close[0]' with your own formula.
                    if (CrossAbove(High[0], SMA(50), 1) || CrossBelow(Low[0], SMA(50), 1))
                    Value.Set(1);
                    else
                    Value.Set(-1); 
                    }
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks again Bertrand. That worked. Looks like my syntax was incorrect.

                      A related question... when I add the following code:
                      if ((High[0] >= SMA(20)) || (Low[0] <= SMA(20)))

                      I get the following error:
                      "Operator '<=' cannot be applied to operands of type 'double'"

                      Any suggestions on how I can make this comparison if that is the case? I'm trying not to use the CrossOver() function, as I'm really interested in seeing if price "touches" a moving average.

                      Thanks.

                      Comment


                        #12
                        Originally posted by fosch View Post
                        if ((High[0] >= SMA(20)) || (Low[0] <= SMA(20)))
                        Please try:
                        Code:
                        if ((High[0] >= SMA(20)[0]) || (Low[0] <= SMA(20)[0]))
                          // do something
                        The SMA() function returns a DataSeries, which is a big, long list of double values, but it looks like you are only interested in the most recent value, which can be accessed with the [0] indexer.

                        I wrote a reference page last summer for when to use the square brackets [], which can be found here.
                        AustinNinjaTrader Customer Service

                        Comment


                          #13
                          Thanks Austin. I will try to put all of this together later tonight.

                          Comment


                            #14
                            Originally posted by NinjaTrader_Bertrand View Post
                            You would need to assign a value differently when using the DataSeries.Set() method, my change below should compile well -

                            Code:
                             
                            {
                            Value.Set(-1);
                            // Use this method for calculating your indicator values. Assign a value to each
                            // plot below by replacing 'Close[0]' with your own formula.
                            if (CrossAbove(High[0], SMA(50), 1) || CrossBelow(Low[0], SMA(50), 1))
                            Value.Set(1);
                            else
                            Value.Set(-1); 
                            }
                            please..can you save this as an indicator..(or instruct me on how to).so i can use..it is perfect for what i need to do on market analyzer...

                            Comment


                              #15
                              mystiq, I'll ask our NinjaScript trainee to work on a conversion / demo script for you as a courtesy.
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              435 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              18 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by frslvr, 04-11-2024, 07:26 AM
                              9 responses
                              126 views
                              1 like
                              Last Post caryc123  
                              Started by selu72, Today, 02:01 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Zachary  
                              Working...
                              X