Merge functionality

Dear all,

I use merge functionality quite often while stitching historical futures contracts & then merging this with the latest contract. This helps us to receive latest contract data until the next roll over date.

Is it possible to use merge functionality from AFL at all ?

I would appreciate suggestions & advice.

Many thanks,

Kind regards,
AD

Hi AD,

I'm with you!
It would be nice to set a synthetic price series Symbol that builds itself on the fly by our coded (roll timing) rules. This would input and scan all the symbols with a Futures Root Symbol bar-by-bar and build up our synthetic series. Continuous back adjusted and continuous spliced etc.

I would also like some additional symbol info fields specifically for futures and options.
-S

Merge functionality is not available programmatically. It is user-interface only feature.

I'm sure you played with the idea, but a continuous series Back-Adjuster sure would be nice! Alert and count-down to roll etc.

Also user defined instrument info fields, on a per database, maybe read off a csv file Name, type and AFL placeholder return types like UserDefinedInfoField1...UserDefinedInfoField2 ?

BTW, "Country" has no OLE setting feature.
Sorry just thinking. :star_struck:
-S

Hi, I have the same problem too. I'm trying to merge new quotes from a NEW symbol to OLD symbol if NEW volume is higher than the OLD one. And I want keep both symbol after merge.

I found several way can do similar idea but not exactly the same. Luckly I found the solution.

  1. Merge functionality:
  • Cannot compare volume
  • Cannot keep both symbol
  1. Pure AFL
    - Cannot add quote directly (I fail to find any function about importing quote through AFL )

  2. AFL + OLE
    AFL: Compare two symbol volume > export a Need csv data file+OLE/Import I don't know any about OLE

  3. AFL + Batch

I found method 4 can do this job.

(1) AFL code

 
Ticker = ParamStr("Symbol", "Symbole NAME_A" ); // Symbole NAME

//_______
new_contract_month_abc = strmid( Name(), 3,1 );
switch(new_contract_month_abc) {
    case "F":new_contract_month = 1;break;
    case "G":new_contract_month = 2;break;
	case "H":new_contract_month = 3;break;
	case "J":new_contract_month = 4;break;
	case "K":new_contract_month = 5;break;
	case "M":new_contract_month = 6;break;
	case "N":new_contract_month = 7;break;
	case "Q":new_contract_month = 8;break;
	case "U":new_contract_month = 9;break;
	case "V":new_contract_month = 10;break;
	case "X":new_contract_month = 11;break;
	case "Z":new_contract_month = 12;break;	
   }
//_______


fh = fopen( "csv_export//"+"Symbole NAME_A.csv", "w" );

if(fh)
{
  printf("Opening file");
  fputs("Date,Time,Open,High,Low,Close,Volume,Contract_Month\n", fh );
  

  dt = DateTime();

 
  olddata_volume = Foreign(Ticker,"Volume");
  olddata_open = Foreign(Ticker,"Open");
  olddata_high= Foreign(Ticker,"High");
  olddata_low = Foreign(Ticker,"Low");
  olddata_close = Foreign(Ticker,"Close");
  olddata_aux1 = Foreign(Ticker,"1");
   
 
  count_to_change = 0;
  change_to_new =0;
  change_to_new_condition1= 0;

//_______
//Compare two symbol's Volume and Find which date change to next month contact
  for( i = 0; i < BarCount; i++ )  
  { 
   if (change_to_new == 0){
		if (Volume[ i ] >0){
			if (Volume[ i ] >= olddata_volume[i]){
				count_to_change++;
				if (count_to_change >=30){
					change_to_new_condition1 =1;
				}
			}
			
			if (change_to_new_condition1 == 1){
				if (StrMatch(DateTimeFormat("%H:%M:%S", dt[i]),"09:15:00") ){
				  change_to_new = 1;
				  }
			}
		}
   }
 //_______
  
  if (change_to_new){
  Line = StrFormat("%s,%s,%g,%g,%g,%g,%g,%g\n",
  DateTimeFormat("%d/%m/%Y", dt[i]) ,
  DateTimeFormat("%H:%M:%S", dt[i]),
	Open[ i ],
   High[ i ],
   Low[ i ],
   Close[ i ],
   Volume[ i ], new_contract_month);
   
  }
  else{
  Line = StrFormat("%s,%s,%g,%g,%g,%g,%g,%g\n",
  DateTimeFormat("%d/%m/%Y", dt[i]) ,
  DateTimeFormat("%H:%M:%S", dt[i]),
  olddata_open[i],
  olddata_high[i],
  olddata_low[i],
  olddata_close[i],
  olddata_volume[i], olddata_aux1[i] );
   }
  
   fputs( Line, fh );
  
  }
 
  fclose( fh );

}
else
{
   printf("Error opening file");
}


(2) Batch Part

Load Database
Set Current Symbol //New Contract Symbol
Load Project // Scan with above AFL to export csv
Scan
Data Import ASCII
Save Database

This is a late reply, but hope can help other people~

1 Like

Hey Game,

I'll see if I can improve this a bit and thanks for your effort!

So let me see if I have this correct? It is meant for intra-day data and needs 30 intervals for a confirmation? Also, this makes a continuous "Spliced" series, rather than a back-adjusted series, correct?

-S

Hi Sean

Yes, the idea is "If New Symbol appear 30 bar that volume larger than Old Symbol, then the next day data in New Symbol will export to a csv".

Yes, afl find the day which needed to change to new contract data, then use batch to import back to Old Symbol.

=)