def mergeticklists(list1, list2, mergeequal=1):
    """helper function to merge tick lists
    - return a merged list of ticks out of list1 and list2
    - CAUTION: original lists have to be ordered
      (the returned list is also ordered)"""
    list1 = list1[:]
    i = 0
    j = 0
    try:
        while True:
            while list2[j] < list1[i]:
                list1.insert(i, list2[j])
                i += 1
                j += 1
            if list2[j] == list1[i]:
                if mergeequal:
                    list1[i].merge(list2[j])
                j += 1
            i += 1
    except IndexError:
        if j < len(list2):
            list1 += list2[j:]
    return list1
