anchor.diff:    Opened = Candle#candle{current_segment = Segment, open = Packet, high = Packet, low = Packet, close = Packet},
     candle_accumulate(Packet, Opened).
   
  +% Flush segment if data is collected
  +flush_segment(#candle{open = undefined} = Candle) ->
  +  % Segment is not opened, so do nothing
  +  {[], Candle};
  +
  +flush_segment(#candle{ref_time = RefTime, current_segment = Segment, period = Period,
  +    open = Open, high = High, low = Low, close = Close} = Candle)
  +when RefTime == start; RefTime == finish ->
  +  % User has requested specific reference time, so we return 5-tuple of {Time, Open, High, Low, Close}
  +  Timestamp = case RefTime of
  +    start -> Segment * Period;
  +    finish -> (Segment+1) * Period
  +  end,
  +  OHLC = {Timestamp, value(open, Open), value(high, High), value(low, Low), value(close, Close)},
  +  {[OHLC], empty(Candle)};
  +
   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}
  +  % By default, return every event as is
  +  Events = lists:sort([Open, High, Low, Close]), % UTC field is just after (common) type, so events are sorted chronologically
  +  {Events, empty(Candle)}.
  +
  +
  +empty(#candle{} = Candle) ->
  +  Candle#candle{
  +    open = undefined,
  +    high = undefined,
  +    low = undefined,
  +    close = undefined
     }.
   
   
  
positive.code: -record(candle, {
      type = md,
      period = 30000,
      current_segment,
      open,
      high,
  
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) ->
  