anchor.diff:  timestamp(#md{timestamp = Timestamp}) -> Timestamp;
   timestamp(#trade{timestamp = Timestamp}) -> Timestamp.
   
  +value(_, #trade{price = Price}) -> Price;
  +value(high, #md{ask = [{Ask, _}|_]}) -> Ask;
  +value(low,  #md{bid = [{Bid, _}|_]}) -> Bid;
  +value(_, #md{} = MD) -> (value(high, MD) + value(low, MD))/2.
   
   test_candle(Input) ->
     test_candle(Input, undefined).
  
positive.code:   Opened = Candle#candle{current_segment = Segment, open = Packet, high = Packet, low = Packet, close = Packet},
    candle_accumulate(Packet, Opened).
  
  flush_segment(#candle{open = Open, high = High, low = Low, close = Close} = Candle) ->
    Events = lists:sort([Open, High, Low, Close]),
    RealEvents = case Events of
      [undefined|_] -> []; % Tells us we have no events
      _ -> Events
    end,
    {RealEvents, Candle#candle{
        open = undefined,
        high = undefined,
        low = undefined,
        close = undefined}
    }.
  
  
  
negative.code: parse_options([{period, Period}|MoreOpts], #candle{} = Candle) ->
    parse_options(MoreOpts, Candle#candle{period = Period});
  parse_options([{type, Type}|MoreOpts], #candle{} = Candle) ->
    parse_options(MoreOpts, Candle#candle{type = Type});
  parse_options([{ref_time, RefTime}|MoreOpts], #candle{} = Candle) when RefTime == start; RefTime == finish ->
    parse_options(MoreOpts, Candle#candle{ref_time = RefTime}).
  
  
  candle(Event, undefined) ->
  