forked from mementum/bta-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |