Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indicator #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions btalib/indicators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

# Volatility
from .atr import * # noqa: F401 F403
from .donchian import *

# Momentum
from .aroon import * # noqa: F401 F403
Expand Down
40 changes: 40 additions & 0 deletions btalib/indicators/donchian.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python
# -*- coding: utf-8; py-indent-offset:4 -*-
###############################################################################
# Use of this source code is governed by the MIT License
###############################################################################
from . import Indicator


class donchian(Indicator):
'''
The Donchian channel is an indicator used in market trading developed by Richard Donchian.

It is formed by taking the highest high and the lowest low of the last n periods. The area between the high and the low is the channel for the period chosen.

Formula:
- top = max(high)
- bottom = min(low)
- mid = bottom + (top - bottom)/2

See:
- https://en.wikipedia.org/wiki/Donchian_channel
'''

group = 'volatility'

inputs = ('high', 'low',)

alias = 'DONCHIAN', 'DonchianChannel', 'DONCHIANCHANNEL'

outputs = 'top', 'bot', 'mid'

params = (
('period', 20, 'Period to consider'),
)

def __init__(self):

self.o.top = top = self.i.high.rolling(window=self.p.period).max()
self.o.bot = bot = self.i.low.rolling(window=self.p.period).min()
self.o.mid = bot + (top - bot)/2