Overall Statistics Total Trades0Average Win0%Average Loss0%Compounding Annual Return0%Drawdown0%Expectancy0Net Profit0%Sharpe Ratio0Probabilistic Sharpe Ratio0%Loss Rate0%Win Rate0%Profit-Loss Ratio0Alpha0Beta0Annual Standard Deviation0Annual Variance0Information Ratio0Tracking Error0Treynor Ratio0Total Fees\$0.00
# https://backtest-rookies.com/2018/12/07/quantconnect-working-with-heikin-ashi-data/
# https://www.quantconnect.com/forum/discussion/1017/simple-heikin-ashi-algorithmhttps://www.quantconnect.com/terminal/
# use heiki ashi for indicator : https://www.quantconnect.com/forum/discussion/1456/how-to-set-candlesticks-to-heiken-ashi-as-default/p1
# todo fee model
import datetime as datetime
from QuantConnect.Indicators import SimpleMovingAverage

class DynamicTachyonThrustAssembly(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2020,5, 15)   # Set Start Date
self.SetEndDate(2020,5,15)       # Set End Date
self.SetCash(10000)             # Set Strategy Cash

self.longStock = "SPXL"
self.shortStock = "SPXS"

self.sma5 = SimpleMovingAverage(5)

self.ha = self.HeikinAshi(self.longStock, Resolution.Minute)
self.ha.Updated += self.haUpdate

chart = Chart("chart")

self.lastPrice = 0.0

def haUpdate(self, sender, updated):
self.sma5.Update(updated)

def OnData(self, data):
if data["SPXL"] is None:
return

return

if self.Time.time() > datetime.datetime(2020,5,15,15,52,0).time() and self.Time.time() < datetime.datetime(2020,5,15,15,59,0).time():
self.Debug("--------{}--------<br>".format(self.Time))
sum = 0
slices = self.History(5)
for slice in slices:
sum = sum + slice.Bars["SPXL"].Close
self.Debug("slices time : {}, and close : {}<br>".format(slice.Time, slice.Bars["SPXL"].Close))
self.Debug("the sma 5 based on original close : {}<br>".format(sum/5))
self.Debug("the sma 5 based on Heikin ashi : {}<br>".format(self.sma5.Current.Value))
self.Debug("ha close : {}<br>".format(self.ha.Close))
for i in self.haWin:
self.Debug("haWin : {}<br>".format(i.Close))
self.lastPrice = data["SPXL"].Close

def OnEndOfDay(self):
self.Plot("chart", "Price", self.lastPrice)
self.Plot("chart", "sma5", self.sma5.Current.Value)