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