Oddly the code works on the M1 timeframe, giving the desired result, but does not work on the 5 min onward etc. I am an amateur coder so I can understand if the following code is not the best way of doing the job but any help would be appreciated.
// if barsinprogress == 1 then we are using the series from state.configure. If this isnt true, end the program
if (BarsInProgress != 1)
{
return;
}
// current DT gives time of the current bar
DateTime current_dt = Times[1][0];
for (int i = 0; i < starttimeslist.Count; i++)
{
// convert session time into a full DateTime for further use
DateTime sess_StartTime = new DateTime(current_dt.Year, current_dt.Month, current_dt.Day, starttimeslist[i].Hour, starttimeslist[i].Minute, starttimeslist[i].Second, DateTimeKind.Local);
DateTime sess_EndTime = new DateTime(current_dt.Year, current_dt.Month, current_dt.Day, endtimeslist[i].Hour, endtimeslist[i].Minute, endtimeslist[i].Second, DateTimeKind.Local);
// if we're in session, do the following, else we are no longer in session and end the function
if (sess_StartTime < current_dt && current_dt <= sess_EndTime)
{
int StartBar = CurrentBar - Bars.GetBar(sess_StartTime.AddMinutes(timeframe));
double BarOpenPrice = Open[StartBar];
// items for the line # non essential to code
String tag = GenerateTodayTag(current_dt);
SimpleFont TextFont = new SimpleFont("Verdana", 9);
// the drawing of the lines themselves
Draw.Line(this, " OL" + tag + nameslist[i], false, sess_StartTime.AddMinutes(timeframe), BarOpenPrice, sess_EndTime, BarOpenPrice, Brushes.White, DashStyleHelper.Solid, 1);
Draw.Text(this, "OL Text" + tag + nameslist[i], false, nameslist[i] + " " + 12, sess_EndTime, BarOpenPrice, 12, Brushes.White, TextFont, TextAlignment.Right, null, null, 100);
}
if (sess_StartTime < current_dt && current_dt <= sess_EndTime)
{
return;
}
​
Comment