How to Modify this AFL

In the following code how I will change the code symbol_name = StrReplace(StrReplace(Name(),"N.",""),"-I.NFO",""); in such a way that only symbol names will come in .txt file format. Like if in Amibroker the Symbol is NSE:YESBANK after exporting the text file will be created with the name YESBANK.TXT only. the full code is here which is used to export the database of Amibroker in Ninjatrader format:

//Coded By Paris Kamal
//Coder -  www.marketcalls.in
//Date : 12th Jul 2017


_SECTION_BEGIN("Export Amibroker Data to Ninjatrader EOD or 1min ASCII format");
path = "C:\\amidata\\";
Filter = 1;
symbol_name = StrReplace(StrReplace(Name(),"N.",""),"-I.NFO","");
data_format = ParamToggle("format","Daily|Minute",defaultval=0);
if(data_format == 1)
{
	path = path + "minute\\"+symbol_name+".txt";
}
else
{
	path = path + "daily\\"+symbol_name+".txt";
}
lin = 0;
line = 0;
fh = fopen(path,"r");
if(fh){
	while(!feof(fh))
	{
		fgets(fh);
		line++;
	}
	fclose(fh);
}
printf("%f",line);
    //yyyyMMdd;open price;high price;low price;close price;volume
for( i = 0; i < BarCount; i++ )
{	
	printf("%g",i);
	
	if(i == 0){
		fh = fopen(path,"w");
	}
	else
	{
		fh = fopen(path,"a");
	}
	if( fh )
    {
		y = Year();
		m = Month();
		d = Day();
		ds = Null;
//		s = gmtime;
	//	printf(s);
		if(data_format == 1)
		{
			r = Hour();
			e = Minute();
			n = Second();
			// convertion from ISO to GMT
			r[i] = abs(r[i]-6 + int((e[i]+30) / 60)) % 24;
			e[i] = (e[i]+ 30) % 60;
			
			ds = StrFormat("%02.0f%02.0f%02.0f %02.0f%02.0f%02.0f", y[ i ], m[ i ], d[ i ],r[ i ],e[ i ],n[ i ] );
		}
		else
		{
			ds = StrFormat("%02.0f%02.0f%02.0f", y[ i ], m[ i ], d[ i ] );
		}
		fputs(ds+";" ,fh ); 
		//fputs("\""+"Date\""+": ISODate(\""+ ds+"\")," ,fh );  
		c1 = StrFormat("%.2f",C[i]);
		o1 = StrFormat("%.2f",O[i]);
		h1 = StrFormat("%.2f",H[i]);
		l1 = StrFormat("%.2f",L[i]);
		v1 = StrFormat("%.0f",V[i]);
		fputs(o1+";" ,fh );
		fputs(h1+";" ,fh );
		fputs(l1+";" ,fh );
		fputs(c1+";" ,fh );
		fputs(v1,fh );
		fputs("\n",fh);
		if(i!=BarCount-1)
		{
			fputs("\n",fh);
		}
		fclose( fh );
//    fputs( qs, fh );
		   
    }
    else
	{
		printf("\nfile not exists");
	}

    }

_SECTION_END();

Any Expert can help me please?

Reading about how StrReplace() work, shouldn't take you more than a few minutes. Put some effort in it!

https://www.amibroker.com/guide/afl/strreplace.html

If you need similar functions, you can find all of them here:

String

https://www.amibroker.com/guide/a_catfunref.html

3 Likes