Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Determining if SMA peak is greater than a previous peak

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

    Determining if SMA peak is greater than a previous peak

    Hi!

    I'm new to this so thanks for your assistance in advance.

    I'm trying to determine if the SMA(10) is indicating a trend. I would like to define a trend by saying the most recent peak must be higher than the previous peak, and the most current trough is higher than the previous trough.

    I'm struggling to understand how I would code this though...

    How could I define current/previous peaks and troughs?

    Are there any inbuilt functions that could be used? i.e. can I use the slope of the SMA line? or would I need to check that the SMA(10) on a particular bar is greater (for peak) or less than (for trough) both the next x bars, and previous x bars?

    Hope I am making sense, and thanks for any help you can provide

    #2
    Hello matth1,
    Welcome to the forum and I am happy to assist you.

    You can use the ZigZag indicator to find the recent peaks of the SMA.
    Code:
    int zzPreHigh = ZigZag(SMA(14), DeviationType.Points, .05, false).HighBar(0,2, 100);
    int zzLastHigh = ZigZag(SMA(14), DeviationType.Points, .05, false).HighBar(0, 1, 100);
    			
    if (High[zzPreHigh] > High[zzLastHigh])
    {
      //do something
    }


    You can use the Slope function to check the slope of the SMA. You can find the Rising and Falling function handy.




    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Originally posted by matth1 View Post
      Hi!

      I'm new to this so thanks for your assistance in advance.

      I'm trying to determine if the SMA(10) is indicating a trend. I would like to define a trend by saying the most recent peak must be higher than the previous peak, and the most current trough is higher than the previous trough.

      I'm struggling to understand how I would code this though...

      How could I define current/previous peaks and troughs?

      Are there any inbuilt functions that could be used? i.e. can I use the slope of the SMA line? or would I need to check that the SMA(10) on a particular bar is greater (for peak) or less than (for trough) both the next x bars, and previous x bars?

      Hope I am making sense, and thanks for any help you can provide
      Use the Swing() indicator. Pretty much its sole purpose is to indicate peaks and valleys.

      Comment


        #4
        Excellent. I'll look into all the methods mentioned here.

        Thanks

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        577 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
        553 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