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 andrewtrades, Today, 04:57 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          6 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          9 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          20 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X