Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
0.002%
Drawdown
0.000%
Expectancy
0
Net Profit
0.001%
Sharpe Ratio
0.141
Probabilistic Sharpe Ratio
25.544%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0.001
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-0.149
Tracking Error
0.078
Treynor Ratio
0.011
Total Fees
$0.00
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 *
from QuantConnect.Indicators import ExponentialMovingAverage

class ScheduledEventsAlgorithm(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2020, 1, 1)  # Set Start Date
        self.SetEndDate(2020, 6, 22) # Set end date
        self.SetCash(100000000)  # Set Strategy Cash
        self.forex = self.AddForex("EURUSD", Resolution.Minute, Market.Oanda)
        self.SetBrokerageModel(BrokerageName.OandaBrokerage)
        self.EMA5 = ExponentialMovingAverage(5)
        self.RegisterIndicator("EURUSD", self.EMA5, timedelta(minutes=5))
        self.EMA40 = ExponentialMovingAverage(40)
        self.RegisterIndicator("EURUSD", self.EMA40, timedelta(minutes=5))
        self.SetBenchmark("EURUSD")
        self.SetWarmUp(55)
        self.Schedule.On(self.DateRules.Every(DayOfWeek.Monday, DayOfWeek.Tuesday), self.TimeRules.At(6,0), self.SpecificTime)
        self.entryTicket=None
        self.stopLimitTicket=None
        self.stopMarketTicket=None
    def OnData(self, data):
        if self.IsWarmingUp:
            return
            #self.SetHoldings("USDCAD", 50)
    
    def SpecificTime(self):
        self.Plot('Custom', 'EMA5', self.EMA5.Current.Value)
        self.Plot('Custom', 'EMA40', self.EMA40.Current.Value)
        #if not self.Portfolio.Invested:
        if self.entryTicket==None:
            close=self.Securities["EURUSD"].Close
            if self.EMA5.Current.Value>self.EMA40.Current.Value:
                self.entryTicket=self.MarketOrder("EURUSD", 100000)
                #self.stopLimitTicket = self.LimitOrder("EURUSD", -100000, (close+0.0011))
                #self.stopMarketTicket = self.StopMarketOrder("EURUSD", -100000, (close-0.0005))
            #f self.EMA5.Current.Value<self.EMA40.Current.Value:
                #elf.MarketOrder("EURUSD", -100000)
                #self.stopLimitTicket = self.LimitOrder("EURUSD", 100000, (close-0.0011))
                #self.stopMarketTicekt = self.StopMarketOrder("EURUSD", 100000, (close+0.0005))
        
    def OnOrderEvent(self, orderEvent):
        if orderEvent.Status != OrderStatus.Filled:
            return
        if self.entryTicket != None and self.entryTicket.OrderID == orderEvent.OrderID:
            self.stopLimitTicket=self.LimitOrder("EURUSD", -100000, (close+0.0011))
            self.stopMarketTicket=self.StopMarketOrder("EURUSD", -100000, (close-0.0005))
        if self.stopLimitTicket !=None and self.stopLimitTicket.OrderID == orderEvent.OrderID:
            self.stopMarketTicket.Cancel()
            self.entryTicket=None
        if self.stopMarketTicket !=None and self.stopMarketTicekt.OrderID == orderEvent.OrderID:
            self.stopLimitTicket.Cancel()
            self.entryTicket=None