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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        152 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        87 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        131 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        127 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        106 views
        0 likes
        Last Post CarlTrading  
        Working...
        X