IDataLoaderResult Data2 is null

Questions about MultiCharts .NET and user contributed studies.
Metrica
Posts: 3
Joined: 04 Apr 2019
Has thanked: 1 time

IDataLoaderResult Data2 is null

Postby Metrica » 08 Sep 2020

Hello,
i'm trying to download Data2 to get BarPriceLevels[] values for history. The value of result.Data2 is always null.
Can you check the code below to find where is the problem?
Is a data provider problem? now i'm using IQFeed .
Thanks so much

Code: Select all

using System; using System.Drawing; using System.Linq; using PowerLanguage.Function; namespace PowerLanguage.Indicator{ public class TestData2 : IndicatorObject { public TestData2(object _ctx):base(_ctx) {} private IPlotObject plot1; private IDataLoaderResult _result; protected override void Create() { // create variable objects, function objects, plot objects etc. plot1 = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Red)); } private void ResultCallbackStorico( IDataLoaderResult result ) { Output.WriteLine( "Evento " + result.Event.ToString() ); if ( result.Event == DataLoadedEvent.History ) { Output.WriteLine( "Received " + result.Data.Length.ToString() + " historical bars... processing now..." ); if( result.IsCompleted ) { Output.WriteLine( "Completato : " + result.Data.Length.ToString() ); DataLoader.EndLoadData(_result); try { Output.WriteLine( "Controllo Data 2 " + result.Data2.Length.ToString() ); if( result.Data2 != null ) { Output.WriteLine( "Valori Data 2 " + result.Data2.Length.ToString() ); } } catch( Exception ex ) { Output.WriteLine( "Eccezione " + ex.Message ); } } } } protected override void StartCalc() { var request = Bars.Request; request.Resolution = new Resolution {Size = 1, Type = EResolution.Tick}; request.Subscribe2RT = false; request.Range = new DataRequest( DateTime.Now, 10, DataRequestType.FromTo, Bars.Time[0]); _result = DataLoader.BeginLoadData( request, ResultCallbackStorico, null ); Output.WriteLine( "Subscribed Storico!" ); } protected override void CalcBar() { // indicator logic plot1.Set(Bars.Close[0]); } } }

User avatar
Tammy MultiCharts
Posts: 200
Joined: 06 Aug 2020
Has thanked: 6 times
Been thanked: 65 times

Re: IDataLoaderResult Data2 is null

Postby Tammy MultiCharts » 09 Sep 2020

Hello Metrica,

The FootPrint chart's resolution has not been specified in the request.

Code: Select all

request.Resolution = Resolution.CreateFootPrint(EResolution.Minute, 1, CumulativeDeltaChartType.DELTA_UP_TICK_DOWN_TICK, FootPrintChartType.BID_ASK_VOL, false);
Please try this example:

Code: Select all

using System; using System.Drawing; using System.Linq; using PowerLanguage.Function; using System.Threading; using System.Collections.Generic; namespace PowerLanguage.Indicator { public class Dataloader_FootPrint : IndicatorObject { public Dataloader_FootPrint( object _ctx ) : base(_ctx) { } private IDataLoaderResult iRes; AutoResetEvent m_Event; private bool m_firstCallback = false; protected override void Create() { m_Event = new AutoResetEvent(true); } protected override void StartCalc() { iRes = null; Output.Clear(); InstrumentDataRequest request = Bars.Request; request.Resolution = Resolution.CreateFootPrint(EResolution.Minute, 1, CumulativeDeltaChartType.DELTA_UP_TICK_DOWN_TICK, FootPrintChartType.BID_ASK_VOL, false); request.Subscribe2RT = false; request.Range = new DataRequest(DateTime.Now, 10, DataRequestType.FromTo, Bars.Time[0]); request.QuoteField = RequestQuoteField.Trade; iRes = DataLoader.BeginLoadData(request, ResultCallback, m_Event); Output.WriteLine("My Request: {0} My Symbol: {1}", DateTime.Now, request.Symbol); } protected override void CalcBar() { } void ResultCallback(IDataLoaderResult Result) { Output.WriteLine("Evento " + Result.Event.ToString()); if (Result.Event == DataLoadedEvent.History) { Output.WriteLine("Received " + Result.Data2.Length.ToString() + " historical bars... processing now..."); if(Result.IsCompleted) { Output.WriteLine( "Completato : " + Result.Data2.Length.ToString()); DataLoader.EndLoadData(iRes); try { Output.WriteLine("Controllo Data 2 " + Result.Data2.Length.ToString()); if(Result.Data2 != null) { Output.WriteLine("Valori Data 2 " + Result.Data2.Length.ToString()); } } catch(Exception ex) { Output.WriteLine("Eccezione " + ex.Message); } } } } protected override void StopCalc() { if (iRes != null) { Output.WriteLine("Unsubscribe iRes"); DataLoader.EndLoadData(iRes); } base.StopCalc(); } } }

Metrica
Posts: 3
Joined: 04 Apr 2019
Has thanked: 1 time

Re: IDataLoaderResult Data2 is null

Postby Metrica » 14 Sep 2020

Thanks for the reply. The problem is that I cannot download information to determine aboveAsk or belowBid exchanges as in Time & Sales.
How can I do? I would also need to calculate it for each bar in the price history.
Thanks so much
Attachments
screen.PNG
(54.39 KiB) Not downloaded yet

User avatar
Tammy MultiCharts
Posts: 200
Joined: 06 Aug 2020
Has thanked: 6 times
Been thanked: 65 times

Re: IDataLoaderResult Data2 is null

Postby Tammy MultiCharts » 24 Sep 2020

Thanks for the reply. The problem is that I cannot download information to determine aboveAsk or belowBid exchanges as in Time & Sales.
How can I do? I would also need to calculate it for each bar in the price history.
Thanks so much
Hello Metrica,

Please check this indicator for accessing the price levels of a VD chart.

Code: Select all

using System; using System.Drawing; using System.Linq; using PowerLanguage.Function; using System.Threading; using System.Collections.Generic; namespace PowerLanguage.Indicator { public class Dataloader_FootPrint : IndicatorObject { public Dataloader_FootPrint( object _ctx ) : base(_ctx) { } private IDataLoaderResult iRes; AutoResetEvent m_Event; private bool m_firstCallback = false; protected override void Create() { m_Event = new AutoResetEvent(true); } protected override void StartCalc() { iRes = null; Output.Clear(); InstrumentDataRequest request = Bars.Request; request.Resolution = Resolution.CreateFootPrint(EResolution.Minute, 1, CumulativeDeltaChartType.ASK_TRADE_BID_TRADE, FootPrintChartType.BID_ASK_VOL, false); request.Subscribe2RT = false; request.Range = new DataRequest(DateTime.Now, 2, DataRequestType.FromTo, Bars.Time[0]); request.QuoteField = RequestQuoteField.Trade; iRes = DataLoader.BeginLoadData(request, ResultCallback, m_Event); Output.WriteLine("My Request: {0} My Symbol: {1}", DateTime.Now, request.Symbol); } protected override void CalcBar() { } void ResultCallback(IDataLoaderResult Result) { Output.WriteLine("Event " + Result.Event.ToString()); if (Result.Event == DataLoadedEvent.History) { Output.WriteLine("Received " + Result.Data2.Length.ToString() + " historical bars... processing now..."); if(Result.IsCompleted) { Output.WriteLine( "Completed : " + Result.Data2.Length.ToString()); DataLoader.EndLoadData(iRes); try { Output.WriteLine("Control Data2 " + Result.Data2.Length.ToString()); if(Result.Data2 != null) { Output.WriteLine("Values Data2 = {0} ", Result.Data2.Length); for(int i = 0; i < Result.Data2.Length; i++) { Output.WriteLine(" Bar_{0}", i+1); for(int j = 0; j < Result.Data2.ElementAt(i).Levels.Length; j++) { Output.WriteLine(" Up = {0}, Down = {1}, Price = {2} ", Result.Data2.ElementAt(i).Levels[j].UpVolume, Result.Data2.ElementAt(i).Levels[j].DownVolume, Result.Data2.ElementAt(i).Levels[j].Price); } } } } catch(Exception ex) { Output.WriteLine("Exception " + ex.Message); } } } } protected override void StopCalc() { if (iRes != null) { Output.WriteLine("Unsubscribe iRes"); DataLoader.EndLoadData(iRes); } base.StopCalc(); } } }
The screenshot attached demonstrates how it works.
Attachments
VD chart indicator.png
(199.12 KiB) Not downloaded yet


Return to “MultiCharts .NET”