Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
62.282%
Drawdown
2.000%
Expectancy
0
Net Profit
0%
Sharpe Ratio
3.513
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.015
Beta
0.941
Annual Standard Deviation
0.107
Annual Variance
0.011
Information Ratio
-1.587
Tracking Error
0.025
Treynor Ratio
0.398
Total Fees
$3.19
from QuantConnect.Data.Market import TradeBar

class RollingWindowAlgorithm(QCAlgorithm):
    '''Basic template algorithm simply initializes the date range and cash'''

    def Initialize(self):
        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
        
        self.SetStartDate(2013,10,1)   # Set Start Date
        self.SetEndDate(2013,11,1)     # Set End Date
        self.SetCash(100000)           # Set Strategy Cash
        self.AddEquity("SPY", Resolution.Daily)

		# Creates a Rolling Window indicator to keep the 2 TradeBar
        self.window = RollingWindow[TradeBar](2)


    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
        
        # Add SPY TradeBar in rollling window
        self.window.Add(data["SPY"])

        # Wait for window to be ready: needs two additions
        if not self.window.IsReady: return

        currBar = self.window[0]   # Current bar has index zero.
        pastBar = self.window[1]   # Past bar has index one.

        # Remember: avoid logging prices
        self.Log("{0} -> {1} ... {2} -> {3}".format(pastBar.Time, pastBar.Close, currBar.Time, currBar.Close))

        if not self.Portfolio.Invested and currBar.Close < pastBar.Close:
            self.SetHoldings("SPY", 1)