Hi,
I'm trying to to have the elapsed time (seconds) per bar shown in real time.
(On range bars)
I have used this thread as base:
The code I use:
--------------------------------------------------
function preMain(){
setStudyTitle("Time3");
setCursorLabelName("Time3", 0);
setPlotType(PLOTTYPE_HISTOGRAM, 0);
setDefaultBarFgColor(Color.white, 0);
}
function main(){
var myDate = new Date();
var myElapsedTimeInSecs = Math.round(myDate.getTime()/1000) - rawtime(0);
var myElapsedTimeInSecsPrevBar = Math.round(myDate.getTime()/1000) - rawtime(-1);
var myDifferenceInSecs = (myElapsedTimeInSecsPrevBar - myElapsedTimeInSecs);
if(myDifferenceInSecs == 0) myDifferenceInSecs = 1;
//setBar(Bar.Value, -1, 0,myDifferenceInSecs);
return(myDifferenceInSecs);
------------------------------------------------------------------------------------------------------
This works fine to show the time in the history bars but the current bar does not update in real time.
I want to be able to see the time "ticking" since the open of the current bar, preferably updated every tick.
If I use "return" instead of "setbar" it still doesn't update in real time.
But if I plot only the "Math.round(myDate.getTime()/1000) - rawtime(0);" the time is updated in real time.
I've been struggling with this for a couple of days now. Please help...
Regards, Lars
I'm trying to to have the elapsed time (seconds) per bar shown in real time.
(On range bars)
I have used this thread as base:
The code I use:
--------------------------------------------------
function preMain(){
setStudyTitle("Time3");
setCursorLabelName("Time3", 0);
setPlotType(PLOTTYPE_HISTOGRAM, 0);
setDefaultBarFgColor(Color.white, 0);
}
function main(){
var myDate = new Date();
var myElapsedTimeInSecs = Math.round(myDate.getTime()/1000) - rawtime(0);
var myElapsedTimeInSecsPrevBar = Math.round(myDate.getTime()/1000) - rawtime(-1);
var myDifferenceInSecs = (myElapsedTimeInSecsPrevBar - myElapsedTimeInSecs);
if(myDifferenceInSecs == 0) myDifferenceInSecs = 1;
//setBar(Bar.Value, -1, 0,myDifferenceInSecs);
return(myDifferenceInSecs);
------------------------------------------------------------------------------------------------------
This works fine to show the time in the history bars but the current bar does not update in real time.
I want to be able to see the time "ticking" since the open of the current bar, preferably updated every tick.
If I use "return" instead of "setbar" it still doesn't update in real time.
But if I plot only the "Math.round(myDate.getTime()/1000) - rawtime(0);" the time is updated in real time.
I've been struggling with this for a couple of days now. Please help...
Regards, Lars
Comment