Hello,

Wondering if I could get some help on an issue I've ran into.

Say you have 200 bars of data, in that 200 bars I want to take a subset (say distance from low to high) and check where price was for each close in relation to a moving average (price is 10% above the EMA on that day, etc)

How can I go about looping through each bar & EMA? I'm assuming I need a RollingWindow but I am yet to use one anywhere so I'm a bit fuzzy. I'm currently selecting my Universe, then hoping to filter it down even further in OnSecuritiesChanged before sending a trade signal.

 

Here is what I've got so far:

       public partial class SymbolData
       {
            public readonly ExponentialMovingAverage EMA200;

            public readonly Maximum PeriodHigh;
            public readonly Minimum PeriodLow;

            public bool IsReady() { return 
                    EMA200.IsReady 

                    && PeriodHigh.IsReady 
                    && PeriodLow.IsReady; }


            public SymbolData(IEnumerable<TradeBar> history)
            {
                EMA200 = new ExponentialMovingAverage(200);

                PeriodHigh = new Maximum(200);
                PeriodLow = new Minimum(200);


                foreach (var bar in history)
                {
                    Update(bar.EndTime, bar.Close);
                }
            }

            public bool Update(DateTime time, decimal value)
            {
                EMA200.Update(time, value);

                PeriodHigh.Update(time, value);
                PeriodLow.Update(time, value);
                return IsReady();
            }
        }
        
        
        public override void OnSecuritiesChanged(SecurityChanges changes)
        {

            //foreach (var security in changes.RemovedSecurities)
            //{
            //    if (security.Invested)
            //    {
            //        Liquidate(security.Symbol);
            //    }
            //}




            foreach (var added in changes.AddedSecurities)
            {
                var history = History(added.Symbol, TradingMonthDays * 8, Resolution.Dailyy);

                SymbolData symbolData = new SymbolData(history);

                if (symbolData.IsReady())
                {

					//Loop through the last N period (PeriodLow - PeriodHigh) 

					and calculate where Daily close was in relation to EMA200, how?

                }

            }
        }

 

Thank you