hi,
I use this handy function from the userss KB
function secondsLeftOnBar_func()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
TimeFrame = Interval();
Newperiod = SecondNum % TimeFrame == 0;
SecsLeft = SecondNum - int( SecondNum / TimeFrame ) * TimeFrame;
SecsToGo = TimeFrame - SecsLeft;
return SecsToGo;
}
see: http://www.amibroker.org/userkb/2008/02/18/real-time-bar-period-timing-2/
----- Original Message -----
From: ozzyapeman
To: [email protected]
Sent: Tuesday, March 17, 2009 3:14 AM
Subject: [amibroker] Testing for new bar using string manipulation and
quotation time
Hello, hoping someone can help out with this string conversion problem.
In live trading, I am pulling quotation time using TimeNum(), and want to
test for the start of a new bar. So my thinking is to simply convert the time
to a number, extract the last two characters, convert back to a number and see
if it equals 0. If so, that means the last two digits in the quotation time are
"00" and hence we are at the start of a new bar.
However, the sample code below is always thinking we have a new bar whether
the time is, for e.g. :
10:37:31 or
10:37:00
Obviously, only the second time should trip the 'new bar' print. But
instead, both do:
barTime = 103731; // we would normally use TimeNum() here, but using a
number for example
barTimeStr = NumToStr(barTime);
NewBarSeconds = StrToNum ( StrRight(barTimeStr, 2) );
printf("NewBarSeconds = " + NewBarSeconds);
if (NewBarSeconds == 0)
printf(" We have a new bar");