Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator

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

    Indicator

    Hi

    I have a indicator which monitors a number of bar formations but want to add an additional constraint which looks at 2 simple moving averages on a chart and checks to see if the shorter term SMA is above the longer term SMA and vice versa.

    How do i reference the SMA from the charts in the indicator programming language?

    Regards
    Ryebank

    #2
    Hi ryebank,

    To clarify, by "shorter term" are you referring to a shorter interval, such as a shorter time interval. Or are you referring to a smaller period SMA?

    You can access the SMA with the syntax described here - http://www.ninjatrader-support.com/H...vingAverageSMA
    TimNinjaTrader Customer Service

    Comment


      #3
      yes 14 period ma and 200 period ma on the same chart same time frame

      Comment


        #4
        as an example could i write

        <previous calculation> && (SMA(close,14) > SMA(close,200))

        Do i need to declare any variables?

        Do i need to add these columns to the market analyzer or will it reference historical data to see if the above condition is true?

        rye

        Comment


          #5
          Hi ryebank,

          If you are using this in an if statement, you could do something like...
          Code:
          if (SMA(14)[0] > SMA(200)[0])
          { 
          do something
          }
          Can you clarify what you are trying to do with the Market Anaylzer?
          TimNinjaTrader Customer Service

          Comment


            #6
            Ok that seems straight forward...

            MA is where my custom built indicator is running and provided alerts

            Can i edit my indicator from Tools > Edit NinjaScript > Indicator and will this update the current compiled version or do i have to reimport the indicator script once i've made a change?
            Last edited by ryebank; 07-06-2010, 02:24 PM.

            Comment


              #7
              would this work.....

              if (SMA(close, 14)[0] > SMA(close, 200)[0])
              {
              do something
              }

              Comment


                #8
                Hi ryebank,

                Correct, you can make the changes at "Tools>Edit NS>Indicator" then compile the indicator. Be sure to "Reload NinjaScript" once you're done. This can be done from the right click menu in both a chart or Market Analyzer.
                TimNinjaTrader Customer Service

                Comment


                  #9
                  SMA's

                  There’s an added complication I’ve thought of. I also need to check to see if the price is above or below the moving averages for example

                  if (Price > (SMA(close,14)[0] && SMA(close,200))[0] && (SMA(close,14)[0] > SMA(close,200)[0])) || (Price < (SMA(close,14)[0] && SMA(close,200)[0]) && (SMA(close,14)[0] < SMA(close, 200)[0]))
                  {
                  do something
                  }

                  what I’m trying to filter are alerts generated when the price is below both moving averages but SMA(14) is greater than SMA(200), so if this occurs I don’t want an alert as the price has to be above both SMA’s and SMA(14) has to be greater than SMA(200) and vice versa for shorts

                  How do I compare SMA’s against current price to ensure it’s above or below?

                  Is the logic correct and would it work programmatically?

                  Many thanks,
                  Ryebank

                  Comment


                    #10
                    Hi ryebank,

                    To compare price to something, you can simply use Close, for example you refer to the current price with Close[0]. This is of course with CalculateOnBarClose=false. On historical, or with COBC=true, Close[0] will refer to the close price.

                    More info at - http://www.ninjatrader-support.com/H...ide.html?Close
                    TimNinjaTrader Customer Service

                    Comment


                      #11
                      Compare price

                      Hi,

                      How do i compare the close of the last bar with the close of a bar x time ago for example how do i compare the close 15:00 (close[0]) bar with the close of a bar at 11:00 (close[3]) allowing for the fact that 11:00 is a fixed time and each subsequent bar needs to be compared against this - 15:00 (11:00), 16:00 (11:00), 17:00 (11:00)....?

                      Thanks
                      Ryebank

                      Comment


                        #12
                        ryebank,

                        You can use GetBar() to get the index value needed. Please see the example in the following link. It does pretty similar to what you want: http://www.ninjatrader.com/support/h...nt7/getbar.htm
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          GetBar

                          Hi,

                          Thanks for GetBar I now have it checking previous bars.

                          However, i do have a question. In DateTime i specify a day (2010, 8, 18, 11, 0 ,0). What happens when the day becomes (2010, 8, 19, 11, 0, 0) do I have to update the script each day or is there a way to use 'current day'?

                          Thanks
                          Rye

                          Comment


                            #14
                            Rye, you can access Time[0], which would be the time of the most recent bar, and you can grab the DateTime info from there.
                            Code:
                            int day = Time[0].Day;
                            int month = Time[0].Month;
                            int year = Time[0].Year;
                            
                            int second = Time[0].Second;
                            int minute = Time[0].Minute;
                            int hour = Time[0].Hour;
                            AustinNinjaTrader Customer Service

                            Comment


                              #15
                              daily

                              Hi

                              if SMA(Close,14)[0] grabs the closing value of the SMA on a 15 minute chart how do I compare it with the closing price of a SMA (same bar [0]) from a daily chart?

                              Cheers
                              Ryebank

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              579 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              334 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              554 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              551 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X