AddToComposite to merge old and new VXX

Hello,

I am merging the old VXX symbol which traded from Jan 2009 until Jan 2019 with the new one using AddToComposite as follows:

/**************************************************************************************************************************
**
** --- VXX Merge Script --- 
** 
** Merges the OHLC and Volume data of the original VXX ticker (first trading date Jan-30-2009, last trading date Jan-29-2019) 
** with the new VXX (traded first under VXXB from Jan-18-2019 to Jan-29-2019). Original volumes are retained by using 
** NorgateOriginalVolumeTimeSeries().
**
** The merged symbol is "~VXX".
**
** Instructions: 
**
**	- Set current symbol to one that encompasses the full trading period (pre Jan-30-2009 until today (SPY for example)
**  - Set the Split Factor parameter (as of Nov 2021 last and only reverse split of the "new" VXX was 4 to 1 on Apr-23-2021)
**	- Run the scan
**  - To get rid of pre Jan-30-2009 zero values open ~VXX, go to Symbol > Quote Editor and delete all bars before Jan-30-2009 
**
**	VXX Split History:
**
**	11/09/2010	1 for 4
**	10/05/2012	1 for 4
**	11/08/2013	1 for 4
**	08/09/2016	1 for 4
**	08/23/2017	1 for 4
**	04/23/2021  1 for 4
**	
****************************************************************************************************************************/

#include_once "Formulas\Norgate Data\Norgate Data Functions.afl"

SplitF = Param("Split Factor", 4, 2, 10, 1);

if( Status("stocknum") == 0 )
{

	// --- Load the first VXX symbol ending on Jan-29-2019 ---
	SetForeign("VXX-201901");
	O1 = Open * SplitF;
	H1 = High * SplitF;
	L1 = Low * SplitF;
	C1 = Close * SplitF;
	V1 = NorgateOriginalVolumeTimeSeries();
	RestorePriceArrays();
	
	// --- Load the current VXX symbol starting Jan-18-2018 (started as VXXB, then reverted to VXX on Jan-30-2019) ---
	SetForeign("VXX");
	O2 = Open;
	H2 = High;
	L2 = Low;
	C2 = Close;
	V2 = NorgateOriginalVolumeTimeSeries();
	RestorePriceArrays();
	
	DateNums = DateNum();
	 _TRACEF("First bar DateTime:" + DateNums[0]);
	 
	for( bar = 1; bar < BarCount; bar++ )
	{

		if ( DateNums[bar] < 1090130 )
		{
			MO[bar] = Null;
			MH[bar] = Null;
			ML[bar] = Null;
			MC[bar] = Null;
			MV[bar] = Null;
		}
		
		else if ( DateNums[bar] < 1190130 )
		{
			MO[bar] = O1[bar];
			MH[bar] = H1[bar];
			ML[bar] = L1[bar];
			MC[bar] = C1[bar];
			MV[bar] = V1[bar];
		}
		
		else
		{
			MO[bar] = O2[bar];
			MH[bar] = H2[bar];
			ML[bar] = L2[bar];
			MC[bar] = C2[bar];
			MV[bar] = V2[bar];
		}
	}
	
	_TRACEF("Last bar DateTime:" + DateNums[bar-1]);
	if ( IsEmpty(MO[1]) ) _TRACEF("First value is Null");
	else _TRACEF(NumToStr(MO[1], 2));

	AddToComposite(MO, "~VXX", "O", atcFlagDeleteValues | atcFlagTimeStamp);
	AddToComposite(MH, "~VXX", "H", atcFlagDeleteValues | atcFlagTimeStamp);
	AddToComposite(ML, "~VXX", "L", atcFlagDeleteValues | atcFlagTimeStamp);
	AddToComposite(MC, "~VXX", "C", atcFlagDeleteValues | atcFlagTimeStamp);
	AddToComposite(MV, "~VXX", "V", atcFlagDeleteValues | atcFlagTimeStamp);
	
}

Setting the pre Jan 2009 values to Null still results in zeroes being plotted in the chart. Somehow these Null values are not being recognized as being {EMPTY}.

Is there a way to force the chart to start in Jan 2009?

Any help much appreciated!

Robert

Since this would be a one time excersize, would it help you if I send you the data ?

1 Like

Thanks a lot! … but I have the data and will use the formula in a batch file to keep the full VXX updated on a regular basis.

Don't write formulas for that. It is pointless. There is a Symbol->Merge built-in tool to merge quotes. Does not require formula.

2 Likes

Thanks Tomasz for pointing this out. Was in plain view but never used it.

Nevetheless, I prefer a solution that I can run inside a batch file with the scheduler to keep my merged symbol up to date. Unless of course the merge function does that which I dont't think is the case. My code already does this, and my question was about getting rid of the leading zeroes. But I can live with them.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.