| 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 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
# https://www.tradingview.com/script/TunYA7oc-Supertrend-1-0-with-Alerts/
# https://www.quantconnect.com/forum/discussion/3383/custom-indicator-in-python-algorithm/p1
from collections import deque
from QuantConnect.Indicators import AverageTrueRange
class CalibratedUncoupledProcessor(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 5, 4) # Set Start Date
self.SetEndDate(2020, 5, 4)
self.SetCash(100000) # Set Strategy Cash
self.AddEquity("SPY", Resolution.Minute)
self.superTrend = SuperTrend('custom', 3)
superTrendConsolidator = TradeBarConsolidator(1)
superTrendConsolidator.DataConsolidated += self.superTrendConsolidateHandler
def OnData(self, data):
self.Debug("-------time : {}----<br>".format(self.Time))
self.Debug(" up : {}<br>".format(self.superTrend.Up))
def superTrendConsolidateHandler(self, sender, bar):
pass
class SuperTrend:
def __init__(self, name, period):
self.Name = name
self.Time = datetime.min
self.IsReady = False
self.Trend = 0
self.Up = 0
self.Down = 0
self.queue = deque(maxlen=period)
self.atr = AverageTrueRange(period, MovingAverageType.Wilders)
# def __repr__(self):
# return "{0} -> IsReady: {1}. Time: {2}. Value: {3}".format(self.Name, self.IsReady, self.Time, self.Value)
def Update(self, input):
self.atr.Update(input)
if self.atr.IsReady:
self.queue.appendleft(input.Close)
hl2 = (input.High - input.Low) / 2
self.Up = hl2 + (self.atr.Current.Value * 1.5)
count = len(self.queue)
self.IsReady = count == self.queue.maxlen