[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Series and Simple Functions



PureBytes Links

Trading Reference Links

>>Does anyone have a real live _example_ of code where the series/ simple
distinction makes a difference? (Maybe of code with a simple function
that is _not_ evaluated on every bar?)<<

Try this...
-----------------------------
User function:  My_Simple_MA
Properties: simple

var: avg(0) ;
avg = ( C + avg ) / 2 ;
My_simple_MA = avg ;
---------------------------
User function:  My_Series_MA
Properties: series

var: avg(0) ;
avg = ( C + avg ) / 2 ;
My_series_MA = avg ;
---------------------------
Indicator:  Compare_MA

if mod(currentbar,2) = 0 then begin

	value1 = My_Simple_MA ;
	value2 = My_Series_MA ;
	end;

plot1( value1 , "" ) ;
plot2( value2 , "" ) ;
---------------------------

The indicator executes the BEGIN block on every other bar.  Consequently, 
My_Simple_MA is evaluated on every other bar. In contrast, My_Series_MA is 
evaluated on every bar regardless of its location within the begin block.

When the indicator is plotted over the time series (set scale to "price"), we 
see both moving averages in a staircase action because the value1 and value2 
are updated on every other bar.  In addition, the two lines are different, with 
My_Series_MA  closer to the original data than My_Simple_MA.  This is because 
the former is being updated twice as often as the latter.

- MArk Jurik