Skip to content

Commit

Permalink
Generalize AccelerationDecelerationOscillator and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mementum committed Jun 11, 2017
1 parent 465a816 commit b189642
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 14 deletions.
32 changes: 18 additions & 14 deletions backtrader/indicators/accdecoscillator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,38 @@
unicode_literals)

import backtrader as bt
from . import SMA
from . import AO
from . import MovAv, AwesomeOscillator


__all__ = ['AccelerationDecelerationOscillator', 'AccDeOsc']


class AccelerationDecelerationOscillator(bt.Indicator):
'''
Acceleration/Deceleration Technical Indicator (AC) measures acceleration and
deceleration of the current driving force. This indicator will change
Acceleration/Deceleration Technical Indicator (AC) measures acceleration
and deceleration of the current driving force. This indicator will change
direction before any changes in the driving force, which, it its turn, will
change its direction before the price.
Formula:
- MEDIAN PRICE = (HIGH + LOW) / 2
- AO = SMA (MEDIAN PRICE, 5) - SMA (MEDIAN PRICE, 34)
- AC = AO - SMA (AO, 5)
- AcdDecOsc = AwesomeOscillator - SMA(AwesomeOscillator, period)
See:
- https://www.metatrader5.com/en/terminal/help/indicators/bw_indicators/ao
- https://www.ifcmarkets.com/en/ntx-indicators/ntx-indicators-accelerator-decelerator-oscillator
'''
alias = ('AC', )
lines = ('ac', )
alias = ('AccDeOsc',)
lines = ('accde', )

plotlines = dict(ac=dict(_method='bar'))
params = (
('period', 5),
('movav', MovAv.SMA),
)

def __init__(self):
plotlines = dict(accde=dict(_method='bar', alpha=0.50, width=1.0))

ao = AO()
#self.l.ac = ao - SMA(ao, 5)
self.l.ac = ao - SMA(ao, period=5)
def __init__(self):
ao = AwesomeOscillator()
self.l.accde = ao - self.p.movav(ao, period=self.p.period)
super(AccelerationDecelerationOscillator, self).__init__()
49 changes: 49 additions & 0 deletions tests/test_ind_accdecosc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python
# -*- coding: utf-8; py-indent-offset:4 -*-
###############################################################################
#
# Copyright (C) 2015, 2016 Daniel Rodriguez
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import testcommon

import backtrader as bt

chkdatas = 1
chkvals = [
['-2.097441', '14.156647', '30.408335']
]

chkmin = 38
chkind = bt.ind.AccelerationDecelerationOscillator


def test_run(main=False):
datas = [testcommon.getdata(i) for i in range(chkdatas)]
testcommon.runtest(datas,
testcommon.TestStrategy,
main=main,
plot=main,
chkind=chkind,
chkmin=chkmin,
chkvals=chkvals)


if __name__ == '__main__':
test_run(main=True)

0 comments on commit b189642

Please sign in to comment.