Bar Replay LastValue AFL issue (Weekly)

In Amibroker v6.30.5 I am using Bar Replay with the Step interval set to weekly to replay a system I am working on and currently debugging.

I am using Bar Reply mode so that I can simulate/debug my trading system, as part of this replay I am writing the lastvalue of the closing price and other arrays out to a csv file which is writing ok. I require these values in a file for later. The issue is that when using lastvalue ( or endvalue) in replay mode, the printed last value for each bar is not the actual last value for that bar. For example, with the weekly Step interval selected, I would expect it to print the closing price for that week which is the last trading date on a Friday, however this is not the case, it seems to print a midweek (Wednesday) date and associated value, so it seems.

Additionally, the Bar Replay is configured to run from 1/1/2016 to 20/9/2019 and for some unknown reason the output file has most of 2019 missing. I have pasted the extracted of the AFL code below which writes the data to the file.
Is there a better way to simulate a "Bar Replay" so that I can capture the values in a file achieving my objective.


fh = fopen( "C:/temp/" + Name() + "_myInd.csv", "a" );
if( fh )

    y = LastValue( Year() );
    m = LastValue( Month() );
    d = LastValue( Day() );

    ds = StrFormat( "%02.0f-%02.0f-%02.0f,", y, m, d );
    fputs( ds, fh );
    qs = StrFormat( "%.4f, %.4f\n", endvalue( C ), endvalue( myInd ) );
    fputs( qs, fh );
    fclose( fh );
1 Like

Bar Replay works CORRECTLY and as per settings and with Daily stepping selected it simulates precisely what would happen if added DAILY quotes every day as time goes. So throughout the week the LAST BAR date would represent Monday, Tuesday, Wednesday, Thursday and Friday as consecutive days are added daily to the last week candle.

If you don't want daily updates and you wanted one-step-per-week, you should obviously change the STEP INTERVAL to weekly. Then it will step one week at a time.


Second thing is that path in Windows are defined with BACKslashes, not forward slashes and backslash should be written as \\ (since single backslash is escape character), so proper path should be written as follows:

fh = fopen( "C:\\temp\\" + Name() + "_myInd.csv", "a" ); // proper path format

Also, system should rather be debugged using Backtest and/or Exploration. That is much more efficient than Bar Reply->Export->whatever you are doing with the file.


1 Like