New Members: Be sure to confirm your email address by clicking on the link that was sent to your email inbox. You will not be able to post messages until you click that link.

Scanning for New High/Low within x number of days


I am trying to write a code for a new 63 day high close any time within the last 20 days and conversely a new 63 day low close within the last 20 days. Is this possible and practical bearing in mind the number of permutations?

Best Answer

  • Options
    markdmarkd mod
    edited February 2016 Answer ✓
    I'm assuming you want both events to occur within the last twenty days. You could test for the max 20 day close equal to the max 63 day close, and the min 20 day close equal to the min 63 day close. That should catch any permutation. Note the 20 days and the 63 days includes the most current close, so if you run the scan during the day, and set the starting day to the most recent intraday update, the scan will count today as one of the 20 and 63 days. If you don't want that, set the starting day to the last closing date. You will probably get some hits where the high occurs first and others where the low occurs first.


  • Options
    Actually it was for 2 separate scans as part of an Up-trend and Down-trend. I thought I may have to write out 20 lines of text but using [max (20, close) = max (63, close)] and [min (20, close) = min (63, close)] does the job fine.

    I also wanted the same on a week basis and eventually got to [weekly max (14, close) = weekly max (52, close)] after trying to figure out where to put the word weekly.
  • Options
    markdmarkd mod
    edited February 2016
    Hi @dtrade01 , glad that worked out for you.

    My understanding from @gord is you have to specify the time frame for every term, otherwise the scan engine assumes the default, which is daily. So for weekly it would be:

    weekly max(14, weekly close) = weekly max(52, weekly close)

    I'm not sure this makes a practical difference if you run the scan after Friday's close, because Friday's daily close is also the weekly close (unless it's a holiday).

    But, if you run a weekly close during the week, it takes the most recent update as the weekly close (regardless of whether you specify weekly). If you run the scan as of yesterday's close, and yesterday is not Friday, it uses the daily close as the weekly close, even though the week is not over. So when you run the scan, to get true weekly results - that is, data for a full week for the last data element - you need to set the start date to the close of the most recent Friday (or last day of the week that was not a holiday).
  • Options
    Thanks mark. That did made a difference to the numbers when running the scan Monday as opposed to Friday.
Sign In or Register to comment.