DataLoader Problem

Questions about MultiCharts .NET and user contributed studies.
Morgan
Posts: 16
Joined: 29 Oct 2014
Has thanked: 1 time
Been thanked: 1 time

DataLoader Problem

Postby Morgan » 17 Jun 2015

Dears:

I tried to use the example of DataLoader in user-guide to modify.
Most codes are as same as the example,
however it displays the error message every time when I applied it.
I really can't find out the problem is.
I've checked there's data in the 2 symbols I want to load.
But it still displays the error message seems like null issue?
Could you help me find out the problem is or how I can solve it?

Thanks~


Codes:
===========

Code: Select all


using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using System.Collections.Generic;

namespace PowerLanguage.Indicator{
public class Axiom_MorganPP_SectorIndex : IndicatorObject {
public Axiom_MorganPP_SectorIndex(object _ctx):base(_ctx){}
private IPlotObject plot1,plot2;

private List<Bar> m_000916=new List<Bar>();
private List<Bar> m_000917=new List<Bar>();

protected override void Create() {
// create variable objects, function objects, plot objects etc.
plot1 = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Red));
plot2 = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Green));
}

public void OnData(IDataLoaderResult Result)
{
if (Result.Request.Symbol=="000916")
{
ProcessData(m_000916,Result);
}
if (Result.Request.Symbol=="000917")
{
ProcessData(m_000917,Result);
}
}

private void ProcessData(List<Bar> Container, IDataLoaderResult Result)
{
switch(Result.Event)
{
case DataLoadedEvent.History:{
Container.AddRange(Result.Data);
break;
}
case DataLoadedEvent.RTNewBar:{
if (Result.RTData.HasValue)
Container.Add(Result.RTData.Value);
break;
}

}

}

protected override void StartCalc() {
// assign inputs
Resolution dayResolution = new Resolution(EResolution.Day, 1);

InstrumentDataRequest Request=Bars.Request;
Request.Subscribe2RT=true;

DataRequest _DataRequest=new DataRequest();
_DataRequest.RequestType= DataRequestType.BarsBack;
_DataRequest.Count=Bars.FullSymbolData.Count;
Request.Range=_DataRequest;

Request.QuoteField=RequestQuoteField.Trade;
Request.Symbol="000916";
Request.Resolution = dayResolution;
DataLoader.BeginLoadData(Request,OnData,null);

Request.QuoteField=RequestQuoteField.Trade;
Request.Symbol="000917";
Request.Resolution = dayResolution;
DataLoader.BeginLoadData(Request,OnData,null);
}
protected override void CalcBar(){
// indicator logic
if (Bars.Status==EBarState.Close){
int index=Math.Min(Bars.CurrentBar,Math.Min(m_000916.Count-1,m_000917.Count-1));
if (index>0)
{
plot1.Set(m_000916[index].Close);
plot2.Set(m_000917[index].Close);
}

}


}
}
}
=============
Attachments
dataloader_error.zip
The picture of error message
(163.89 KiB) Downloaded 728 times

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

Re: DataLoader Problem

Postby Henry MultiСharts » 18 Jun 2015

Hello Morgan,

Please replace this code:

Code: Select all

DataRequest _DataRequest=new DataRequest();
_DataRequest.RequestType= DataRequestType.BarsBack;
_DataRequest.Count=Bars.FullSymbolData.Count;
Request.Range=_DataRequest;
With the following one:

Code: Select all

DataRequest _DataRequest = DataRequest.CreateBarsBack(DateTime.Now, Bars.FullSymbolData.Count);
Request.Range=_DataRequest;


Return to “MultiCharts .NET”