original_docstring: 
          Callback of new bar data update.
          
docstring: Callback of new bar data update.
docstring_tokens: Callback of new bar data update .
code: def on_bar(self, bar: BarData):
          """
          Callback of new bar data update.
          """
          self.cancel_all()
  
          self.bars.append(bar)
          if len(self.bars) <= 2:
              return
          else:
              self.bars.pop(0)
          last_bar = self.bars[-2]
  
          if last_bar.datetime.date() != bar.datetime.date():
              if self.day_high:
                  self.range = self.day_high - self.day_low
                  self.long_entry = bar.open_price + self.k1 * self.range
                  self.short_entry = bar.open_price - self.k2 * self.range
  
              self.day_open = bar.open_price
              self.day_high = bar.high_price
              self.day_low = bar.low_price
  
              self.long_entered = False
              self.short_entered = False
          else:
              self.day_high = max(self.day_high, bar.high_price)
              self.day_low = min(self.day_low, bar.low_price)
  
          if not self.range:
              return
  
          if bar.datetime.time() < self.exit_time:
              if self.pos == 0:
                  if bar.close_price > self.day_open:
                      if not self.long_entered:
                          self.buy(self.long_entry, self.fixed_size, stop=True)
                  else:
                      if not self.short_entered:
                          self.short(self.short_entry,
                                     self.fixed_size, stop=True)
  
              elif self.pos > 0:
                  self.long_entered = True
  
                  self.sell(self.short_entry, self.fixed_size, stop=True)
  
                  if not self.short_entered:
                      self.short(self.short_entry, self.fixed_size, stop=True)
  
              elif self.pos < 0:
                  self.short_entered = True
  
                  self.cover(self.long_entry, self.fixed_size, stop=True)
  
                  if not self.long_entered:
                      self.buy(self.long_entry, self.fixed_size, stop=True)
  
          else:
              if self.pos > 0:
                  self.sell(bar.close_price * 0.99, abs(self.pos))
              elif self.pos < 0:
                  self.cover(bar.close_price * 1.01, abs(self.pos))
  
          self.put_event()
code_tokens: def on_bar ( self , bar : BarData ) : self . cancel_all ( ) self . bars . append ( bar ) if len ( self . bars ) <= 2 : return else : self . bars . pop ( 0 ) last_bar = self . bars [ - 2 ] if last_bar . datetime . date ( ) != bar . datetime . date ( ) : if self . day_high : self . range = self . day_high - self . day_low self . long_entry = bar . open_price + self . k1 * self . range self . short_entry = bar . open_price - self . k2 * self . range self . day_open = bar . open_price self . day_high = bar . high_price self . day_low = bar . low_price self . long_entered = False self . short_entered = False else : self . day_high = max ( self . day_high , bar . high_price ) self . day_low = min ( self . day_low , bar . low_price ) if not self . range : return if bar . datetime . time ( ) < self . exit_time : if self . pos == 0 : if bar . close_price > self . day_open : if not self . long_entered : self . buy ( self . long_entry , self . fixed_size , stop = True ) else : if not self . short_entered : self . short ( self . short_entry , self . fixed_size , stop = True ) elif self . pos > 0 : self . long_entered = True self . sell ( self . short_entry , self . fixed_size , stop = True ) if not self . short_entered : self . short ( self . short_entry , self . fixed_size , stop = True ) elif self . pos < 0 : self . short_entered = True self . cover ( self . long_entry , self . fixed_size , stop = True ) if not self . long_entered : self . buy ( self . long_entry , self . fixed_size , stop = True ) else : if self . pos > 0 : self . sell ( bar . close_price * 0.99 , abs ( self . pos ) ) elif self . pos < 0 : self . cover ( bar . close_price * 1.01 , abs ( self . pos ) ) self . put_event ( )
short_docstring: Callback of new bar data update.
short_docstring_tokens: Callback of new bar data update .
comment: """
          Callback of new bar data update.
          """