Total Volume for the day indicator

Questions about MultiCharts .NET and user contributed studies.
newdesigner
Posts: 7
Joined: 10 Feb 2009
Has thanked: 1 time

Total Volume for the day indicator

Postby newdesigner » 05 Mar 2023

I created an indicator that calculates the sum of bars volume for a period of bars. (See code below) I need help converting the period from a hard number to the number of bars since open (9:30AM ET) This would be plotted in a one minute chart. Any suggestions welcomed. Thanks.

Code: Select all

using System; using System.Drawing; using System.Linq; using PowerLanguage.Function; namespace PowerLanguage.Indicator { public class FTS230304VolSumBars : IndicatorObject { public FTS230304VolSumBars(object _ctx):base(_ctx) { period = 60; } [Input] public int period {get; set;} private IPlotObject plot1; protected override void Create() { // create variable objects, function objects, plot objects etc. plot1 = AddPlot(new PlotAttributes("TotalVol", EPlotShapes.Line, Color.Red)); } protected override void StartCalc() { // assign inputs } protected override void CalcBar() { double totalVolume = 0; // indicator logic for(int i = 0; i <= period; i++) { //plot1.Set(Bars.Volume[0] + Bars.Volume[1] + Bars.Volume[2] + Etc.); totalVolume += (Bars.Volume[i]); plot1.Set(totalVolume); } } } }

HellGhostEvocatorX
Posts: 77
Joined: 10 Feb 2022
Has thanked: 47 times
Been thanked: 9 times

Re: Total Volume for the day indicator

Postby HellGhostEvocatorX » 10 Mar 2023

is the first bar also the opening price?
then use the first bar by saying if a new day then start counting from the first bar.
there is even a FirstBarofaday indicator as well as many others dealing with time, maybe Timespan or something here is what you are looking for. you only need to set the first bar and then count the bars as I said

or you use a time comparison:

Code: Select all

var _now_time = new DateTime(1, 1, 1, Bars.Time[0].Hour, Bars.Time[0].Minute, Bars.Time[0].Second);
How long should your indicator count the bars? from the opening price of the bars until?
I changed your code as follows, it counts until the end of the day but always takes the current counter value.

I'm not exactly sure what your aim is, but maybe this code will give you an idea

Code: Select all

using System; using System.Drawing; using System.Linq; using PowerLanguage.Function; namespace PowerLanguage.Indicator { public class FTS230304VolSumBars : IndicatorObject { private TimeSpan Einstiegszeitpunkt; private TimeSpan AktuelleUhrzeit; private int Zaehler; private bool ZahlerStart; public FTS230304VolSumBars(object _ctx):base(_ctx) { period = 60; EinstiegsStunde = 09; EinstiegsMinute = 30; } [Input] public int period {get; set;} [Input] public int EinstiegsStunde { get; set; } [Input] public int EinstiegsMinute { get; set; } private IPlotObject plot1; protected override void Create() { // create variable objects, function objects, plot objects etc. plot1 = AddPlot(new PlotAttributes("TotalVol", EPlotShapes.Line, Color.Red)); } protected override void StartCalc() { Zaehler = 0; Einstiegszeitpunkt = new TimeSpan(EinstiegsStunde, EinstiegsMinute, 0); } protected override void CalcBar() { AktuelleUhrzeit = new TimeSpan(Bars.TimeValue.Hour, Bars.TimeValue.Minute, 0); if (Einstiegszeitpunkt == AktuelleUhrzeit) { ZahlerStart = true; } if (ZahlerStart == true) { Zaehler++; } if (Bars.Time[0].Day > Bars.Time[1].Day) { ZahlerStart=false; Zaehler = 0; } double totalVolume = 0; // indicator logic //for (int i = 0; i <= period; i++) for (int i = 0; i <= Zaehler; i++) { //plot1.Set(Bars.Volume[0] + Bars.Volume[1] + Bars.Volume[2] + Etc.); totalVolume += (Bars.Volume[i]); plot1.Set(totalVolume); } } } }
maybe this will help you too:

Code: Select all

Bars.FullSymbolData.Count Bars.FullSymbolData.Current


Return to “MultiCharts .NET”