BeginDataLoad Exception

Questions about MultiCharts .NET and user contributed studies.
Yaropolk
Posts: 6
Joined: 20 Aug 2013

BeginDataLoad Exception

Postby Yaropolk » 23 Aug 2013

Hello,

Not sure if this is a bug or I'm just doing something wrong.

When applied to chart the indicator generates message: SEHException (0x80004005): External component has thrown an exception.

Please see the attached image to see the full exception message.

I use MC.NET Starter Edition x64. The symbol I'm trying to download the data for is one of two symbols I have in the Quote Manager.

The code which generates the exception is as follows:

Code: Select all

using System.Collections.Generic;

namespace PowerLanguage.Indicator{
public class Test6_DataLoader : IndicatorObject {
public Test6_DataLoader(object _ctx):base(_ctx){}

private List<Bar> m_StockP = new List<Bar>();

protected override void Create() {}

protected override void StartCalc()
{
var dataReq = new DataRequest {RequestType = DataRequestType.BarsBack, Count = Bars.FullSymbolData.Count};

var req = Bars.Request;
req.Range = dataReq;

req.Symbol = "P";
DataLoader.BeginLoadData(req, OnData, null); //EXCEPTION ON THIS LINE
}

protected override void CalcBar() {}

private void OnData(IDataLoaderResult Result) {}
}
}
Attachments
000059.png
(39.85 KiB) Downloaded 624 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: BeginDataLoad Exception

Postby Henry MultiСharts » 27 Aug 2013

Hello Yaropolk,

Please use the following code:

Code: Select all

protected override void StartCalc()
{
var req = Bars.Request;
req.Range = DataRequest.CreateBarsBack(System.DateTime.Now, Bars.FullSymbolData.Count);


DataLoader.BeginLoadData(req, OnData, null);
}

Yaropolk
Posts: 6
Joined: 20 Aug 2013

Re: BeginDataLoad Exception

Postby Yaropolk » 29 Aug 2013

Thank you, I will try it.

Yaropolk
Posts: 6
Joined: 20 Aug 2013

Re: BeginDataLoad Exception

Postby Yaropolk » 30 Aug 2013

Henry,

Your code works.

The code I tried initially was taken from this wiki-page - http://goo.gl/pv6tRe

If that code is not working than it should probably be changed there.

I understand that wiki example uses constructor for creating DataRequest instance. And yours uses factory method. As I understood crash happens because To field of the DataRequest is not initialized in wiki example. If I use either of the following two initializations no crash happens.

Code: Select all

var dataReq = new DataRequest(DateTime.Now, Bars.FullSymbolData.Count, DataRequestType.BarsBack, DateTime.MinValue);

or

var dataReq = new DataRequest { To = DateTime.Now, Count = Bars.FullSymbolData.Count, RequestType = DataRequestType.BarsBack}; //, From = DateTime.MinValue };
The problem with DataRequest type is that it is a struct and can't have explicit private parameterless constructor (to prohibit users to use C#'s object initializer feature).

The easiest solution is to make DataRequest type a class and add private parameterless constructor.

Yaropolk
Posts: 6
Joined: 20 Aug 2013

Re: BeginDataLoad Exception

Postby Yaropolk » 30 Aug 2013

Now I've discovered another problem with the code. The code works with stock symbols. But when I'm trying to download data for $TRIN symbol it throws SymbolNotFoundException.

My datafeed is eSignal. Since I use Starter Edition I DO make sure that $TRIN is one of two symbols present in QuoteManager before trying the code. And $TRIN symbol can be loaded on price chart.

Thanks,
Yaropolk

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: BeginDataLoad Exception

Postby Henry MultiСharts » 10 Sep 2013

Now I've discovered another problem with the code. The code works with stock symbols. But when I'm trying to download data for $TRIN symbol it throws SymbolNotFoundException.

My datafeed is eSignal. Since I use Starter Edition I DO make sure that $TRIN is one of two symbols present in QuoteManager before trying the code. And $TRIN symbol can be loaded on price chart.

Thanks,
Yaropolk
Please make sure that you have specified the correct symbol parameters for $TRIN in DataLoader:

Code: Select all

protected override void StartCalc()
{
var req = Bars.Request;
req.Range = DataRequest.CreateBarsBack(System.DateTime.Now, Bars.FullSymbolData.Count);
req.Symbol = "$TRIN";
req.Category = ESymbolCategory.Index;
req.Exchange = "USI";
DataLoader.BeginLoadData(req, OnData, null);
}


Return to “MultiCharts .NET”