Minute UpVolume histogram as sum of tick UpVolume  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
silent921
Posts: 2
Joined: 02 Aug 2014
Been thanked: 1 time

Minute UpVolume histogram as sum of tick UpVolume

Postby silent921 » 05 Aug 2014

I need to create Up/DownVolume histogram based on the minute as the sum of its constituent ticks.
I write code based on viewtopic.php?f=19&t=45940&p=101877#p101976
2 questions:
- How to reset counter on next bar?
- How to build this histogram on historical data?
I would be very grateful for the help.

Code: Select all

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


namespace PowerLanguage.Indicator
{
public class avolume_bugs : IndicatorObject
{
public avolume_bugs(object _ctx):base(_ctx)
{
up_color = System.Drawing.Color.Green;
down_color = System.Drawing.Color.Red;
}

private IPlotObject up_line;
private IPlotObject down_line;

[Input]
public Color up_color { get; set;}
[Input]
public Color down_color { get; set;}

protected override void Create()
{
up_line = AddPlot(new PlotAttributes("UpVolume", EPlotShapes.Histogram, up_color));
down_line = AddPlot(new PlotAttributes("DownVolume", EPlotShapes.Histogram, down_color));
}

float sum_UpVolume;
float sum_DownVolume;
IDataLoaderResult m_DL_Result;

protected override void StartCalc()
{
Resolution _ResolutionForRequest_fp = Resolution.CreateFootPrint(EResolution.Tick, 1,
CumulativeDeltaChartType.ASK_TRADE_BID_TRADE, FootPrintChartType.BID_ASK_VOL, false);
DateTime _Res_Time = Bars.TimeValue;
if (Bars.Info.Resolution.Type==EResolution.Second)
_Res_Time = Bars.TimeValue.AddSeconds(-Bars.Info.Resolution.Size);
if (Bars.Info.Resolution.Type==EResolution.Minute)
_Res_Time = Bars.TimeValue.AddMinutes(-Bars.Info.Resolution.Size);
if (Bars.Info.Resolution.Type==EResolution.Hour)
_Res_Time = Bars.TimeValue.AddHours(-Bars.Info.Resolution.Size);
InstrumentDataRequest _Res_fp = new InstrumentDataRequest(Bars.Info.DataFeed, Bars.Info.ASymbolInfo2, _ResolutionForRequest_fp, _Res_Time, Bars.TimeValue);
_Res_fp.Subscribe2RT = true;

m_DL_Result = DataLoader.BeginLoadData(_Res_fp, _1 =>
{
if (_1.IsCompleted)
{
if (_1.RTData != null)
{
Bar _RT = _1.RTData.Value;
}

if (_1.RTData2 != null)
{
sum_UpVolume=sum_UpVolume+_1.RTData2.Value.Bar.UpVolume;
sum_DownVolume=sum_DownVolume+_1.RTData2.Value.Bar.DownVolume;
}
}
}, null);
}

protected override void CalcBar()
{
up_line.Set(sum_UpVolume, up_color);
down_line.Set(sum_DownVolume, down_color);
}

protected override void StopCalc()
{
base.StopCalc();
DataLoader.EndLoadData(m_DL_Result);
}
}}
Attachments
avolume_bugs.pln
(1.57 KiB) Downloaded 415 times

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

Re: Minute UpVolume histogram as sum of tick UpVolume

Postby Henry MultiСharts » 13 Aug 2014

Hello silent921,

1) You can check the bar status and the bar number.
When a time based chart is used then you can compare the bar time on the current calculation with the previous value. If the value has changed then the calculation is being done on a new bar. But this solution cannot be applied to your case as you are using FootPrint chart.
2) You can plot the values if they are provided by your data vendor.

silent921
Posts: 2
Joined: 02 Aug 2014
Been thanked: 1 time

Re: Minute UpVolume histogram as sum of tick UpVolume  [SOLVED]

Postby silent921 » 13 Aug 2014

I have solved this problem by collecting historical data to several arrays.
Data from arrays processed as I need and gave them to the histogram.
Thank you for your attention. Topic can be closed.


Return to “MultiCharts .NET”