Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
import numpy as np
from datetime import datetime


class BasicTemplateAlgorithm(QCAlgorithm):
    '''Basic template algorithm simply initializes the date range and cash'''

    def Initialize(self):
        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
        
        self.symbols = ["EURUSD","EURAUD","GBPUSD","AUDUSD"]
        self.SetStartDate(2016, 1, 1)    #Set Start Date
        self.SetEndDate(2018, 6, 1)      #Set End Date
        self.SetCash(25000)             #Set Strategy Cash
        
        self.forex = self.AddForex(self.symbols[0], Resolution.Minute, Market.FXCM)
        self.SetBrokerageModel(BrokerageName.FxcmBrokerage)
        
        self.SetWarmup(100)
        
        # Trade 15m and 240m timeframes
        consolidator_15 = QuoteBarConsolidator(15)
        self.SubscriptionManager.AddConsolidator(self.symbols[0], consolidator_15)
        consolidator_240 = QuoteBarConsolidator(240)
        self.SubscriptionManager.AddConsolidator(self.symbols[0], consolidator_240)
        
        # Initiatialize indicators
        
        
        self._macd = MovingAverageConvergenceDivergence(self.symbols[0], 12, 26, 9, MovingAverageType.Exponential)
        self._macdTrend = MovingAverageConvergenceDivergence(self.symbols[0], 12, 26, 9, MovingAverageType.Exponential)
        
        
        self.RegisterIndicator(self.symbols[0], self._macd, consolidator_15)
        self.RegisterIndicator(self.symbols[0], self._macdTrend, consolidator_240)
        
        self._macdTrend.Updated += self.MacdUpdated
        self._macdWindow =  RollingWindow[IndicatorDataPoint](3)
        
        self.__previous = datetime.min
       

    def OnData(self, data):
        
        if self.IsWarmingUp: return 
            
        # only once per day
        if self.__previous.date() == self.Time.date(): return

         # wait for our macd to fully initialize
        if not ( self._macd.IsReady and self._macdTrend.IsReady) : return
        
        self._macdTrend.Previous = self._macdWindow[1]
        
        #self.Debug(self._macd.Current.Value)
        #self.Debug(self._macdTrend.Previous.Value)
        #self.Debug(self._macdTrend)
        # Problem code here on self._macdTrend.Previous
        if (self._macdTrend.Current.Value > 0) and (self._macd.Current.Value > self._macdTrend.Previous.Value):
            trendMACDUp = True
        else:
            trendMACDUp = False
        self.Debug(str(trendMACDUp))
        
        self.__previous = self.Time
        
    def MacdUpdated(self, sender, updated):
        self._macdWindow.Add(updated)