Mean, Median, Mode, Std Dev - For a specified time period

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
User avatar
pivot
Posts: 29
Joined: 07 Dec 2009
Been thanked: 2 times

Mean, Median, Mode, Std Dev - For a specified time period

Postby pivot » 16 Sep 2010

I am trying to create indicators for Mean, Median, Mode and Standard Deviation for a specified time period (ie 00:00 to 23:59).

Yes I have tried to play with

Mode

Code: Select all

inputs:
PriceValue( numericseries ),
Len( numericsimple ),
Type( numericsimple ) ;


variables:
var0( 0 ),
var1( 0 ),
var2( -1 ),
Value2( 0 ) ;

arrays:
arr0[1000]( 0 ) ;

if Len > 1 then
begin

for Value1 = 1 to Len
begin
arr0[Value1] = PriceValue[ Value1 - 1 ] ;
end ;

Value1 = SortArray( arr0, Len, -1 ) ;
var0 = 1 ;
var1 = 1 ;
var2 = -1 ;

for Value2 = 1 to Len - 1
begin
condition1 = arr0[Value2] = arr0[ Value2 + 1 ] ;
if condition1 then
var0 = var0 + 1
else
var0 = 1 ;
condition1 = var0 > 1 and var0 >= var1 ;
if condition1 then
begin
if var0 > var1 then
begin
var2 = arr0[Value2] ;
var1 = var0 ;
end
else
begin
condition1 = var0 = var1 and Type >= 0 ;
if condition1 then
var2 = arr0[Value2] ;
end;


end ;
end ;
end ;

Mode = var2;
Median

Code: Select all

inputs: PriceValue( numericseries ), Len( numericsimple ) ;
variables: var0( 0 ), var1( 0 ) ;
arrays: arr0[1000]( 0 ) ;


for Value1 = 1 to Len
begin
arr0[Value1] = PriceValue[ Value1 - 1 ] ;
end ;

Value1 = SortArray( arr0, Len, 1 ) ;

var0 = Len * .5 ;
var1 = IntPortion( var0 + 1 ) ;
if FracPortion( var0 ) = 0 then
Median = ( arr0[var0] + arr0[ var0 + 1 ] ) * .5
else
Median = arr0[ var1 ] ;
Mean

Code: Select all

inputs:
PriceValue( numericseries ),
Len( numericsimple ) ;

Average = Summation( PriceValue, Len ) / Len ;
All these need Len being number of bars where I am using tick data and want to create Mean, Median, Mode and Std Dev for a day or a specified time period.

Help on this would be appreciated as I am new in this programing field.

regards

p

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Mean, Median, Mode, Std Dev - For a specified time perio

Postby TJ » 19 Sep 2010

you can set up a counter... and start counting when D<>D[1]....
then use the count as the denominator.


Return to “User Contributed Studies and Indicator Library”