I just ran a test to see if you could use StrFormat instead:
_trace( StrFormat( "%1.0g", openpos.Handle ) );
However, it seems that it too suffers from a similar problem; It does
not accept double as an argument type.
Just passing the raw double to _trace doesn't work either:
_trace( "" + openpos.Handle );
One way to work around the limitation would be to introduce JScript to
your code as follows:
EnableScript( "jscript" );
<%
function DoubleToStr( arg )
{
return "" + arg;
}
%>
SetCustomBacktestProc( "" );
if ( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject();
so = GetScriptObject();
...
for ( openpos = bo.GetFirstOpenPos(); openpos ; openpos =
bo.GetNextOpenPos() )
{
_trace( so.DoubleToStr( openpos.Handle ) );
} ...
}
The above will be equivalent to what you could have expected from
passing the raw double to _trace.
JScript does not have a native sprintf like C/C++ (from which StrFormat
borrows its formatting behavior), so if you wanted formatting you would
have to write it yourself. Fortunately, you can get a free
implementation from here:
http://www.diveintojavascript.com/projects/javascript-sprintf
<http://www.diveintojavascript.com/projects/javascript-sprintf>
Simply embed the source as-is within the script delimeters (i.e. <% and
%>) in the above example, and it will allow you full blown formatting
along the lines of C/C++ described here:
http://www.cplusplus.com/reference/clibrary/cstdio/printf/
<http://www.cplusplus.com/reference/clibrary/cstdio/printf/>
Specifically, you could call it like below to get exactly what you were
originally asking for:
_trace( so.sprintf( "%1.0f", openpos.Handle ) );
If you have an open ticket, it would be worth adding StrFormat and
_TRACE to the fix request so that they all work for doubles.
Mike
--- In [email protected], "whitneybroach" <whitneybro...@...>
wrote:
>
> Just as a follow-up, I heard from Tomasz off-line.
>
> At the moment, it can't be done with NumToStr. He is considering
whether to modify NumToStr. One issue: because the underlying values
are doubles, the numbers are large, 32- or 64 bits-worth, depending on
your platform.
>
> --- In [email protected], "whitneybroach" WhitneyBroach@
wrote:
> >
> > How do I write an openpos.Handle value to trace? Does the double
format not convert in NumToStr?
> >
> > Code like this produces only zeros from inside the openpos loop:
> >
> > //////////////////
> >
> > for( openpos = bo.GetFirstOpenPos(); openpos ; openpos =
bo.GetNextOpenPos() )
> > {
> > _trace( NumToStr( openpos.Handle, 1.0, False ) );
> >
> > // substituting 1.5 for 1.0 produces more zeros
> >
> > }// for openpos
> >
> > //////////////////
> >
> > (The code is checking to see if a dividend has already been paid on
an open position. Must be able to use multiple positions per symbol.)
> >
>