请老师帮我看一下这个画图的代码出现了什么问题 [MC]
-
MC用户求助:
input:n(36);
Var:x(0),z(0),z_sell(0),z_buy(0);
once begin
value1=tl_new(date ,2100,z,date ,2300,z);
value2=tl_new(date ,2100,z_Sell,date ,2300,z_Sell);
value3=tl_new(date ,2100,z_buy,date ,2300,z_buy);
end;
x=AvgTrueRange(n);
z=open;
z_sell= z + 2 * x;
z_buy= z - 2 * x;
tl_setbegin(value1,date,2100,z);
tl_setend(value1,date,2300,z);
第一、tl_new是用于新建趋势线的,每次新建时会返回该趋势线的编号;
第二、tl_setbegin和tl_setend用于更改趋势线的开始位置和终点位置,通过趋势线的编号;
第三、MC是每一根bar执行一次计算,而您的代码是每次计算时都执行三次tl_new,从而导致每次计算时都新建三条趋势线,所以才会那么多趋势线,这样很占用资源的。
第四、once关键字的用法见帖子http://forums.icetech.com.cn/for ... &highlight=once
-
MC回复讨论一:
input:n(36);
Var:x(0),z(0),z_sell(0),z_buy(0);
once begin
value1=tl_new(date ,2100,z,date ,2300,z);
value2=tl_new(date ,2100,z_Sell,date ,2300,z_Sell);
value3=tl_new(date ,2100,z_buy,date ,2300,z_buy);
end;
x=AvgTrueRange(n);
z=open;
z_sell= z + 2 * x;
z_buy= z - 2 * x;
tl_setbegin(value1,date,2100,z);
tl_setend(value1,date,2300,z);
第一、tl_new是用于新建趋势线的,每次新建时会返回该趋势线的编号;
第二、tl_setbegin和tl_setend用于更改趋势线的开始位置和终点位置,通过趋势线的编号;
第三、MC是每一根bar执行一次计算,而您的代码是每次计算时都执行三次tl_new,从而导致每次计算时都新建三条趋势线,所以才会那么多趋势线,这样很占用资源的。
第四、once关键字的用法见帖子http://forums.icetech.com.cn/for ... &highlight=once
-
MC回复讨论二:
老师您好,我在问题里面没有描述清楚,用了您的改动发现还是没有得到我需要的效果。我重新描述一遍问题吧:
我想做一个日内突破模型,中心线(一条水平线)是每日9:00和每夜21:00的开盘价,然后沿着中心线每隔一个ATR单位便画一条水平线,白天的代码如下,if date <> Date[1] then
begin
Y = Opend(0) ;
Y_Sell1 = Y + x ;
Y_Sell2 = Y + 2 * x ;
Y_Sell3 = Y + 3 * x ;
y_buy1 = Y - x ;
Y_Buy2 = Y - 2 * x ;
Y_buy3 = Y - 3 * x ;
tl_new(date ,0900,Y,date ,1500,Y);
tl_new(date ,0900,Y_Sell1,date ,1500,Y_Sell1);
tl_new(date ,0900,Y_Sell2,date ,1500,Y_Sell2);
tl_new(date, 0900,y_sell3,date ,1500,y_sell3);
tl_new(date ,0900,y_buy1,date ,1500,y_buy1);
tl_new(date ,0900,Y_Buy2,date ,1500,Y_Buy2);
tl_new(date, 0900,Y_buy3,date ,1500,Y_buy3);
end ;
这样写完全能够画出我需要的线。但是晚上就不太灵了,经过我这一天的查询与询问,顶多能写出如下的代码(这里面的开盘价opedndy是我在论坛查询夜盘代码时查出来的,导入的函数,发现还挺好用,确实起到了夜盘21:00开盘价的作用):
if time>=2100 and date=date[1] then
begin
z=opendy(0);
z_Sell1 = z + x ;
z_Sell2 = z + 2 * x ;
z_Sell3 = z + 3 * x ;
z_buy1 = z - x ;
z_Buy2 = z - 2 * x ;
z_buy3 = z - 3 * x ;
tl_new(date ,2100,z,date ,2300,z);
tl_new(date ,2100,z_Sell1,date ,2300,z_Sell1);
tl_new(date ,2100,z_Sell2,date ,2300,z_Sell2);
tl_new(date, 2100,z_sell3,date ,2300,z_sell3);
tl_new(date ,2100,z_buy1,date ,2300,z_buy1);
tl_new(date ,2100,z_Buy2,date ,2300,z_Buy2);
tl_new(date, 2100,z_buy3,date ,2300,z_buy3);
end;
但是得到的还是无数条很乱的水平线,不像白天的那种很规律的七条线。
我也试了您说的once begin函数,但是由于看不太懂说明,所以也是不太奏效,不知应该怎样改进才可以?
-
MC回复讨论三:
if date <> Date[1] then
begin
Y = open;
{通过date<>date[1]来界定这段begin end内部的代码只在白天开盘第一根bar执行,然后取open价格就可以了}
Y_Sell1 = Y + x ;
Y_Sell2 = Y + 2 * x ;
Y_Sell3 = Y + 3 * x ;
y_buy1 = Y - x ;
Y_Buy2 = Y - 2 * x ;
Y_buy3 = Y - 3 * x ;
tl_new(date ,0900,Y,date ,1500,Y);
tl_new(date ,0900,Y_Sell1,date ,1500,Y_Sell1);
tl_new(date ,0900,Y_Sell2,date ,1500,Y_Sell2);
tl_new(date, 0900,y_sell3,date ,1500,y_sell3);
tl_new(date ,0900,y_buy1,date ,1500,y_buy1);
tl_new(date ,0900,Y_Buy2,date ,1500,Y_Buy2);
tl_new(date, 0900,Y_buy3,date ,1500,Y_buy3);
end ;
if time>=2100 and time[1]<=1500 then
{通过time>=2100 and time[1]<=1500来界定这段begin end内部的代码只在夜盘开盘第一根bar执行,然后取open价格就可以了}
begin
z=open;
z_Sell1 = z + x ;
z_Sell2 = z + 2 * x ;
z_Sell3 = z + 3 * x ;
z_buy1 = z - x ;
z_Buy2 = z - 2 * x ;
z_buy3 = z - 3 * x ;
tl_new(date ,2100,z,date ,2300,z);
tl_new(date ,2100,z_Sell1,date ,2300,z_Sell1);
tl_new(date ,2100,z_Sell2,date ,2300,z_Sell2);
tl_new(date, 2100,z_sell3,date ,2300,z_sell3);
tl_new(date ,2100,z_buy1,date ,2300,z_buy1);
tl_new(date ,2100,z_Buy2,date ,2300,z_Buy2);
tl_new(date, 2100,z_buy3,date ,2300,z_buy3);
end;
-
MC回复讨论四:
if date <> Date[1] then
begin
Y = open;
{通过date<>date[1]来界定这段begin end内部的代码只在白天开盘第一根bar执行,然后取open价格就可以了}
Y_Sell1 = Y + x ;
Y_Sell2 = Y + 2 * x ;
Y_Sell3 = Y + 3 * x ;
y_buy1 = Y - x ;
Y_Buy2 = Y - 2 * x ;
Y_buy3 = Y - 3 * x ;
tl_new(date ,0900,Y,date ,1500,Y);
tl_new(date ,0900,Y_Sell1,date ,1500,Y_Sell1);
tl_new(date ,0900,Y_Sell2,date ,1500,Y_Sell2);
tl_new(date, 0900,y_sell3,date ,1500,y_sell3);
tl_new(date ,0900,y_buy1,date ,1500,y_buy1);
tl_new(date ,0900,Y_Buy2,date ,1500,Y_Buy2);
tl_new(date, 0900,Y_buy3,date ,1500,Y_buy3);
end ;
if time>=2100 and time[1]<=1500 then
{通过time>=2100 and time[1]<=1500来界定这段begin end内部的代码只在夜盘开盘第一根bar执行,然后取open价格就可以了}
begin
z=open;
z_Sell1 = z + x ;
z_Sell2 = z + 2 * x ;
z_Sell3 = z + 3 * x ;
z_buy1 = z - x ;
z_Buy2 = z - 2 * x ;
z_buy3 = z - 3 * x ;
tl_new(date ,2100,z,date ,2300,z);
tl_new(date ,2100,z_Sell1,date ,2300,z_Sell1);
tl_new(date ,2100,z_Sell2,date ,2300,z_Sell2);
tl_new(date, 2100,z_sell3,date ,2300,z_sell3);
tl_new(date ,2100,z_buy1,date ,2300,z_buy1);
tl_new(date ,2100,z_Buy2,date ,2300,z_Buy2);
tl_new(date, 2100,z_buy3,date ,2300,z_buy3);
end;
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 511411198 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容