Hallo, I am trying to run a simple dip buying strategy backtest. The strategy buys the first stock out of the list, which price falls 2% below yesterday close and sell it at close. When I try to run with secod resolution, I alwas get error message: Memory Usage Maxed Out. Am I doing something wrong in the code?
/*
Strategy DipFast
buy intraday the first stock out of the list, which price drops below the yesterday Close * 0.98
*/
namespace QuantConnect
{
public class BasicTemplateAlgorithm : QCAlgorithm
{
string Dow30 = "MMM,APX,AAPL,BA,CAT,CVX,CSCO,KO,DIS,DD,XOM,GE,GS,HD,IBM,INTC,JNJ,JPM,MCD,MRK,MSFT,NKE,PFE,PG,TRV,UTX,UNH,VZ,V,WMT";
string symbols;
List
List
public override void Initialize()
{
SetStartDate(2008, 1, 1);
SetEndDate(DateTime.Now.Date.AddDays(-1));
SetEndDate(2015, 5, 27);
SetCash(10000);
symbols = Dow30;
symbolList = new List
Daily_Close = new List
Daily_Close.Clear();
for (int n = 0; n < symbolList.Count; n++)
{
AddSecurity(SecurityType.Equity, symbolList[n], Resolution.Second);
Daily_Close.Add(SMA(symbolList[n], 1, Resolution.Daily));
}
}
public void OnData(TradeBars data)
{
for (int n=0; n {
string symbol = symbolList[n];
if (!data.ContainsKey(symbol)) continue;
if ((!Portfolio.HoldStock) && (Time.TimeOfDay.TotalHours >= 9.54) && (Time.TimeOfDay.TotalHours < 15.75))
{
decimal buyLimit = Daily_Close[n] * 0.98m;
decimal price = data[symbol].Price;
if ( price < buyLimit)
{
int quantity = (int)Math.Floor(Portfolio.Cash * 0.99m / price);
Order(symbol, quantity);
break;
}
}
}
if (Portfolio.HoldStock)
{
if ((Time.Minute == 59) && (Time.Hour == 15))
{
Liquidate();
}
}
}
}
}
Michael Handschuh
Jan Veris
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!