Overall Statistics
Total Trades
0
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
-2.742
Tracking Error
0.179
Treynor Ratio
0
Total Fees
$0.00
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Indicators")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect.Data import *
from QuantConnect.Data.Market import *
from QuantConnect.Data.Consolidators import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from QuantConnect.Securities import *
from QuantConnect.Orders import *
from datetime import datetime
from System.Drawing import Color
from QuantConnect import *

import decimal as d
import numpy as np

class HMAStrat(QCAlgorithm):
    
    def Initialize(self):
        
        # configuration parameters (configurable inputs into the algorithm)
        DEBUG_LOG = str(self.GetParameter("Debug Log")).lower() == "true" or False
        SYMBOL = str(self.GetParameter("Symbol"))
        HMALENGTH = int(self.GetParameter("HMA Length")) or 50

        self.ORDER_MAP = ["Market", "Limit", "StopMarket", "StopLimit", "MarketOnOpen", "MarketOnClose", "OptionExercise"]
        
        self.DEBUG = DEBUG_LOG
    
        # initialization
        self.SetStartDate(2020, 9, 8)
        self.SetEndDate(2020, 10, 9)
        self.SetCash(100000)
        self.stock = self.AddEquity(SYMBOL, Resolution.Hour, Market.USA, True, 1, True)

        
        self.hma = self.HMA(SYMBOL, 20, Resolution.Hour)

    
        stockPlot = Chart('Stock Plot')
        stockPlot.AddSeries(Series('PriceOpen', SeriesType.Scatter, '$', Color.Green, ScatterMarkerSymbol.Circle))
        stockPlot.AddSeries(Series('PriceHigh', SeriesType.Scatter, '$', Color.Green, ScatterMarkerSymbol.Triangle))
        stockPlot.AddSeries(Series('PriceLow', SeriesType.Scatter, '$', Color.Green, ScatterMarkerSymbol.TriangleDown))
        stockPlot.AddSeries(Series('PriceClose', SeriesType.Line, '$', Color.Green, ScatterMarkerSymbol.Square))
        stockPlot.AddSeries(Series('HMA', SeriesType.Line, '$', Color.Gray))
        self.AddChart(stockPlot)
        
        self.lastPrice = 0.0
        self.pl = 0.0
        self._lo = None
        
        self.SetWarmup(HMALENGTH, Resolution.Hour)
        
    
    def OnData(self, data):
        # if we're not ready to trade, skip this run
        if self.IsWarmingUp:
            return
        
        self.Plot('Stock Plot', 'PriceOpen', float(data[self.stock.Symbol].Open))
        self.Plot('Stock Plot', 'PriceHigh', float(data[self.stock.Symbol].High))
        self.Plot('Stock Plot', 'PriceLow', float(data[self.stock.Symbol].Low))
        self.Plot('Stock Plot', 'PriceClose', float(data[self.stock.Symbol].Close))
        
        hma = float(self.hma.ToString())
        self.Plot('Stock Plot', 'HMA', Math.Round(hma, 2))