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, MovingAverageType.Simple, Resolution.Minute)
        self.EMA55 = self.EMA("USDCAD", 55, MovingAverageType.Simple, Resolution.Minute)
        self.SetBenchmark("USDCAD")
        self.SetWarmUp(50)
        self.Schedule.On(self.DateRules.Every(DayOfWeek.Monday), self.TimeRules.At(00,24), self.SpecificTime)
    def OnData(self, data):
                if self.IsWarmingUp:
                    return
                    #self.SetHoldings("USDCAD", 50)
    def SpecificTime(self):
                if not self.Portfolio.Invested:
                    if self.EMA8.Current.Value>self.EMA55.Current.Value:
                        self.MarketOrder("USDCAD", 100000)
                        self.stopLimitTicket = self.StopLimitOrder("USDCAD", -100000, self.securities["USDCAD"].Close-0.0006, -100000, self.securities["USDCAD"].Close+0.0011)
                    if self.EMA8.Current.Value<self.EMA55.Current.Value:
                        self.MarketOrder("USDCAD", -100000)
                        self.stopLimitTicket = self.StopLimitOrder("USDCAD", 100000, self.securities["USDCAD"].Close+0.0006, 100000, self.securities["USDCAD"].Close-0.0011)