Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to determine if SMA is moving up or down

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

    How to determine if SMA is moving up or down

    Hi,
    I'm trying to code if a moving average is moving up or down rather than sideways and am using the following code (this is for UP) as part of overall code. But it doesn't seem to execute the any trades. When i remove this line it works fine it trades fine, but then it really doesn't allow me to take a trend into my criteria. Any assist?

    SMA(25)[0] - SMA(25)[2] >= 2

    #2
    krakken, it is best to break down lines of code as simple as possible. It looks like you want to check if the current SMA value is two points higher than the SMA from two bars ago. The check would thus be:
    Code:
    if ((SMA(25)[0] + 2) > SMA(25)[2])
    // up trend
    AustinNinjaTrader Customer Service

    Comment


      #3
      thanks. Also, curious...Does SMA(25)[0] - SMA(25)[2] >= 2*TickSize work the same way? I don't have ticksize defined anywhere and assuming it's default value is 1? I tried this way and it did execute trades, but want to make sure it was the right usage.

      Comment


        #4
        krakken, be sure to use as many parenthesis as necessary to fully define your statements. I'm not sure how the statement would read and execute without any parenthesis.

        TickSize is common to all strategies and indicators and is set automatically to the minimum price fluctuation for the instrument it is running on.
        AustinNinjaTrader Customer Service

        Comment


          #5
          I use
          if (SMA(25)[0] > SMA(25)[1])
          {
          Print ("SMA = UP");
          }
          if (SMA(25)[0] < SMA(25)[1])
          {
          Print ("SMA = Down");
          }

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          105 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          53 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          35 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          38 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          74 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X