Volume Delta as histogram  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
mirek
Posts: 24
Joined: 08 Jan 2013
Has thanked: 3 times
Been thanked: 3 times

Volume Delta as histogram

Postby mirek » 11 Oct 2013

Hi all,

I have found details about Volume profile in the Reference guide for MC.NET. (thx for it) I would like to write an indicator(histogram) which displays volume delta for one bar. I think it is possible via Volume Profile when VP is setup for bar.I have found MaxDelta and MinDelta levels and I feel that I can read values through it. There is no possibility to get Delta for Bar. Howto do it? Should I use:
public interface ILevel : IEquatable<ILevel>

decimal AskTradedValue { get; } - Cumulative volume of all ASK traded trades for the level
decimal BidTradedValue { get; } - Cumulative volume of all BID traded trades for the level
Price Price { get; } - Level price
decimal TotalValue { get; } - Cumulative volume of the level

and calculate all volumes through all levels in the bar? How to get level ID's which are in the current bar? Is there any easier way to do it?

Thank you
mirek

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

Re: Volume Delta as histogram

Postby Henry MultiСharts » 17 Oct 2013

Hello mirek,

Have you checked all of the Volume Profiles interfaces described at this page? Please have a look at IProfile.Values

mirek
Posts: 24
Joined: 08 Jan 2013
Has thanked: 3 times
Been thanked: 3 times

Re: Volume Delta as histogram

Postby mirek » 17 Oct 2013

Hi Henry,

thx for response. Yes, I saw it, but i am not able to use it in the Indicator object. A small example would help how to use it.

I appreciate your help

mirek

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

Re: Volume Delta as histogram

Postby Henry MultiСharts » 18 Oct 2013

Please find a sample code attached.
Attachments
Test_ILevelInfo.pln
(1.26 KiB) Downloaded 931 times

mirek
Posts: 24
Joined: 08 Jan 2013
Has thanked: 3 times
Been thanked: 3 times

Re: Volume Delta as histogram

Postby mirek » 21 Oct 2013

Hi Henry,

thx a lot code. It helped a lot. I have written something like this:

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using PowerLanguage.VolumeProfile;

namespace PowerLanguage.Indicator{

public class _Volume_Stats : IndicatorObject {
public _Volume_Stats(object _ctx):base(_ctx){}

private IPlotObject Min_Delta;
private IPlotObject Max_Delta;
private IPlotObject Delta_Total;

public Color plusColor = Color.Green;
public Color minusColor = Color.Red;

protected override void Create() {

Min_Delta = AddPlot(new PlotAttributes("MaxDelta", EPlotShapes.Histogram, Color.Red, Color.Black, 2, 0, true));
Max_Delta = AddPlot(new PlotAttributes("MinDelta", EPlotShapes.Histogram, Color.Green, Color.Black, 2, 0, true));
Delta_Total = AddPlot(new PlotAttributes("DeltaTotal", EPlotShapes.Histogram, minusColor, Color.Black, 2, 0, true));

}
protected override void StartCalc() {
//subscribing for profile changes
VolumeProfile.EChanged += VolumeProfileOnEChanged;
}
protected override void CalcBar()
{
int bn = Bars.FullSymbolData.Current-1;
var vp = VolumeProfile.ItemForBar(bn);
decimal _deltaTotal=0;
decimal _maxAsk =0;
decimal _maxBid = 0;
Color _bar_color ;

foreach (VolumeProfile.ILevel _pcol in vp.Values)
{
_maxAsk = _maxAsk + _pcol.AskTradedValue;
_maxBid = _maxBid + _pcol.BidTradedValue;
_deltaTotal = _maxAsk - _maxBid;
}
decimal max_delta = vp.MaxDelta.TotalValue;
decimal min_delta = vp.MinDelta.TotalValue;

if (vp != null)
{
Max_Delta.Set((double)max_delta );
Min_Delta.Set((double)min_delta );
_bar_color = minusColor;
if ( _deltaTotal > 0) _bar_color = plusColor;
Delta_Total.Set((double)_deltaTotal, _bar_color);
}
}
private void VolumeProfileOnEChanged(bool full)
{
//Recalculate if the profile has been completely changed.
if (full)
this.ExecControl.Recalculate();
}
}
}
It is plotted like the picture in the attachment.

