Back

During the algorithm initialization, the following exception has occurred: Please register to receive data for symbol ' ' using the AddSecurity() function.

i am already registering the symbo

namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic template algorithm simply initializes the date range and cash. This is a skeleton
/// framework you can use for designing an algorithm.
/// </summary>
public class BasicTemplateAlgorithm : QCAlgorithm
{
private string _spy_s="SPY";
private TradeBar _workingDailyBar,_workingWeeklyBar;
private bool dailydataJustConsolidated = false,weeklydataJustConsolidated = false;
private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
private int totalticks,totaldays;
private RollingWindow<TradeBar> _dailywindow, _weeklywindow;
private RollingWindow<IndicatorDataPoint> _slowwindow,_fastwindow;
private bool movedlong=false;

private SimpleMovingAverage slow,fast;

/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// need to consolidate weekly bars.
/// </summary>
public override void Initialize()
{
totalticks=0;
totaldays=0;
SetStartDate(2011, 10, 03); //Set Start Date
SetEndDate(2013, 11, 25); //Set End Date
SetCash(100000); //Set Strategy Cash
// Creates a Rolling Window indicator to keep the 25 TradeBar

_dailywindow = new RollingWindow<TradeBar>(25); // For other security types, use QuoteBar
_weeklywindow = new RollingWindow<TradeBar>(25); // For other security types, use QuoteBar
_slowwindow = new RollingWindow<IndicatorDataPoint>(25);
_fastwindow = new RollingWindow<IndicatorDataPoint>(25);

slow= SMA(_spy_s,200,Resolution.Daily);
slow.Updated+=(sender,updated)=>_slowwindow.Add(updated);
fast= SMA(_spy_s,50,Resolution.Daily);
fast.Updated+=(sender,updated)=>_fastwindow.Add(updated);

// Find more symbols here: http://quantconnect.com/data
// Forex, CFD, Equities Resolutions: Tick, Second, Minute, Hour, Daily.
// Futures Resolution: Tick, Second, Minute
// Options Resolution: Minute Only.
AddEquity(_spy_s, Resolution.Second );

TradeBarConsolidator dailyconsolidator = new TradeBarConsolidator(TimeSpan.FromDays(1) );
dailyconsolidator.DataConsolidated += DailyHandler;
SubscriptionManager.AddConsolidator(_spy_s, dailyconsolidator);

TradeBarConsolidator weeklyconsolidator = new TradeBarConsolidator(TimeSpan.FromDays(7) );
weeklyconsolidator.DataConsolidated += WeeklyHandler;
SubscriptionManager.AddConsolidator(_spy_s, weeklyconsolidator);
SetWarmUp(TimeSpan.FromDays(500) );



// The time rule here tells it to fire 10 minutes before SPY's market close
Schedule.On(DateRules.EveryDay(_spy_s), TimeRules.BeforeMarketClose(_spy_s, 10), () =>
{
Log("EveryDay.SPY 10 min before close: Fired at: " + Time);
});




// There are other assets with similar methods. See "Selecting Options" etc for more details.
// AddFuture, AddForex, AddCfd, AddOption
}


/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice data)
{
if (IsWarmingUp) return;

if (fast.IsReady && slow.IsReady)
{
Debug("Indicators are ready!");
}

ConsolidateDailyWeeklyBars( data);
totalticks++;

if (!Portfolio.Invested)
{
SetHoldings(_spy, 1);
Debug("Purchased Stock");
}
// Log("OnData" + data.Time);

}
public void OnData(TradeBars data)
{
// TradeBars objects are piped into this method.
//Log( "????open" + data["SPY"].Open);


}


private void ConsolidateDailyWeeklyBars(Slice data)
{
//https://groups.google.com/forum/#!topic/lean-engine/JRKIP-QDwNs




if(_workingWeeklyBar == null || weeklydataJustConsolidated)
{


}

}
protected DateTime GetRoundedBarTime(DateTime time)

{

// return last EOD time

return time.RoundDown(TimeSpan.FromDays(1));

}
public override void OnEndOfDay(string symbol)
{
// close up shop each day and reset our 'last' value so we start tomorrow fresh
Log("eod data" + symbol + "total ticks" + totalticks);

}

public override void OnEndOfDay()
{
// close up shop each day and reset our 'last' value so we start tomorrow fresh
// Log("eod data" );
}


public void WeeklyHandler(object sender, TradeBar data) {

Log(" *****WeeklyHandler" + data.EndTime + "total days " + totaldays);
totaldays=0;
_weeklywindow.Add(data);

// handle the data each daily here
}
public void DailyHandler(object sender, TradeBar data) {

// Log("Daily Handler" + data.EndTime + "total ticks" + totalticks);
totalticks=0;
totaldays++;
_dailywindow.Add(data);



// handle the data each daily here
}
}
}

l at line 47 in the initialize. why do i get this excecption suddenly?

Update Backtest







 

Building Project ID: 1697918 Content Signature: 5ffbe24383422f674f64d804416eae10
636 | 21:24:50:
Build Request Successful for Project ID: 1697918 CompileID: e63739d4d99a7015033d8e24842ef528-5ffbe24383422f674f64d804416eae10 Lean Version: 2.4.0.0.4556
637 | 21:24:53:
Building Project ID: 1697918 Content Signature: 5ffbe24383422f674f64d804416eae10
638 | 21:24:53:
Build Request Successful for Project ID: 1697918 CompileID: d9aff238c9f74ec26f154585bc089033-5ffbe24383422f674f64d804416eae10 Lean Version: 2.4.0.0.4556
639 | 21:24:53:
Backtesting Project ID: 1697918
640 | 21:24:57:
Successfully sent backtest request for 'Calculating Fluorescent Orange Zebra', (Compile Id: d9aff238c9f74ec26f154585bc089033-5ffbe24383422f674f64d804416eae10)
641 | 21:25:08:
During the algorithm initialization, the following exception has occurred: Please register to receive data for symbol ' ' using the AddSecurity() function.
642 | 21:25:18:
Your log was successfully created and can be retrieved from: https://www.quantconnect.com/backtest/23194/1697918/3e3d117567a4690fcfe00db400d21622-log.txt

0


This exception was thrown because you were creating indicators before subscribing to the security.
Rule of thumb, we should first use set the algorithms (SetStartDate, SetCash, SetBrokerageModel, etc), then subscribe to the securities (AddEquity, AddForex, etc). After that, we can proceed to create consolidators, indicators and schedule events.

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed