I have been reading and listening to tutorials on Collections and processing them, but so far I do not have everything I need. I think the issues is how do I define a variable that I can then use. What I think I know, but do not know where to put them, and presume I am missing something.
what I think I know
1 - I need to define the Collection and the ILevel
2 - to iterate through the possible levels, I need to do a 'foreach' loop with price as my 'index' item
Here is my code so far. -- not complete as you will see.
John
Code: Select all
//comments I included from another piece of code provided on MC.Net forum to help me understand
//
// To get the volume profile collection for the current bar you should pass in the IInstrument CurrentBar(not the CurrentBar - 1).
// I used the following code to access the volume profiles for two data streams on a short and long term chart ,
// I include only the code for the short term chart and the "..." represent other irrelevant lines of code:
//
//
// https://www.multicharts.com/trading-software/index.php/4.7.6_Volume_Profile
// this is where I got the example code to use Min VA and Max VA values and plot them as sample.
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using PowerLanguage.VolumeProfile;
namespace PowerLanguage.Indicator{
public class JOR_ValueAreaBoundries : IndicatorObject
{
// I added this definition, thinking it was needed to see the variable definitio within it's structure
//
// Maybe I need to further define it (another instance?)
//
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
}
public JOR_ValueAreaBoundries(object _ctx):base(_ctx){}
private IPlotObject max_VA;
private IPlotObject min_VA;
private IInstrument _ShortTermBars; //short term chart instrument
//declare the shrort term collection to access ALL the profiles on the chart
private IProfilesCollection _ShortTermVolumeProfiles;
private ILevel jorAskBidLevels;
.
protected override void Create()
{
// create variable objects, function objects, plot objects etc.
max_VA = AddPlot(new PlotAttributes("MaxVA", EPlotShapes.Line, Color.Red, Color.Black, 2, 0, true));
min_VA = AddPlot(new PlotAttributes("MinVA", EPlotShapes.Line, Color.Blue, Color.Black, 2, 0, true));
_ShortTermBars = BarsOfData(1); //get the first data stream, this should point the same IInstrument as Bars
_ShortTermVolumeProfiles = VolumeProfileByDataStream(1); // get the profiles collection using the data stream
//
// I know I need some help here
//
jorAskBidLevels.Price = ?????
jorAskBidLevels.AskTradedValue = ??????
jorAskBidLevels.BidTradedValue = ??????
}
protected override void StartCalc()
{
// assign inputs
//subscribing for profile changes
VolumeProfile.EChanged += VolumeProfileOnEChanged;
}
protected override void CalcBar()
{
// indicator logic
double jorTempTestVar = 0;
double jorTempAskVol = 0;
double jorTempBidVol = 0;
int bn = Bars.FullSymbolData.Current-1;
var vp = VolumeProfile.ItemForBar(bn);
if (vp != null)
{
// These are the lines I am trying to use to get at each level bid and ask volume for the bar.
// at some point, I would do some things
//jorAskBidLevels = vp.Values(bn);
// I'm not sure this is right to use vp.Values
//foreach ( Price Price in vp.Values )
//{
// int jorTempAskVol = vp.Values.????
// int jorTempBidVol = vp.Values.????
//}
//// below 2 lines are from MC.Net example
max_VA.Set((double)vp.HighVAForBar(bn).Dbl );
min_VA.Set((double)vp.LowVAForBar(bn).Dbl );
}
}
private void VolumeProfileOnEChanged(bool full)
{
//Recalculate if the profile has been completely changed.
if (full)
this.ExecControl.Recalculate();
}
}
}