My question is, Is it at all possible to also add a custom formula like (C/Ref(C, -1))-1 to the above AFL and export that too in the CSV file? If so, can someone please guide me on how to or to an example of a similar nature?
qs = StrFormat( "%g,%g,%g,%g,%g\n", O[ i ], H[ i ], L[ i ], C[ i ], V[ i ] );
// variable to understand
pc = (C[i]/C[i-1])-1;
qs = StrFormat( "%g,%g,%g,%g,%g,%g\n", O[ i ], H[ i ], L[ i ], C[ i ], V[ i ], pc );
and for ( i = 0;... should start from 1... or you write some if statement to output that "first" bar with pc = 0 etc
because when i=0, i-1 will be error.
thank you v much @nsm51. was stuck at the for i = 0 bit. cheers.
just to add to this query, your solution works but now when i export the data, the first bar for OHLC is missing in the csv. The code i am using is as follows
fh = fopen( "C:\\Data\\" + Name() + ".csv", "w" );
// proceed if file handle is correct
if ( fh )
{
dt = DateTime();
// write header line
fputs( "Ticker,Date/Time,Open,High,Low,Close,Volume,aux1_Percentile, aux2_Circuit, chg\n", fh );
// iterate through all the bars
for ( i = BarCount - 1; i >= 1; i-- ) // here is where i started i from 1
{
// write ticker name
fputs( Name() + "," , fh );
// write date/time information
fputs( DateTimeToStr( dt[ i ],1 ) + ",", fh );
pc = (C[i]/C[i-1])-1;
//write quotations and go to the next line
qs = StrFormat("%.4f, %.4f, %.4f, %.4f, %.0f, %.4f, %.4f, %.%%f\n",
O[ i ], H[ i ], L[ i ], C[ i ], V[ i ], Aux1[ i ], Aux2[ i ], pc*100 );
fputs( qs, fh );
}
// close file handle
fclose( fh );
}
// line required by SCAN option
Buy = 0;