Overall Statistics
from System import *
from QuantConnect import *
from QuantConnect.Data.Consolidators import *
from QuantConnect.Data.Market import *
from QuantConnect.Orders import OrderStatus
from QuantConnect.Algorithm import QCAlgorithm
from QuantConnect.Indicators import *
import numpy as np
from datetime import timedelta, datetime


class RollingWindowAlgorithm(QCAlgorithm):

    def Initialize(self):
       

        self.SetStartDate(2013,10,1)  
        self.SetEndDate(2017,11,1)   
        self.SetCash(100000)           
       

        ForexSymbols = ["EURUSD", "USDJPY"]
                
        for symbol in ForexSymbols:
            
           self.AddForex(symbol, Resolution.Daily)


        self.SMA("EURUSD", 9).Updated += self.SmaUpdated

        self.SMA("USDJPY", 9).Updated += self.SmaUpdated

        self.smaWin = RollingWindow[IndicatorDataPoint](9)

        self.window = RollingWindow[QuoteBar](2)
        

        
    def SmaUpdated(self, sender, updated):

        self.smaWin.Add(updated)

        


    def OnData(self, data):
        
        self.window.Add(data["EURUSD"])
        
        holdingseurusd = self.Portfolio["EURUSD"].Quantity
        
        
        if not (self.window.IsReady and self.smaWin.IsReady): return
        
        CurrentBar = self.window[0]                     
        PastBar = self.window[1]                     
       

        currSma = self.smaWin[0]                     
        pastSma = self.smaWin[1]  
       

        if holdingseurusd <= 0 and currSma.Value > pastSma.Value:
            self.SetHoldings("EURUSD", 1)