Back

How to find the line number of the runtime error?

namespace QuantConnect
{
public partial class BootCampTask : QCAlgorithm
{
private OrderTicket ticket;
public override void Initialize()
{
SetStartDate(2017, 06, 01);
SetEndDate(2017, 06, 15);
// Select the data you need here
var iwm=AddEquity("IWM",Resolution.Minute);
iwm.SetDataNormalizationMode(DataNormalizationMode.Raw);

}

public override void OnData(Slice data)
{
// Place an order and print the average fill price
ticket= MarketOrder("IWM",100);
}
// Override the base class event handler for order events
public override void OnOrderEvent(OrderEvent orderEvent)
{
// var order = Transactions.GetOrderById(orderEvent.OrderId);
//Console.WriteLine("{0}: {1}: {2}", Time, order.Type, orderEvent);
if(Portfolio.Invested && ticket.Status==OrderStatus.Filled)
{
Debug("aVE PRICE" + Portfolio["IWM"].AveragePrice);
}


}
}
}

I am trying to do the boot camp exercise and am running into run time error. but i cannto figure out which line is causing his. how can i find the error line.

here is the full code.

Update Backtest








You should uncomment the line "var order = Transactions.GetOrderById(orderEvent.OrderId);" and use 

if(Portfolio.Invested && order.Status==OrderStatus.Filled)
{
Debug("aVE PRICE" + Portfolio["IWM"].AveragePrice);
}

The stack trace can not give the line number of error like "Runtime Error: Object reference not set to an instance of an object". It means you didn't assign "ticket" while using its property.

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