Overall Statistics
Total Trades
4
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$30000000.00
Lowest Capacity Asset
ETHUSD XJ
# region imports
from AlgorithmImports import *
# endregion

class DeterminedAsparagusManatee(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 6, 22)  # Set Start Date
        self.SetEndDate(2020, 6, 23)
        self.SetCash(100000)  # Set Strategy Cash
        self.ethusd = self.AddCrypto("ETHUSD", Resolution.Minute).Symbol

        self.window = RollingWindow[Decimal](2)

        self.vwap = self.VWAP(self.ethusd)

        self.p1 = 0.01
        self.p2 = 0.02

        stockplot = Chart("TradePlot")
        stockplot.AddSeries(Series("Price", SeriesType.Line, 0))
        stockplot.AddSeries(Series("VWAP", SeriesType.Line, 0))
        self.AddChart(stockplot)
      
    def OnData(self, data: Slice):

        self.window.Add(data[self.ethusd].Close)

        if not self.window.IsReady:
            return

        pnl = self.Securities[self.ethusd].Holdings.UnrealizedProfitPercent
        
        self.Plot("TradePlot", "Price", self.Securities[self.ethusd].Close)
        self.Plot("TradePlot", "VWAP", self.vwap.Current.Value)

        currentclose = self.window[0]
        pastclose = self.window[1]
        vwap = self.vwap.Current.Value

        if not self.Portfolio.Invested:
            if pastclose < vwap and currentclose > vwap:
                self.Buy(self.ethusd, 1)
            
            elif pastclose > vwap and currentclose < vwap:
                self.Sell(self.ethusd, 1)
        
        elif self.Portfolio.Invested:
                if pnl > self.p2 or pnl < -self.p1:
                    self.Liquidate(self.ethusd)