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.791
Tracking Error
0.141
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
#region imports
from AlgorithmImports import *
#endregion


# Your New Python File
# In Initialize()
BAR = 2; STOCK = "SPY"

class TestHA(QCAlgorithm):
    
    def Initialize(self):
        
        self.SetStartDate(DateTime(2010, 5, 17, 9, 30, 0))  
        self.SetEndDate(DateTime(2021, 12, 1, 16, 0, 0)) 
        self.SetCash(200000) 

        self.symbol = self.AddEquity(STOCK, Resolution.Hour).Symbol
        consolidator = TradeBarConsolidator(timedelta(hours = BAR))
        self.Consolidate(self.symbol, timedelta(hours = BAR), self.BarHandler)
       
        self.heikinashi = self.HeikinAshi(self.symbol, Resolution.Hour)
        self.RegisterIndicator(self.symbol, self.heikinashi, consolidator)

        self.SetWarmUp(50, Resolution.Hour)


    def BarHandler(self, consolidated):
        if self.IsWarmingUp: return
        if not self.heikinashi.IsReady: return

    def IndicatorDataPoint(self, bar):
        if self.IsWarmingUp: return
        if not self.heikinashi.IsReady: return
        if self.heikinashi.IsReady:
            open = self.heikinashi.Open.Value
            high = self.heikinashi.High.Value
            low = self.heikinashi.Low.Value
            close = self.heikinashi.Close.Value
            volume = self.heikinashi.Volume.Value
            current = self.heikinashi.Current.Value

        #if self.heikinashi.IsReady:
            self.Plot("open", self.heikinashi.Open.Value)
            self.Plot("high", self.heikinashi.High.Value)
            self.Plot("low", self.heikinashi.Low.Value)
            self.Plot("close", self.heikinashi.Close.Value)
            self.Plot("volume", self.heikinashi.Volume.Value)
            self.Plot("heikinashi", self.heikinashi.Current.Value)

        if not self.Portfolio[self.symbol].IsLong:
            #if 2 > 1:
            if self.heikinashi.Current.Value >  close:
        #if self.heikinashi.Current.Value >  self.heikinashi.Open.Value:
                self.SetHoldings(self.symbol, 1, True, "Buy Signal")
        
        elif not self.Portfolio[self.symbol].IsShort:
            #if 2 < 1:
            if self.heikinashi.Current.Value <  close:
        #elif self.heikinashi.Current.Value <  self.heikinashi.Close.Value:
                self.SetHoldings(self.symbol, -1, True, "Sell Signal")

#region imports
from AlgorithmImports import *
#endregion
# Trading QC Super Trend Indicator
# --------------------------------------------
STOCK = "QQQ";  BAR =20; SL = -0.0745; TP = 0.04; #ATR = 1; MULT = 1; #wil m 0.2 and kama 0.16 spy 3 0.1..  A1M0.1  A2M0.2  A1M0.16
# --------------------------------------------

obv_SMA = 10;   # Also used for HA sma smoothing
#-----------------------------------------------------
#2010-2022,
#STOCK = "QQQ";  BAR =1; SL = -0.0745; TP = 0.02; ATR = 39; MULT = 1...  obv_SMA = 10... hour
#  616%  29%dd
#if self.Securities[self.stock].High < (self.heikin_ashiSMA.Current.Value)*1.04:
#elif self.Securities[self.stock].Low > (self.heikin_ashiSMA.Current.Value)*0.96:
#
#--------------------------------
#STOCK = "QQQ";  BAR =125; SL = -0.9745; TP = 0.05; ATR = 30; MULT = 1 , obv_SMA = 20 /  Hour
#  900 % and 16%dd  self.mari which is st  + haSMA   ?? cant find it ohhh
#679%    29%dd    self.mari  hour   with 129 orders........   if use sl 0.0745  profit is 580% dd 20
#
#  if self.Securities[self.stock].High < (self.mari.Current.Value)*1.05
#   elif self.Securities[self.stock].Low > (self.mari.Current.Value)*0.95
#
#
#------------------------------------------------------
#  STOCK = "QQQ";  BAR =1; SL = -0.0745; TP = 0.05; ATR = 39; MULT = 1;.. Hour  obv 725    
#if self.Securities[self.stock].High < (self.heikin_ashi.Current.Value)*1.05:
#elif self.Securities[self.stock].Low > (self.heikin_ashi.Current.Value)*0.95:
#679%  dd30  with 13 orders
# if change bars to minute , 683% 30dd with 200 orders 
#--------------------------------------------------------------

