Does anyone have any code to calculate the duration of a non-time-based bar (contracts and ticks) in milliseconds for historical data?
I'd like to plot the data with an indicator.
This is my code for plotting bar duration in seconds:
Var:
BarDuration( 0 ) ;
BarDuration = TimeToSeconds( Time_s ) - TimeToSeconds( Time_s[1] );
plot1(barduration);
Thanks!
Bar Duration for Contract or Tick bars
Re: Bar Duration for Contract or Tick bars
The code doesn't quite make sense. Do you want this plotted as text for each bar? (that would bog your PC down) Or just a dot when an extreme happens?
Something to get you started:
Something to get you started:
Code: Select all
BarTime=( MillisecondsFromDateTime( DateTime )-MillisecondsFromDateTime( DateTime[1] ) ) ;
Last edited by MAtricks on 09 Feb 2015, edited 1 time in total.
Re: Bar Duration for Contract or Tick bars
I only want it plotted for historical data. I wouldn't plot anything for real time data.
Re: Bar Duration for Contract or Tick bars
Much appreciated, MAtricks.
I incorporated that code into my original code to get seconds with milliseconds added on:
Var:
BarDuration( 0 );
barduration = ( TimeToSeconds( Time_s ) + (MillisecondsFromDateTime( DateTime ) / 1000)) -
( TimeToSeconds( Time_s[1] ) + (MillisecondsFromDateTime( DateTime[1] ) / 1000));
I incorporated that code into my original code to get seconds with milliseconds added on:
Var:
BarDuration( 0 );
barduration = ( TimeToSeconds( Time_s ) + (MillisecondsFromDateTime( DateTime ) / 1000)) -
( TimeToSeconds( Time_s[1] ) + (MillisecondsFromDateTime( DateTime[1] ) / 1000));