Intraday / Multi-Time Frame | GetIntradayBar and the similar functions

Modified on 2010/08/25 11:56 by Eugene — Categorized as: Knowledge Base

Problem

Wealth-Lab 5 does not include functions like GetIntradayBar or GetWeeklyBar, previously used to access compressed Data Series in a higher time frame. The purpose of these functions was to take a Bar number and convert it to the corresponding bar in the compressed Data Series interval. For example, it allowed to get the correct bar of data in a 15 minute compressed Data Series from a 1 minute chart.

Referencing the synchronized series on a bar-by-bar basis in Version 5 could simply be done using RestoreScale and Synchronize - the WL6 equivalents to RestorePrimarySeries and IntradayFromCompressed. Nonetheless, if you need those functions for compatibility when porting a ChartScript from Wealth-Lab 4, you'll find the code snippets below helpful:



Code Example 1: GetIntradayBar


Font font = new Font("Arial", 7, FontStyle.Regular);
SetScaleCompressed(15);			
DataSeries CompBar = new DataSeries(Bars, "Compressed Bar Numbers");	// initialize a DataSeries
for (int bar = 0; bar < Bars.Count; bar++)	// load the bar numbers
	CompBar[bar] = bar;
			
DataSeries CompressedClose = Close;				// Compressed series for test
RestoreScale();			

// Synch the bar numbers with the base time frame (here's your "function") DataSeries GetIntradayBar = Synchronize(CompBar); for(int bar = 0; bar < Bars.Count; bar++) { int b = (int)GetIntradayBar[bar]; AnnotateBar(b.ToString("0"), bar, true, Color.Black, Color.Transparent, font); AnnotateBar(CompressedClose[b].ToString("0.00"), bar, false, Color.Black, Color.Transparent, font); }



Code Example 2: GetWeeklyBar


// Workaround for GetWeeklyBar

SetScaleWeekly(); DataSeries CompBar = new DataSeries(Bars, "Compressed Bar Numbers"); // initialize a DataSeries for (int bar = 0; bar < Bars.Count; bar++) CompBar[bar] = bar;

// Weekly EMA DataSeries wk_ema = EMA.Series( Bars.Close, 10, EMACalculation.Modern );

RestoreScale();

DataSeries wk_ema_synchedToIntraday = Synchronize( wk_ema ); DataSeries GetWeeklyBar = Synchronize(CompBar);

PlotSeries( PricePane, wk_ema_synchedToIntraday, Color.Blue, LineStyle.Solid, 1 ); SetBarColors( Color.Silver, Color.Silver ); HideVolume();

Font font = new Font("Courier", 7, FontStyle.Regular);

for(int bar = 30; bar < Bars.Count; bar++) { int gwb = (int)GetWeeklyBar[bar]; AnnotateBar(gwb.ToString(), bar, false, Color.Black,Color.Transparent, font);

if( wk_ema[gwb] > wk_ema[gwb-1] ) SetBarColor( bar, Color.Blue ); }