Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to program moving avg is Above or Below another

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

    How to program moving avg is Above or Below another

    How do i program if a set of moving averages is below or above another moving average to execute a trade. Not a crossabove or crossbelow. But simply above or below. I tried using the following but get an error:

    if (CrossAbove(LinReg(10), SMA(9), 1) && ToTime(Time[0]) >= ToTime(startHour, startMin, 0)
    && ToTime(Time[0]) <= ToTime(endHour, endMin, 0) && (LinReg(10) && SMA(9) > SMA(14)))
    {
    EnterLong(DefaultQuantity, "buy");

    #2
    Hi krakken,

    You can compare above or below using < or > operators.


    These types of expressions can be created using the strategy wizard condition builder, and is a good place to start if you are unsure the code syntax.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      I get the following compile error.
      Operator '>' cannot be applied to operands of type 'NinjaTrader.Indicator.SMA' and 'NinjaTrader.Indicator.SMA'

      Comment


        #4
        You need to apply indexing to the SMAs:
        SMA(9)[0] > SMA(14)[0]

        This expression can easily be created with your mouse in point and click strategy wizard. After you create it, click view code to see the syntax. Strategy wizard is great for identifying syntax for these types of conditions. You can still copy - paste the generated code into another script if you want to work in code.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thanks Ryan. That was it. You guys are a great support team...especially with Newbies like me!

          Comment


            #6
            Glad you were able to move forward on it. Thanks, krakken.
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

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