_Trace every bar

Hi,
I seem to not understand something very simple; I want to use _TRACE to print to log window every bar, for example the very simple code:

_TRACE("Date: " + Date());	

That if I use daily bars it will print every bar it's date, how do I do that?

Date() function is printing selected date only.

You would need to iterate from to zero to Barcount-1 if you want to print every bar.

dt = DateTime();
for( i = 0; i < BarCount; i++ )
    _TRACE("Date: " + DateTimeToStr(dt[i], 1));	
1 Like

@orshk, usually to verify array contents it is better to use explorations and/or (for limited size arrays) the debugger.

If you truly want to use _TRACE you need to change your code to loop over bars and use a _TRACE() for each bar as per the @codejunkie example.

Or maybe you could write something along these lines (not very useful IMHO - maybe you could devise something better passing multiple arrays to a custom function) :

function dumpNumericArray( a )
{
	local s, i;
    
    s = "\n";
    for( i = 0; i < BarCount; i++ )
    {
        s = s = s + NumToStr( i, 1.0 ) + " " + a[i] + "\n";
    }
    return s;
}

function dumpDateArray( dt )
{
	local s, i;
    
    s = "\n";
    for( i = 0; i < BarCount; i++ )
    {
        s = s + NumToStr( i, 1.0 ) + " " + DateTimeToStr( dt[i] ) + "\n";
    }
    return s;
}

_TRACE( "Close: " + dumpNumericArray( C ) );
_TRACE( "Date: " + dumpDateArray( DateTime() ) );

I will go with explorations anyway! See also this thread How do I debug my formula?

Something does not fit there.

Thanks for the replies, I'll also try working with explorations and see what's more convenient. It just that coming from other trading platforms it's seems strange to me that there isn't an easy log functionality.

@orshk: @codejunkie provided you with a solution that requires only 3 lines of code. How does that not qualify as "easy log functionality"?

@orshk: Coming from another platform may take a bit of getting used to, but once you "get" the power of AmiBroker, I doubt you will ever look back.

I use _Trace to follow the Logic of my program and Exploration to see the values of the calculations. Just make sure you know that the Exploration is INDEPENDENT of the Chart. You have to set all the parameters and system variables for the Exploration, separate from the Chart.