Write screener to a file .txt

Yesterday I uploaded this query :

and @fxshrat solved it for me, but today I have another problem, I want to write the result of the screener to a file.

ListWL = CategoryGetSymbols( categoryWatchlist, 8 ); // Sotcks SP500
numtickers = 1 + StrCount( ListWL, "," ); 

MCap = Close * GetFnData( "SharesOut" );

Filter = MCap  > 8e11;  
SetOption("NoDefaultColumns", True ); 
SetSortColumns( -3 );

// No OK in the EXPLORE (I need only 5 positions)
AddTextColumn("","Ticker");
AddTextColumn("","Name");
AddColumn ( Null, "MarketCap", 1.0 ); 

//I need only for the top 5 positions
//How can I pass the result to StrFormat()?
for ( i = 0; i <= 5 ; i++ ) 
	{
	qs = StrFormat( "%s\t%s\t%1.0f", Name(), FullName(), Close * GetFnData( "SharesOut" ) );
	AddRow( qs );
	}

//So I need to pass it to a file
//Only for the first 5 positions to write them to a file .txt

fh = fopen( "C:\\Datos\\Demo" + ".txt", "w" );

if ( fh )
{
    // write header line
    fputs( "Ticker,Name,MarketCap\n", fh );

    // iterate through all the bars

for ( i = 0; i <= 5; i++ ) 
    {
    
	// PROBLEM ???????

	qs = StrFormat( "%s\t%s\t%1.0f", Name(), FullName(), Close * GetFnData( "SharesOut" ) );

    fputs( qs, fh );

    }
    // close file handle
    fclose( fh );
}

OK result --> I need write a file .txt

BAD result

Thanks for your help.

Use your AFL of yesterday (exploration part). Save it to analysis project file.
Then open new batch. Insert three batch steps.

  1. Batch step with action "Load project" file (you have saved before).
  2. Add 2nd batch step with action "Explore"
  3. Add 3rd batch step with action "Export to file" and choose location to save CSV file to.
  4. In case the order from top to bottom is not "Load project" -> "Explore" -> "Export to file" then use move up/move down buttons of batch tool bar to correct it.

Save batch via File - Save and alternatively run it in intervals via batch scheduler.

1 Like

Thanks @fxshrat for your quick response as always.
I have tried it and it works ok.

See this thread,

1 Like

I have seen it later, but I still get the header.
I have version 6.35.1
I do explore no backtest.

Tank you @fxshrat

Hi Carlos,
Did you unchecked Ticks on "Include Formula in the report" on the Analysis Settings/Report Tab and Also on the Old Backtester Submenu? Here I have unchecked all as i don't use this BT.
I also use Explore and it was related.
Best,

1 Like

And Make sure this Uncheck is saved on the APX File you are using on your Batch. APX Files saves on itself all the Analysis configuration.

1 Like

I have reloaded version 6.30.5.

Version 6.30.5 --> OK

Version 6.35.1 --> No OK

There is ZERO difference between 6.35.1 and 6.30.0 with regards to Export. You have enabled formula inclusion in the settings (APX file). That's all.

1 Like

Now all OK.

Thank you.

1 Like