【OHLCPeriodsAgoGen】
[code]inputs:PeriodType( numericsimple ),
PeriodsAgo( numericsimple ),
oPeriodOpen( numericref ),
oPeriodHigh( numericref ),
oPeriodLow( numericref ),
oPeriodClose( numericref ),
stream( numericsimple ) ;
variables:
var0( 0 ), sess_last_bar(false) ;
arrays:
arr0[ 4, 50 ]( -1 ) ;
sess_last_bar = sessionlastbar;
condition1 = PeriodsAgo > 50 or BarType > IFF(PeriodType<>0, PeriodType + 1, PeriodType + 2) or BarType > 4 ;
if condition1 then
begin
oPeriodOpen = -1 ;
oPeriodHigh = -1 ;
oPeriodLow = -1 ;
oPeriodClose = -1 ;
OHLCPeriodsAgoGen = -1 ;
end
else
begin
if PeriodType = 0 then
Condition1 = sess_last_bar[1]
else if PeriodType = 1 then
Condition1 = Date <> Date[1]
else if PeriodType = 2 then
Condition1 = DayOfWeek( Date ) < DayOfWeek( Date[1] )
else if PeriodType = 3 then
Condition1 = Month( Date ) <> Month( Date[1] )
else if PeriodType = 4 then
Condition1 = Year( Date ) <> Year( Date[1] ) ;
condition1 = CurrentBar = 1 or Condition1 ;
if condition1 then
begin
var0 = var0 - 1 ;
if var0 = -1
then var0 = 50 ;
arr0[ 1, var0 ] = O of data(stream) ;
arr0[ 2, var0 ] = H of data(stream) ;
arr0[ 3, var0 ] = L of data(stream) ;
arr0[ 4, var0 ] = C of data(stream) ;
end
else
begin
condition1 = H of data(stream) > arr0[ 2, var0 ] ;
if condition1 then arr0[ 2, var0 ] = H of data(stream);
condition1 = L of data(stream) < arr0[ 3, var0 ] ;
if condition1 then arr0[ 3, var0 ] = L of data(stream);
arr0[ 4, var0 ] = C of data(stream);
end ;
oPeriodOpen = arr0[ 1, Mod( var0 + PeriodsAgo, 51 ) ] ;
oPeriodHigh = arr0[ 2, Mod( var0 + PeriodsAgo, 51 ) ] ;
oPeriodLow = arr0[ 3, Mod( var0 + PeriodsAgo, 51 ) ] ;
oPeriodClose = arr0[ 4, Mod( var0 + PeriodsAgo, 51 ) ] ;
OHLCPeriodsAgoGen = 1 ;
end ;
if false then
Value1 = OHLCPeriodsAgoGen[1] ;
[/code]
页:
[1]