After a while working on the above I've generated the following code:
// Custom Backtester begins here
SetCustomBacktestProc( "" );
if ( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject();
bo.Backtest( 1 );
path = "write data tester2.csv";
fh = fopen( path, "w" );
if ( fh )
{
trnum = 0;
dt = DateTime();
// writes the header
fputs("date,signal,gainahead\n", fh );
for ( trade = bo.GetFirstTrade(); trade;
trade = bo.GetNextTrade() )
{
trnum = trnum + 1;
//original
//trp = trade.GetPercentProfit();
//outstr =
// StrFormat( "Trade Number %5.0f PctGain %3.6f\n",
// trnum, trp );
//fputs( outstr, fh );
// using https://www.amibroker.com/kb/2014/11/14/how-to-export-quotes-to-separate-text-files-per-symbol/
//fputs( DateTimeToStr (dt [i] ), fh ); //doesn't work because i not initialized
fputs( DateTimeToStr (dt [trnum] ), fh ); //works but all on one line, no return?
//outstr = StrFormat( "%g,%g,%g\n", dt [trnum], dt [trnum], dt [trnum] );
//fputs (outstr, fh); // works, but displays values oddly
//outstr = StrFormat ("%g,%g\n", O[trnum], C[trnum]); works, but displays zeros
//fputs (outstr, fh );
//write quotations and go to the next line
//qs = StrFormat( "%g,%g,%g,%g,%g\n", O[ trnum ], H[ trnum ], L[ trnum ], C[ trnum ], V[ trnum ] );
//fputs( qs, fh );
// this works, but all data is zero
//trp = trade.GetNextSignal(); // GetNextSignal does not exist
trp1 = trade.EntryPrice(); // this is helpful
trp2 = trade.ExitPrice(); // also helpful
//trp = trade.FindSignal(); // FindSignal does not exist
//trp = trade.FindOpenPos(); // FindOpenPos does not exist
trp3 = trade.GetEntryValue (); // not useful
//trp = trade.IsEntry(); // IsEntry does not exist
//trp = trade.IsExit(); // is Exit does not exist
trp4 = trade.IsLong(); // helpful? always -1 (there are two instances, this is the first)
//trp = trade.IsLong(); // same as above, but second instance
trp5 = trade.IsOpen(); // helpful
trp6 = trade.Shares (); // changes, shows that system is running
trp7 = trade.GetPercentProfit ();
outstr =
StrFormat( "placeholder for signal %5.0f entryPrice %5.5f exitPrice %5.5f entryValue %5.5f IsLong %5.5f IsOpen %5.5f Shares %5.5f GetPercentProfit %5.5f\n",
trnum, trp1, trp2, trp3, trp4, trp5, trp6, trp7 );
fputs (outstr, fh);
// using https://www.amibroker.com/kb/2014/12/22/text-output-in-explorations/
//Buy = Cross( MACD(), Signal() );
//Sell = Cross( Signal(), MACD() );
//Filter = Buy OR Sell;
//AddColumn( IIf( Buy, 'B', 'S' ), "Signal", formatChar ); //not helpful
}
outstr = StrFormat( "Number of trades %5.0f \n",
trnum );
fputs( outstr, fh );
fclose( fh );
}
else
{
Error( "Error -- file cannot be opened" );
}
//bo.ListTrades();
}
// trading system
Buy = DayOfWeek() == 1;
Sell = DayOfWeek() == 5;
///////////////////////////// end /////////////////
and it gives me this output
I think that there is a flaw this though. The above code is working off of trade numbers, and I'm looking for a daily output. I started over trying to work day by day.
// Custom Backtester begins here
SetCustomBacktestProc( "" );
if ( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject();
bo.Backtest( 1 );
path = "write data tester3.csv";
fh = fopen( path, "w" );
if ( fh )
{
dt = DateTime();
// write header line
fputs( "Date/Time,Open,High,Low,Close,Volume\n", fh );
// iterate through all the bars
for ( i = 0; i < BarCount; i++ )
{
// write ticker name
//fputs( Name() + "," , fh );
// write date/time information
fputs( DateTimeToStr( dt[ i ] ) + ",", fh );
//write quotations and go to the next line
qs = StrFormat( "%g,%g,%g,%g,%g\n", O[ i ], H[ i ], L[ i ], C[ i ], V[ i ] );
fputs( qs, fh );
}
fclose( fh );
}
else
{
Error( "Error -- file cannot be opened" );
}
//bo.ListTrades();
}
// trading system
Buy = DayOfWeek() == 1;
Sell = DayOfWeek() == 5;
///////////////////////////// end /////////////////
This is now walking me through an output day by day, so I think I've made progress there. However, I'm no closer to generating a signal or gainAhead. In fact I can't figure out how to get any data or figures out of this to work with. So I think I've regressed in that nature.
Here is my current output: