Firetron’s Median

3 862 Views 1 Comment 4 years ago
  • Finds the middle value of a table of values. If there is an even number of elements, takes the average of the 2 middle values.

    Custom Command Dependencies:
    None

    Test Code:

    if not Load('done', false) then
    
      local table = Grab(ClosePrices(), 0, 9)
    
      Log(' ')
      Log(table)
      Log('Unsorted Table:')
      Log(' ')
    
      Log(ArraySort(table))
      Log('Sorted Table:')
      Log(' ')
    
      local median = CC_Median(table)
    
      Log(median)
      Log('Median Value:')
      Log(' ')
    
      Save('done', true)
    
    end
    HaasScript Code
    Sign in or Register to download for free
    • #2145
      Firetron
      Basic
      Up
      0
      Down
      ::

      Now works for ListNumber input as well as Table input.
      Now has an isSorted param, which you can set to true if you already sorted your list, so the command won’t sort it again, redundantly.

Login or Register to Comment

Unlock your crypto trading potential

Create a free account and enjoy everything we have to offer.

Join for Free