Overall Statistics
from NodaTime import DateTimeZone
from datetime import datetime
import decimal as d
import pandas as pd

class ForexVolumeAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetCash(2000)
        self.SetStartDate(2015,1,01)
        self.SetEndDate(2017,11,01)
 
        self.syl = self.AddForex("EURUSD", Resolution.Hour, Market.FXCM).Symbol
        self.Securities[self.syl].FeeModel = FxcmTransactionModel()
        self.SetTimeZone(DateTimeZone.Utc)
        self.vol_syl = self.AddData[FxcmVolume]("EURUSD_Vol", Resolution.Hour).Symbol
 
        self.macd = self.MACD(self.syl, 12, 26, 9, MovingAverageType.Exponential, Resolution.Hour)
        self.vol_bb = self.BB(self.vol_syl, 30, 2, MovingAverageType.Exponential, Resolution.Hour)
        

    def OnData(self, data):
        if self.macd.IsReady and self.vol_bb.IsReady:
            if not self.vol_syl in data: return
      
            volume = data[self.vol_syl].Volume
            
            if not self.Portfolio.Invested:
                if self.macd.Current.Value > self.macd.Signal.Current.Value and volume > self.vol_bb.UpperBand.Current.Value:  
                    self.Buy(self.syl, 1000)
            if self.Portfolio.Invested:
                if self.macd.Current.Value < self.macd.Signal.Current.Value and volume > self.vol_bb.UpperBand.Current.Value: 
                    self.Liquidate()