Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 fx.practic, 10-15-2013, 12:53 AM
        5 responses
        5,404 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by Shai Samuel, 07-02-2022, 02:46 PM
        4 responses
        95 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by DJ888, Yesterday, 10:57 PM
        0 responses
        8 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        159 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Yesterday, 09:29 PM
        0 responses
        8 views
        0 likes
        Last Post Belfortbucks  
        Working...
        X