I'm trying to basically set a trade to fire when the price of the current symbol goes above the 125 day high

but I'm confused on how to compare max to the current price dynamically. Line 34 is where my problem is.

namespace QuantConnect { public class MaxMinFutures : QCAlgorithm { private Maximum _max125; private Maximum _max7; public override void Initialize() { SetStartDate(2017, 1, 1); var equity = AddEquity("SPY"); var future = AddFuture(Futures.Indices.SP500EMini); future.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(60)); // Indicators _max125 = MAX(equity.Symbol, 125); _max7 = MAX(equity.Symbol, 7); } public override void OnData(Slice slice) { if (!Portfolio.Invested) { foreach(var chain in slice.FutureChains) { var contract = ( from futuresContract in chain.Value.OrderBy(x => x.Expiry) where futuresContract.Expiry > Time.Date.AddDays(5) select futuresContract ).FirstOrDefault(); if (contract != null) { var _price = Securities[Symbols].Price; if (_price > _max125){ var quantity = 1; MarketOrder(contract.Symbol, quantity); } } } } } public override void OnEndOfDay() { Liquidate(); } } }

 

Author