For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
One for the cookbook: On Balance Volume
-
@backtrader Not developed by myself but a valuable indicator. Credits go to backtest rookies
class OnBalanceVolume(bt.Indicator): alias = 'OBV' lines = ('obv') params = ( ('length', 12), ) plotlines = dict( obv=dict( _name='OBV', color='purple', alpha=0.50 ) ) def __init__(self): # Plot a horizontal Line self.plotinfo.plotyhlines = [0] def next(self): # Aliases to avoid long lines c = self.data.close v = self.data.volume obv = self.lines.obv if c[0] > c[-1]: obv[0] = obv[-1] + v[0] elif c[0] < c[-1]: obv[0] = obv[-1] - v[0] else: obv[0] = obv[-1]