龙听期货论坛's Archiver

龙听 发表于 2019-3-23 11:40

【MC常见问题】跨周期数据调用子图2数据 [MC]

[b]咨询内容:[/b][color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px] 跨周期data2调用[/size][/font][/color]

[color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]var: x2(0,[/size][/font][/color][b]data[/b][color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]2);[/size][/font][/color]

[color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]value1 = (close + open)/2;[/size][/font][/color]
[color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]value4 = ((close + open)/2 )of [/size][/font][/color][b]data[/b][color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]2;[/size][/font][/color]
[color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]x2 = ((close + open)/2 )of [/size][/font][/color][b]data[/b][color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]2;[/size][/font][/color]

[color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]value2 = Average(value1 , 5 ) of [/size][/font][/color][b]data[/b][color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]2;[/size][/font][/color]
[color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]value3 = Average((close + open)/2 , 5) of [/size][/font][/color][b]data[/b][color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]2;[/size][/font][/color]
[color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]value6 = Average(value4, 5) of [/size][/font][/color][b]data[/b][color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]2;[/size][/font][/color]
[color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]value5 = Average(x2, 5) of [/size][/font][/color][b]data[/b][color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]2;[/size][/font][/color]

[color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]当我们定义变量,使用跨周期的时候需要定义X2这样类型的变量,而不是一般的变量,譬如上面这个例子我预期是想得到value3的值,但是value2和value6输出的值都不对,value5的值和value3的值一致。大家可以用一个指标的方式画出这个值,用plot方式数据计算直接用[/size][/font][/color][b]data[/b][color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]2的数据作为计算资料。[/size][/font][/color]

[color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]我的理解是一般变量是每根K线都运行一次(没开bar内交易),那么在一般变量传值到函数里面调用的时候,是每根主图的K线都传递一次的,而不是子图[/size][/font][/color][b]data[/b][color=#212121][font=宋体, Arial, Helvetica, sans-serif][size=14px]2每根K线传递一次的,所以会有错误,无论我是用value2的方式还是用value6的方式都没达到我想要的value3的值。[/size][/font][/color]

龙听小虎 发表于 2023-11-3 21:10

{:48:}

页: [1]