hello to everyone,

 

while i have some experience developing automated strategies, i'm completely new to quantconnect and could use some help in order to finalize a very simple strategy. i have been making modifications to one of the sample strategies that are included with the lean platform but there are some errors and i can't finalize it.

 

i have two issues i haven't been able to solve, even when i have searched the documentation and sample code. 1) ¿what changes should be made to this strategy so that everything ran in 6 minute bars (the trade bars, the indicators, everything)? 2) and the second thing i have had trouble with is the logic for the entries and exits: (_hmav[0] > _hmav[1]). ¿how could i get the strategy to go long if the current value of the hma is greater than one period ago, and short if the inverse is true?

 

/* * */ using System; using System.Linq; using QuantConnect.Data.Market; using QuantConnect.Indicators; namespace QuantConnect.Algorithm.CSharp { /// <summary> /// /// </summary> /// <meta name="tag" content="indicators" /> /// <meta name="tag" content="indicator classes" /> public class hmarevdaily : QCAlgorithm { private string _symbol = "NVDA"; private DateTime _previous; private HullMovingAverage _hmav; private SimpleMovingAverage[] _ribbon; /// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> public override void Initialize() { // set up our analysis span SetStartDate(2013, 01, 01); SetEndDate(2019, 01, 15); SetCash(10000); //Set Strategy Cash // request SPY data with minute resolution AddSecurity(SecurityType.Equity, _symbol, Resolution.Minute); // create a 15 day exponential moving average _hmav = HMA(_symbol, 15, Resolution.Minute); } /// <summary> /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. /// </summary> /// <param name="data">TradeBars IDictionary object with your stock data</param> public void OnData(TradeBars data) { // if (!_hmav.IsReady) return; var holdings = Portfolio[_symbol].Quantity; // we only want to go long if we're currently short or flat if (holdings <= 0) { // if the fast is greater than the slow, we'll go long if (_hmav[0] > _hmav[1]) { Log("BUY >> " + Securities[_symbol].Price); SetHoldings(_symbol, 1.0); } } // we only want to liquidate if we're currently long // if the fast is less than the slow we'll liquidate our long if (holdings > 0 && __hmav[0] < __hmav[1]) { Log("SELL >> " + Securities[_symbol].Price); SetHoldings(_symbol, -1.0); } Plot(_symbol, "Price", data[_symbol].Price); // easily plot indicators, the series name will be the name of the indicator Plot(_symbol, _hmav); _previous = Time; } } }

 

 

very well, thanks, regards.

Author