[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Testing for new bar using string manipulation and quotation time



PureBytes Links

Trading Reference Links

Again, assuming that your approach is sound, better still would be to use the modulo operator.

barTime = 103731;

if (barTime % 100 == 0)
  _TRACE( "New bar found" );

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@xxx> wrote:
>
> Without commenting on the validity of the approach (I am not a real time trader), I can suggest that your problem is coming from a formatting incompatibility.
> 
> Add a format clause indicating zero decimal places and it will work fine.
> 
> Note too that your switching back to a number again is redundant and even error prone since "==" is not necessarily exact when dealing with floats. Just use the string manipulation directly.
> 
> barTime       = 103731;
> barTimeStr    = NumToStr( barTime, 6.0 );
> 
> if ( StrRight( barTimeStr, 2 ) == "00" )
>     _TRACE ( "New bar found" );
> 
> Mike
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@> wrote:
> >
> > 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");
> >
>




------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/