如何获取某一时段内的开高低收 [MC]
-
MC用户求助:
MCpro版本有HighS和LowS函数,没有OpenS和CloseS函数,MC8.8和MC8s都没有。下面是OHLCPeriodsAgo的代码。
inputs:
PeriodType( numericsimple ),
PeriodsAgo( numericsimple ),
oPeriodOpen( numericref ),
oPeriodHigh( numericref ),
oPeriodLow( numericref ),
oPeriodClose( numericref ) ;
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 ;
OHLCPeriodsAgo = -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 ;
arr0[ 2, var0 ] = H ;
arr0[ 3, var0 ] = L ;
arr0[ 4, var0 ] = C ;
end
else
begin
condition1 = H > arr0[ 2, var0 ] ;
if condition1 then arr0[ 2, var0 ] = H ;
condition1 = L < arr0[ 3, var0 ] ;
if condition1 then arr0[ 3, var0 ] = L ;
arr0[ 4, var0 ] = C ;
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 ) ] ;
OHLCPeriodsAgo = 1 ;
end ;
if false then
Value1 = OHLCPeriodsAgo[1] ;
-
MC回复讨论一:
MCpro版本有HighS和LowS函数,没有OpenS和CloseS函数,MC8.8和MC8s都没有。下面是OHLCPeriodsAgo的代码。
inputs:
PeriodType( numericsimple ),
PeriodsAgo( numericsimple ),
oPeriodOpen( numericref ),
oPeriodHigh( numericref ),
oPeriodLow( numericref ),
oPeriodClose( numericref ) ;
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 ;
OHLCPeriodsAgo = -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 ;
arr0[ 2, var0 ] = H ;
arr0[ 3, var0 ] = L ;
arr0[ 4, var0 ] = C ;
end
else
begin
condition1 = H > arr0[ 2, var0 ] ;
if condition1 then arr0[ 2, var0 ] = H ;
condition1 = L < arr0[ 3, var0 ] ;
if condition1 then arr0[ 3, var0 ] = L ;
arr0[ 4, var0 ] = C ;
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 ) ] ;
OHLCPeriodsAgo = 1 ;
end ;
if false then
Value1 = OHLCPeriodsAgo[1] ;
-
MC回复讨论二:
再请教下老师:
之前的问题算是明白了。但关于这个Session的定义与计算,我发现周五夜盘与周一早盘,系统会当成是两个Session(如图),这样会导致我的策略计算有误,请问有何办法解决这个问题?
-
MC回复讨论三:
我将原始的OHLCPeriodsAgo函数的代码做了调整,使该代码可以完全用于国内期货交易所的时间段,不会出现周五夜盘与周一早盘分成两个交易时段的问题。详细见代码附件,顺便写了调整后的HighS和lowS代码
代码见链接:
http://dl.icetech.com.cn/download/forums/test_OHLCPeriodsAgo.rar
-
MC回复讨论四:
我将原始的OHLCPeriodsAgo函数的代码做了调整,使该代码可以完全用于国内期货交易所的时间段,不会出现周五夜盘与周一早盘分成两个交易时段的问题。详细见代码附件,顺便写了调整后的HighS和lowS代码
代码见链接:
http://dl.icetech.com.cn/download/forums/test_OHLCPeriodsAgo.rar
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 511411198 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容