Overall Statistics
import numpy as np

class BasicTemplateAlgorithm(QCAlgorithm):

    def Initialize(self):

        self.instrument_id = "USDJPY"
        self.N1,self.N2= 150, 20
        self.SetStartDate(2016,1,1)  #Set Start Date
        self.SetEndDate(2016,1,10)    #Set End Date
        self.SetCash(10000)           #Set Strategy Cash

        self.SetBrokerageModel(BrokerageName.OandaBrokerage, AccountType.Margin)

        self.AddForex(self.instrument_id, Resolution.Tick)

        self.SetBenchmark(self.instrument_id)
        self.Securities[self.instrument_id].SetLeverage(50)

        ## Need to declare consolidator as Tick QuoteBar Consolidator so it can handle Tick objects, rather thank QuoteBar which would
        ## be the appropriate type for anything with a coarser resolution than tick
        ## Note that if your tick data was for a security supporting TradeBars, then the proper consolidator would be TickConsolidator

        consolidator = TickQuoteBarConsolidator(TimeSpan.FromMinutes(30)) ## force consolidator to produce 30 minute bars
        consolidator.DataConsolidated += self.OnCandle
        self.SubscriptionManager.AddConsolidator(self.instrument_id, consolidator)
        
    
    def OnData(self, data):
        ## Any trading code in here will be at the tick level
        pass
        
    def OnCandle(self, sender, bar):
        ## Any trading code in here will be at the minute level
        self.Log('New 30M bar >> Bid Close price: ' + str(bar.Bid.Close))