Overall Statistics
from Alphas.EmaCrossAlphaModel import EmaCrossAlphaModel
from datetime import datetime,timedelta
import numpy as np
from System.Collections.Generic import List
from QuantConnect.Data.UniverseSelection import*
from System import *


#class ResistanceMultidimensionalReplicator(QCAlgorithm):
class ScheduledEventsAlgorithm(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2020, 1, 1)  # Set Start Date
        self.SetEndDate(2020, 6, 22) # Set end date
        self.SetCash(1000000)  # Set Strategy Cash
        self.forex = self.AddForex("USDCAD", Resolution.Minute, Market.Oanda)
        self.SetBrokerageModel(BrokerageName.OandaBrokerage)
        self.EMA8 = self.EMA("USDCAD", 8, Resolution.Minute)
        self.EMA55 = self.EMA("USDCAD", 55, Resolution.Minute)
        self.SetBenchmark("USDCAD")
        self.SetWarmUp(55)
        self.Schedule.On(self.DateRules.Every(DayOfWeek.Monday), self.TimeRules.At(0, 24), self.SpecificTime)
    def OnData(self, data):
        if self.IsWarmingUp:
            return
            #self.SetHoldings("USDCAD", 50)
    def SpecificTime(self):
        self.Plot('Custom', 'EMA8', self.EMA8.Current.Value)
        self.Plot('Custom', 'EMA55', self.EMA55.Current.Value)
        if not self.Portfolio.Invested:
            if self.EMA8.Current.Value>self.EMA55.Current.Value:
                self.MarketOrder("USDCAD", 100000)
                self.stopLimitTicket = self.LimitOrder("USDCAD", -100000, self.Securities["USDCAD"].Close+0.0011)
            if self.EMA8.Current.Value<self.EMA55.Current.Value:
                self.MarketOrder("USDCAD", -100000)
                self.stopLimitTicket = self.LimitOrder("USDCAD", 100000, self.Securities["USDCAD"].Close-0.0011)