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

MAX and MRO functions

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

    MAX and MRO functions

    Hello,

    I would like to use the MAX() and MRO(() functions to find the max high since a crossover condition

    I have come up with
    Code:
    XOverBarsAgo = MRO(() => CrossAbove(Close, EMA(Close, 20), 100), 1, 50);
    I have a Print function in place but it returns a value of zero for all bars. Are crossover conditions able to be evaluated in an MRO function?

    After this is working correctly I would like to pass the output of the MRO function to the MAX function to find the MAX(high) since the crossover occured.

    I have come up with

    Code:
    MAX(High, XOverBarsAgo < 1 ? 1 : XOverBarsAgo)[0];
    Does this look like it would work if the MRO function is corrected?

    Thanks

    #2
    Hello MisterGee,

    Thanks for your post.

    I've attached an example of a test using your code (except I changed the look back for the crossover from 100 to 1). In the example, I also waited until I had real-time bars just to ensure we had plenty of bars to work with.

    In the chart, the arrow shows the bar that is when the cross condition was detected (actually the bar before but this was using Calculate.OnBarClose).

    In the center, the print output showing the "bars ago" and the highest value from those bars ago, Note: The currently forming bar is higher but had not closed when I took the screenshot so it is not yet included but surely would be on the next run of the code. So the highest high prior to the right edge forming bar is the 5th bar back from that.

    Click image for larger version

Name:	mistergee-1.PNG
Views:	256
Size:	107.4 KB
ID:	1154707



    An alternate way to do this would be to use the cross event to reset a double type variable that you can use to hold the high value, something like this:

    if (Crossabove(EMA(20), Close, 1)
    {
    latestHigh = 0.0; // reset with new cross
    }
    lif (High[0] > latestHigh)
    {
    latestHigh = High[0]; // save the new high
    }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your time and testing Paul.

      Am I to assume then that the code I have supplied will work as desired?

      Edit: It does appear though upon further inspection of your image that the crossover happened 20 bars ago (including the furthest right bar) but your output window says 14?
      Last edited by MisterGee; 05-05-2021, 09:33 AM.

      Comment


        #4
        Hello MisterGee,

        Thanks for your reply.

        You can see what I tested with which was your code with a modification to the lookback of the crossover.

        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by andrewtrades, Today, 04:57 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        3 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
        7 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X