OutsideBar — Outside Bar
A bar whose range contains the previous bar’s entirely: an expansion that took out both sides. Often a reversal, always a widening of the trading range. Returns 1 when present.
Signature
OutsideBar(lookback, on=<source>)| Argument | Type | Required | Notes |
|---|---|---|---|
lookback |
int Param | Yes | Pinned at 1. Bounds 1–1. |
on= |
symbol | No | Source symbol. Defaults to the trade symbol. Reads high and low. |
Formula
$$ \text{OutsideBar} = 1 \text{ when } H_t \ge H_{t-1} \text{ and } L_t \le L_{t-1} $$
Warmup
One bar of state.
Reading the value
ob.valueob > 0Example
class OutsideBarReversal(Strategy): """Trade the direction an outside bar closed.""" trade = Symbol() sizing = FixedCapital()
def execute(self): ob = OutsideBar(1, on=self.trade) sma = SMA(50, on=self.trade) if ob.value > 0 and self.trade.close > sma.value and self.trade.is_flat: self.buy(self.trade, reason="Outside bar up") if self.trade.close < sma.value and self.trade.is_long: self.sell(self.trade, self.trade.position, reason="Trend lost")Notes
- Range-based, unlike
Engulfing, which compares bodies. They fire on different bars and mean different things. - Proven by an assert-via-trade run on SPY daily (matched a strategy-side reference exactly on every bar; zero alarm trades).