Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to get time of a bar_index for each bar_index?

Is there a way to get the time of each bar_index?
I am doing

if peakLow
    array.push(VarArrayBarIndexLows, bar_index-1)
    array.push(VarArrayLowsValues, low[1])

I am wondering how I can also add the time of the bar_index-1 to an array?
Something like array.push(VarArrayTimeofBarIndexLows,time_of_bar_index), but I am not sure how to get the time_of_bar_index for each bar_index-1?

TLDL;
Specifically, here is what I am trying to do and I dont know how to find the ???

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

// High and Low Functions to find the peaks
fHigh(hi) =>
    pHigh = (hi[1] > hi[2]) and (hi <= hi[1])
fLow(lo) =>
    pLow = (lo[1] < lo[2]) and (lo >= lo[1])
peakLow = fLow(low)
peakHigh = fHigh(high)
plotshape(peakLow,    style=shape.triangleup,   location=location.belowbar, color=color.new(color.red,50),   offset = -1 , size=size.auto)
plotshape(peakHigh,   style=shape.triangledown, location=location.abovebar, color=color.new(color.blue,50),  offset = -1 , size=size.auto)
// =================== initializing the internal params ================
var VarArrayBarIndexLows = array.new_int()
var VarArrayTimeofBarIndexLows = array.new_float()
var VarArrayBarIndexHighs = array.new_int()
// init Array that holds the value for lows/highs
var VarArrayLowsValues = array.new_float()
var VarArrayHighsValues = array.new_float()



// if there is a peakLow then give the index and value to arrays
// I want to also get its time so later I use it in drawing tools
if peakLow
    array.push(VarArrayTimeofBarIndexLows, ???)
    array.push(VarArrayBarIndexLows, bar_index-1)
    array.push(VarArrayLowsValues, low[1])

>Solution :

You can simply get the time of bar_index - 1 with time[1].

Note: That will be in milliseconds.

You can also do hour[1], minute[1], seconds[1] etc.

You can use the below code from the faq to convert a time to a date-string format.

f_timeToString(_t) =>
  tostring(year(_t), "0000") + "." + tostring(month(_t), "00") + "." + tostring(dayofmonth(_t), "00") + " " +
  tostring(hour(_t), "00") + ":" + tostring(minute(_t), "00") + ":" + tostring(second(_t), "00")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading