Overall Statistics
Total Trades
9
Average Win
0%
Average Loss
-0.09%
Compounding Annual Return
-21.792%
Drawdown
8.300%
Expectancy
-1
Net Profit
-4.003%
Sharpe Ratio
-1.228
Probabilistic Sharpe Ratio
12.657%
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.189
Beta
-0.536
Annual Standard Deviation
0.123
Annual Variance
0.015
Information Ratio
-0.446
Tracking Error
0.181
Treynor Ratio
0.282
Total Fees
$9.00
Estimated Strategy Capacity
$1000.00
Lowest Capacity Asset
BTC TLQHZ0DZBGPX
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from QuantConnect.Data.Market import TradeBar
import numpy


BO = 20
SO = 10
take_profit = 5
stop_loss = 0
budget = 6000


class RollingWindowAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 8, 1)  #Set Start Date
        self.SetEndDate(2021, 9, 30)   #Set End Date
        self.SetCash(budget)           #Set Strategy Cash
        self.eurusd = self.AddEquity("BTC", Resolution.Minute)
        #self.SetTimeZone("Europe/Rome")
        
        self.rsi = self.RSI("BTC", 7)
        
        # set warmup period
        self.SetWarmUp(7)

    def OnData(self, data):
        if not (self.rsi.IsReady):
            return

        # Current price
        price = self.Securities["BTC"].Price
        
        # Calculate
        lower = self.Securities["BTC"].Price * 1
        
        #take_profit at 5%
        higher = self.Securities["BTC"].Price * (1 + (take_profit/100))
        
        # Calculate quantity
        holdings = self.Portfolio["BTC"].Quantity

        if not self.Portfolio.Invested:
            if self.rsi.Current.Value < 30:
                self.SetHoldings("BTC", (BO/100))
                holdings = self.Portfolio["BTC"].Quantity
                self.LimitOrder("BTC", -holdings, lower)
                self.Debug("BO order was placed")
                self.StopMarketOrder("BTC", -holdings, higher)
                self.Debug("Take Profit")
                
                
            if self.rsi.Current.Value < 20:
                self.SetHoldings("BTC", (SO/100))
                holdings = self.Portfolio["BTC"].Quantity
                self.LimitOrder("BTC", -holdings, lower)
                self.Debug("SO order was placed")
                self.StopMarketOrder("BTC", -holdings, higher)
                self.Debug("Take Profit")
            
    ### Cancel remaining order if limit order or stop loss order is executed
    def OnOrderEvent(self, orderEvent):
        order = self.Transactions.GetOrderById(orderEvent.OrderId)
        
        if order.Status == OrderStatus.Filled:
            if order.Type == OrderType.Limit or order.Type == OrderType.Limit:
                self.Transactions.CancelOpenOrders(order.Symbol)
                
        if order.Status == OrderStatus.Canceled:
            self.Log(str(orderEvent))