Skip to content

Commit

Permalink
Add indicator(mementum#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
elidioxg committed Aug 21, 2021
1 parent b4bdc32 commit 2955561
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
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

0 comments on commit 2955561

Please sign in to comment.