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.981
Tracking Error
0.123
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
# assets volume oscillator

# --------------------------------------------------
ASSETS = ["QQQ", "SPY", "TLT"]; MA_F = 1; MA_S = 21;
# --------------------------------------------------

class VolumeOscillator(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 3, 1)  
        self.SetEndDate(2022, 4, 1)
        self.SetCash(100000) 
        self.assets =  [self.AddEquity(ticker, Resolution.Daily).Symbol for ticker in ASSETS]
        self.ma_f = {}; self.ma_s = {};
        for sec in self.assets:
            self.ma_f[sec] = self.SMA(sec, MA_F, Resolution.Daily, Field.Volume)
            self.ma_s[sec] = self.SMA(sec, MA_S, Resolution.Daily, Field.Volume)
        self.SetWarmUp(MA_S, Resolution.Daily)
        
        
    def OnData(self, data):
        if self.IsWarmingUp: return
        
        for sec in self.assets:
            if not (self.ma_f[sec].IsReady and self.ma_s[sec].IsReady): continue
            fast_volume = self.ma_f[sec].Current.Value
            slow_volume = self.ma_s[sec].Current.Value
            volume_oscillator = (fast_volume / slow_volume) if slow_volume > 0 else 1.0
            
            self.Plot("Volume Oscillator", sec, volume_oscillator)