1#!/usr/bin/env python
2# -*- coding: utf-8; py-indent-offset:4 -*-
3###############################################################################
4#
5# Copyright (C) 2016 Daniel Rodriguez
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#
20###############################################################################
21from __future__ import (absolute_import, division, print_function,)
22#                        unicode_literals)
23
24import backtrader as bt
25
26
27class PivotPoint1(bt.Indicator):
28    lines = ('p', 's1', 's2', 'r1', 'r2',)
29
30    def __init__(self):
31        h = self.data.high(-1)  # previous high
32        l = self.data.low(-1)  # previous low
33        c = self.data.close(-1)  # previous close
34
35        self.lines.p = p = (h + l + c) / 3.0
36
37        p2 = p * 2.0
38        self.lines.s1 = p2 - h  # (p x 2) - high
39        self.lines.r1 = p2 - l  # (p x 2) - low
40
41        hilo = h - l
42        self.lines.s2 = p - hilo  # p - (high - low)
43        self.lines.r2 = p + hilo  # p + (high - low)
44
45
46class PivotPoint(bt.Indicator):
47    lines = ('p', 's1', 's2', 'r1', 'r2',)
48    plotinfo = dict(subplot=False)
49
50    def __init__(self):
51        h = self.data.high  # current high
52        l = self.data.low  # current high
53        c = self.data.close  # current high
54
55        self.lines.p = p = (h + l + c) / 3.0
56
57        p2 = p * 2.0
58        self.lines.s1 = p2 - h  # (p x 2) - high
59        self.lines.r1 = p2 - l  # (p x 2) - low
60
61        hilo = h - l
62        self.lines.s2 = p - hilo  # p - (high - low)
63        self.lines.r2 = p + hilo  # p + (high - low)
64