Announcement

Collapse
No announcement yet.

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:	329
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
    }

    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.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        46 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        66 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X