areed1192 / python-trading-robot

A trading robot, that can submit basic orders in an automated fashion using the TD API.
MIT License
535 stars 312 forks source link

`bollinger_band` calculation method #13

Open Wolfslayer opened 3 years ago

Wolfslayer commented 3 years ago

Thanks for this project Alex! Awesome stuff.

Working on building a robot for tracking trades vs indicator readings and I noticed something looked funny with the bollinger_band indicator. Don't have much of a background in finance so it could be I'm misunderstanding something. You calculate the upper band as

self._frame['band_upper'] = 4 * (self._frame['moving_std'] / self._frame['moving_avg'])

which makes sense to me as 4 times the normalized standard dev, but then the lower band is calculated as

self._frame['band_lower'] = (
             (self._frame['close'] - self._frame['moving_avg']) +
              (2 * self._frame['moving_std']) /
              (4 * self._frame['moving_std'])
          )

Where that third term I believe just simplies to 1/2. I would've guessed based on how upper band is given that lower band would just be its negated version? Again, I'm a novice in finance so my thinking may just be incorrect here.