class SuperTrendIndicator(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(DateTime(2010, 5, 17, 9, 30, 0))  
        self.SetEndDate(DateTime(2021, 12, 1, 16, 0, 0)) 
        self.SetCash(200000) 

        
      


        res = Resolution.Hour
        ATR = int(self.GetParameter("ATR_A"))   
        MULT = float(self.GetParameter("MULT_A"))
        #BAR = int(self.GetParameter("BAR_A"))

#Risk Management
        #self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.05))
        #self.SetRiskManagement(TrailingStopRiskManagementModel(0.2545 ))
        #self.SetExecution(ImmediateExecutionModel())


        self.stock = self.AddEquity(STOCK, res, extendedMarketHours = True).Symbol
        consolidator = TradeBarConsolidator(timedelta(hours = BAR))
        self.Consolidate(self.stock, timedelta(hours = BAR), self.BarHandler)
        
        
        self.st = SuperTrend(ATR, MULT, MovingAverageType.Wilders)   #, MovingAverageType.Wilders
        self.RegisterIndicator(self.stock, self.st, consolidator)



        
#self.heikin_ashi = self.HeikinAshi(STOCK, Resolution.Minute)
        self.heikin_ashi = self.HeikinAshi(self.stock, Resolution.Hour)
        self.RegisterIndicator(self.stock, self.heikin_ashi, consolidator)

        self.heikin_ashiSMA = IndicatorExtensions.SMA(self.heikin_ashi, obv_SMA)
        
        #self.mari = IndicatorExtensions.Over(self.heikin_ashiSMA, self.st)   # extension, uhhmmm

        self.mari = IndicatorExtensions.Over(IndicatorExtensions.Plus(self.st, self.heikin_ashi), 2)


#OBV
        
        self.obv = self.OBV(STOCK, Resolution.Daily)
        self.RegisterIndicator(STOCK, self.obv, TradeBarConsolidator(timedelta(days = BAR)))
        
        self.obvSMA = IndicatorExtensions.SMA(self.obv, obv_SMA)   #   Of extension helper for SMA method.

        
        	

        self.SetWarmUp(50*BAR*ATR, res)

    
    


    def BarHandler(self, consolidated):
       
        if self.IsWarmingUp: return

        if not self.st.IsReady: return

        if not self.heikin_ashi.IsReady: return


        if not self.mari.IsReady: return
        
        if not self.obv.IsReady: return

        if not self.obvSMA.IsReady: return

        if not self.heikin_ashiSMA.IsReady: return

        #if not self.ha_week.IsReady: return   # weekly ha

    def onData():
        if not self.heikin_ashi.IsReady: return
        if self.heikin_ashi.IsReady:
            open = self.heikin_ashi.Open.Value
            high = self.heikin_ashi.High.Value
            low = self.heikin_ashi.Low.Value
            close = self.heikin_ashi.Close.Value
            volume = self.heikin_ashi.Volume.Value
            current = self.heikin_ashi.Current.Value

        self.Plot(STOCK, "Price", self.Securities[self.stock].Price)
        #self.Plot(STOCK, "Super Trend", self.st.Current.Value)
        self.Plot(STOCK,"MARI", self.mari.Current.Value)
        #self.Plot(STOCK,"HA Current Value", self.heikin_ashi.Current.Value)
        #self.Plot(STOCK,"HA SMA 0.97", (self.heikin_ashi.Current.Value)*1)
        #self.Plot(STOCK,"HA SMA 1.02", (self.heikin_ashiSMA.Current.Value)*1.02)
        #self.Plot(STOCK, "OBV", self.obv.Current.Value)
        #self.Plot(STOCK, "OBV SMA 1", (self.obvSMA.Current.Value)*1.1)
        #self.Plot(STOCK, "OBV SMA 2 Down", (self.obvSMA.Current.Value)*0.9)



        pnl = self.Securities[self.stock].Holdings.UnrealizedProfitPercent


        #if not self.Portfolio[self.stock].IsLong:
        #if self.obv.Current.Value > (self.obvSMA.Current.Value):

        if self.Securities[self.stock].Price > (Close)*1:
        #if (self.Securities[self.stock].Close > (self.mari.Current.Value)*0.92): # and (self.obv.Current.Value > (self.obvSMA.Current.Value)*0.99):  # and (self.Securities[self.stock].High < self.st.Current.Value):     #mari  BAR 125 obv_SMA 20 , atr 30 m 1  sl0.945
        #if self.mari.Current.Value > (self.heikin_ashiSMA.Current.Value)*0.90:
            self.SetHoldings(self.stock, 1, True, "Buy Signal")

        
        elif self.Securities[self.stock].Price < (Close)*1:
        #elif not self.Portfolio[self.stock].IsShort:  0.94
        #elif (self.Securities[self.stock].Close < (self.mari.Current.Value)*0.92): # and (self.obv.Current.Value > (self.obvSMA.Current.Value)*0.99): # and (self.Securities[self.stock].Low > self.st.Current.Value):  # mari BAR 12  obv_SMA 20 , atr 30 m 1    sl0.945
        #elif self.mari.Current.Value < (self.heikin_ashiSMA.Current.Value)*0.90:
            self.SetHoldings(self.stock, -1, True, "Sell Signal")
            #self.Liquidate(self.stock, "Sell Signal")
           # if self.Portolio is shoer ...  then Stop loss at 


        if self.Portfolio[self.stock].Invested:
            if pnl < SL:
                self.Liquidate(self.stock, "Stop Loss")
            #elif pnl > TP:
                #self.Liquidate(self.stock, "Take Profit")