Need AFL to export hourly data

#1
Hi,
Someone. could you please help me to export hourly amibroker data to text file? I used the below AFL to export the same. But I am not getting the timeframe as I expected. I should have timeframe as below
9:00
10:00
11:00
12:00
13:00
14:00
15:00
9:00
..
..

Please someone help me
Code:
_SECTION_BEGIN("Export Analysis1");
fh1 = fopen( "d:\\OHLC\\"+Name()+"\\price_h.txt", "w"); 
	TimeFrameSet( inHourly ); 

	d = Day(); 
	y = Year(); 
	r = Hour();
	e = Minute();
	n = Second();
	m = Month();
	if( fh1 ) 
	{ 
		for( i = BarCount - 50; i < BarCount; i++ ) 
		{ 

			fputs( Name() + "," , fh1 );
			ds = StrFormat("%02.0f-%02.0f-%02.0f,",y[ i ], m[ i ], d[ i ]); 
			fputs( ds, fh1 ); 
			ts = StrFormat("%02.0f:%02.0f,",r[ i ],e[ i ]); 
			fputs( ts, fh1 );
			smah=0;
			for (j = i - 12; j <= i;j++){
				smah = smah + H[j];

			}
			smah = smah/13;

			smal=0;
			for (j = i - 12; j <= i;j++){
				smal = smal + L[j];

			}
			smal = smal/13;
			qs = StrFormat("%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.0f\n",O[ i ],H[ i ],L[ i ],C[ i ],sma,smah,smal,V[i]); 
			fputs( qs, fh1 ); 
		} 
		
	}
fclose( fh1 ); 
TimeFrameRestore(); 
   Buy=1;
_SECTION_END();
 
#2
thank you.My database time is already set to hourly as expected above. However, Still my requirement is to export hourly data even though I am looking at different timeframe in amibroker. is it not possible?
 
#3
I quite agree with abhig10.
Just follow his guideline.


Hi,
Someone. could you please help me to export hourly amibroker data to text file? I used the below AFL to export the same. But I am not getting the timeframe as I expected. I should have timeframe as below
9:00
10:00
11:00
12:00
13:00
14:00
15:00
9:00
..
..

Please someone help me
Code:
_SECTION_BEGIN("Export Analysis1");
fh1 = fopen( "d:\\OHLC\\"+Name()+"\\price_h.txt", "w"); 
	TimeFrameSet( inHourly ); 

	d = Day(); 
	y = Year(); 
	r = Hour();
	e = Minute();
	n = Second();
	m = Month();
	if( fh1 ) 
	{ 
		for( i = BarCount - 50; i < BarCount; i++ ) 
		{ 

			fputs( Name() + "," , fh1 );
			ds = StrFormat("%02.0f-%02.0f-%02.0f,",y[ i ], m[ i ], d[ i ]); 
			fputs( ds, fh1 ); 
			ts = StrFormat("%02.0f:%02.0f,",r[ i ],e[ i ]); 
			fputs( ts, fh1 );
			smah=0;
			for (j = i - 12; j <= i;j++){
				smah = smah + H[j];

			}
			smah = smah/13;

			smal=0;
			for (j = i - 12; j <= i;j++){
				smal = smal + L[j];

			}
			smal = smal/13;
			qs = StrFormat("%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.0f\n",O[ i ],H[ i ],L[ i ],C[ i ],sma,smah,smal,V[i]); 
			fputs( qs, fh1 ); 
		} 
		
	}
fclose( fh1 ); 
TimeFrameRestore(); 
   Buy=1;
_SECTION_END();
 

raynor

Active Member
#4
A Help is Required..... Can the position of New candle can be shifted from left last to middle of the screen
 
#5
It is very possible. I myself exported in 5min. Follow the procedure I wrote.
I tried out. Still no success.My database timing already set to 9:00 AM to 16:00 PM and my plan is to run the hourly export in background though I am watching 5 minutes chart. I think this can accomplished through timeframeset only. Please guide. Thanks
 

KelvinHand

Well-Known Member
#6
I tried out. Still no success.My database timing already set to 9:00 AM to 16:00 PM and my plan is to run the hourly export in background though I am watching 5 minutes chart. I think this can accomplished through timeframeset only. Please guide. Thanks
Is there a communication problem by you ?
If you insert the script into the price chart or as indicator, it will nothing happen to export anything, it that what you are doing ?
Do you know that the script need to run in the exploration analysis mode OR
do you know that the script need to be inserted into other script to cause execution ?

If you know how to do it, then you will know your script got bugs.

This statement will cause problem:
fh1 = fopen( "d:\\OHLC\\"+Name()+"\\price_h.txt", "w");

Because the folder if not created.

2nd issue is out of range issue that i am facing

I dont had realtime data, do not ask me to solve for you.
 
Last edited:
#7
The folder is already created. You may get the error due to insufficient bars. However, I am able to export hourly data by changing the periodicity to hourly. But my requirement is to export hourly and 5 minute data through one AFL which I couldn't through AFL. It seems only one time frame can be used to export
 
#8
Both are possible. You asked how to export hourly data and I gave you the fix.

If you want hourly and 5min data output in a single file then that can also be managed using TimeFrameSet. My question is why would you need to export such type of data?
If possible, could you please guide me? I have another application which requires both hourly and 5 minute data to generate calls. thanks
 
#9
I am not going to import into any chart application. This application java based created by me. All wanted here is that 5 minute and hourly data in txt file. That's it. Then my application will take care of generating calls. thanks
 
#10
I am finding bit difficulty to understand the AFL. Could you please the complete AFL if possible? Thanks much

The below AFL is to export 5 minute. Could you please incorporate hourly time frame as well?
Code:
_SECTION_BEGIN("Export");
	fh1 = fopen( "d:\\OHLC\\"+Name()+"\\price_h.txt", "w"); 
	y = Year(); 
        m = Month(); 
        d = Day(); 
        r = Hour();
        e = Minute();
        n = Second();
	if( fh1 ) { 
        fputs( "Ticker,Date,Time,Open,High,Low,Close,Volume,O/I \n", fh ); 
	
     

        for( i = 1; i < BarCount; i++ ) {
                    fputs( Name() + "," , fh1 );
                    ds = StrFormat("%02.0f%02.0f%02.0f,", y[ i ], m[ i ], d[ i ] );
                    fputs( ds, fh1 ); 
  
                    ts = StrFormat("%02.0f:%02.0f:%02.0f,", r[ i ], e[ i ], n[ i ] ); 
                    fputs( ts, fh1 ); 
 
                    qs = StrFormat("%.2f,%.2f,%.2f,%.2f,%.0f,%.0f\n", O[ i ],H[ i ],L[ i ],C[ i ],V[ i ], OpenInt[ i ] );
                    fputs( qs, fh1 ); 
           
       } 
      fclose( fh1 ); 

} 

Buy = 1;
_SECTION_END();
 
Last edited:

Similar threads