I hope it helps to someone else. If there is a better way to code it, pls. let me know. I am ready to learn.

Thank you
mirek
Attachments
DeltaMM.PNG
(49.06 KiB) Downloaded 1551 times

mirek
Posts: 24
Joined: 08 Jan 2013
Has thanked: 3 times
Been thanked: 3 times

Re: Volume Delta as histogram

Postby mirek » 22 Oct 2013

Hi all,

I closed MC.NET yesterday and restarted it today and I can not run my indicator. There is attached error. Can someone help?

Thank you
mirek
Attachments
_Volume_Stats_error.PNG
(35.62 KiB) Downloaded 1480 times

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

Re: Volume Delta as histogram

Postby Henry MultiСharts » 23 Oct 2013

Hi all,

I closed MC.NET yesterday and restarted it today and I can not run my indicator. There is attached error. Can someone help?

Thank you
mirek
Have you applied your study before the Volume Profile was loaded?

1. You need to apply your study to the chart after the Volume Profile is loaded.
2. Before referencing Volume Profile fields you need to make sure they are not NULL.

mirek
Posts: 24
Joined: 08 Jan 2013
Has thanked: 3 times
Been thanked: 3 times

Re: Volume Delta as histogram

Postby mirek » 23 Oct 2013

I had VP and my study enabled in the desktop. I have closed MC.NET and I have started it again the next day. The VP has been properly loaded and my study has reported the error.

I have tried to disable study, disable VP and enable VP(with disabled study), wait till VP was fully loaded and then I have reenabled the study. It failed with the same error.

I do not think it is convenient to disable/delete studies each time when MC.NET is closed and reenable them when MC.NET is started and VP is fully loaded.

Anyway I will give it a try as a temporary workaround.

mirek

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

Re: Volume Delta as histogram

Postby Henry MultiСharts » 24 Oct 2013

mirek, did you make sure in the code that the Volume Profile fields are not NULL before utilizing them?

mirek
Posts: 24
Joined: 08 Jan 2013
Has thanked: 3 times
Been thanked: 3 times

Re: Volume Delta as histogram

Postby mirek » 24 Oct 2013

It seems that the study works with TS, InteractiveBrokers data and it does not work with Zen-Fire data.

Any idea?

mirek

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

Re: Volume Delta as histogram  [SOLVED]

Postby Henry MultiСharts » 25 Oct 2013

Zen-Fire provides historical tick ask and bid data only for the last trading session. Please make sure you have enough ask and bid tick data in your data base that covers the chart data range. You can also try using a different volume profile setting that does not utilize ask/bid data (up/down tick).

mirek
Posts: 24
Joined: 08 Jan 2013
Has thanked: 3 times
Been thanked: 3 times

Re: Volume Delta as histogram

Postby mirek » 25 Oct 2013

I have limited symbol to 1 day back only and it works. There is something wrong with the data or my DB. I am investigating. Thx for pointing me to the right direction.

johnromeronc
Posts: 53
Joined: 18 Feb 2011
Has thanked: 11 times
Been thanked: 13 times

Re: Volume Delta as histogram - also Bid / Ask Volume within Footprint VolumeProfile

Postby johnromeronc » 04 Sep 2019

First a shout out to -->> Henry, Thanks, I found an example solution you put on forum to get at ILevels - bid/ask volume. It has taken me a few times to read it to understand it. But I have to admit, I would have never figured that out on my own. It is my lack of C# general knowledge. Now I know how to get at ASK & Bid Volumes with the bar.

Suggestions I think it would be helpful for others to have that as a 2nd example up in the WiKi . 4.7.6 Volume Profile. Also would it be helpful to have the structures also listed in this area? 4.7.5.2 Collections Elements.

Any way - it is a journey as I am self learning C#. I have an old programming degree, and no formal learning on OO, just online stuff. I like the Msft Bob Tabor lessons on C# general stuff. For examples of things specific to MC.Net, where is the best place to find examples? As a resource Visual Studio as the ability to search entire solution. So I search on possible keywords involved in whatever I am looking for. ex - VolumeProfile.

A wish, and I will add it to project mgmt - is to have many more examples, snippets, to be included in the supplied indicators , studies ... They could be in a sub folder to distinguish from other type of code.

John


Return to “MultiCharts .NET”