Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
-14.059%
Drawdown
0.100%
Expectancy
0
Net Profit
-0.124%
Sharpe Ratio
-10.051
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.017
Beta
0.175
Annual Standard Deviation
0.008
Annual Variance
0
Information Ratio
7.653
Tracking Error
0.036
Treynor Ratio
-0.448
Total Fees
$2.00
import decimal as d
from datetime import timedelta

class OrderTicketDemoAlgorithm(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2013, 10, 07)
        self.SetEndDate(2013, 10, 9)
        self.SetCash(10000)
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage,AccountType.Margin)
        
        self.EURUSD = self.AddForex("EURUSD", Resolution.Hour)
        self.SetBenchmark(self.EURUSD.Symbol)
        
        self.newTicket = None
        self.expiry = None
        

    def OnData(self, data):

        # Creating an Order:
        if not self.Portfolio.Invested and self.expiry is None:
            close = data[self.EURUSD.Symbol].Close
            StopLong = close + d.Decimal(0.003)
            LimitLong = StopLong + d.Decimal(0.0001)
            
            self.newTicket = self.StopLimitOrder(self.EURUSD.Symbol, 1000, StopLong, LimitLong)
            self.expiry = self.newTicket.Time + timedelta(hours=2)
            
            self.Log("Order: {0}. EXPIRY: {1}".format(self.newTicket, self.expiry))
            
        if self.expiry is None: return
        
        if self.newTicket is not None:
            if self.UtcTime >= self.expiry:
                self.newTicket.Cancel()
                self.newTicket = None
                self.expiry = None
                self.Log("Order Expired: self.Time >= self.expiry")
                

    def OnOrderEvent(self, orderEvent):
        if orderEvent.Status != OrderStatus.Filled: return
    
        # if filled, set expiry to None in order to be able to create a new order
        self.expiry = None
        order = self.Transactions.GetOrderById(orderEvent.OrderId)
        self.Log("{0}: {1}: {2}".format(self.Time, order.Type, orderEvent))


    def TimeIs(self, day, hour, minute):
        return self.Time.day == day and self.Time.hour == hour and self.Time.minute == minute