Hello, I'm testing out the debugging functionality using Debug() and am having trouble logging anything outside of a child class of QCAlgorithm. I have a main class LoggingTest and an indicator class Indicator. The Debug() method works from the first and doesn't work from the second. Is there another way to do this?
Here is my code for LoggingTest and Indicator with a commented out debugging line on the second file:
namespace QuantConnect
{
public class LoggingTest : QCAlgorithm
{
private string symbol = "IBM";
private Indicator indicator = new Indicator();
public override void Initialize()
{
SetStartDate(2017, 1, 1);
SetEndDate(2017, 1, 7);
SetCash(30000);
AddEquity(symbol, Resolution.Hour);
}
public void OnData(TradeBars data)
{
String debug = "OnData(" + symbol + "): [" + data[symbol].Time + "]";
Debug(debug);
indicator.AddSample();
}
}
}
namespace QuantConnect {
public class Indicator
{
private int _numSamples;
public int Samples {
get { return _numSamples; }
}
public Indicator() {
this._numSamples = 0;
}
public decimal AddSample() {
// Debug("AddSample()");
_numSamples++;
return _numSamples;
}
}
}
AutomatedMachine
I think this will help you out. I just threw it together in the comment editor without trying to compile anything, but I think it should work for you.
public Class MyClass { public void MyMethod(QCAlgorithm algo) { algo.Debug("This is my message"); } } ----------------------------------- public override void OnData(Slice data) { MyClass test = new MyClass(); test.MyMethod(this); }
Wriju Bhattacharya
Yes it works!!! Thanks AutomatedMachine!
Also attaching a backtest since I just found out this feature exists
Wriju Bhattacharya
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!