在开盘30分钟后准备入场;
上轨=开盘后30分钟高点;
下轨=开盘后30分钟低点;
用法:
当价格突破上轨,买入开仓;
当价格跌穿下轨,卖出开仓。
止损:
当买入开仓后;最小价格变动N1个单位 止损。
当卖出开仓后;最小价格变动N2个单位止损。
止盈:
当买入开仓后:最小价格变动N3个单位止盈。
当卖出开仓后:最小价格变动N4个单位止盈。
如果止盈止损都不触及,收盘平仓。
请各位老师能帮忙写下代码。感谢!
谢谢老师。
//N1,N2,N3,N4可以自行定义
//适用周期一分钟
t1:=time>090000 and time<145500;
t2:=time>=145500;
shanggui:=valuewhen(todaybar<=30,hhv(h,todaybar));
xiagui:=valuewhen(todaybar<=30,llv(l,todaybar));
if h>shanggui and t1 then buy(holding=0,1,market);
if l<xiagui and t1 then buyshort(holding=0,1,market);
if c-enterprice>n1*mindiff and holding<0 then sellshort(1,0,market);//止损空头
if enterprice-c>n2*mindiff and holding>0 then sell(1,0,market);//止损多头
if c-enterprice>n3*mindiff and holding>0 then sell(1,0,market);//多头止盈
if enterprice-c>n4*mindiff and holding<0 then sellshort(1,0,market);//空头止盈
if t2 then BEGIN
sellshort(1,0,market);
sell(1,0,market);
end//收盘平仓
//N1,N2,N3,N4可以自行定义
//适用周期一分钟
INPUT:N1(10,1,100,10),N2(10,1,100,10),N3(50,1,100,20),N4(50,1,200,20)
t1:=time>090000 and time<145500;
t2:=time>=145500;
shanggui:=valuewhen(todaybar<=30,hhv(h,todaybar));
xiagui:=valuewhen(todaybar<=30,llv(l,todaybar));
if h>shanggui and t1 then buy(holding=0,1,market);
if l<xiagui and t1 then buyshort(holding=0,1,market);
if c-enterprice>n1*mindiff and holding<0 then sellshort(1,0,market);//止损空头
if enterprice-c>n2*mindiff and holding>0 then sell(1,0,market);//止损多头
if c-enterprice>n3*mindiff and holding>0 then sell(1,0,market);//多头止盈
if enterprice-c>n4*mindiff and holding<0 then sellshort(1,0,market);//空头止盈
if t2 then BEGIN
sellshort(1,0,market);
sell(1,0,market);
end//收盘平仓
---------------------------------------------------------------------------------------
在编译的时候还提示未定义T1,但是这句t1:=time>090000 and time<145500;
不是已经定义了T1了吗?
菜鸟问题较多,还请老师多多包涵。
INPUT:N1(10,1,100,10),N2(10,1,100,10),N3(50,1,100,20),N4(50,1,200,20)
老师,在这句话后加个分号以后测试成功了。
经过测试以后,我发现设置的止损系数是10个点,但止损后发现会有大于10个点的情形出现。我对照图找了以后发现,应该是止损的时候按照当根止损K线的收盘时的价格计算的。
希望老师能帮我改成到10个点止损系数后,就按当时的价格立刻止损掉,等于是固定点数的止损。(止盈也是如此)
还有就是如果有止盈止损情况出现后,当日不在开仓。还有就是老师写的代码为什么注释是 适合一分钟的,希望能写成适合5分钟的。
感谢jinzhe老师百忙抽空解答菜鸟的问题。
测评是做不到触发价的,只能是开高低收4个中的一个来编写,如果觉得收盘价不行,那么你改这个自己认为正确的价格
使用5分钟,把上面的
shanggui:=valuewhen(todaybar<=30,hhv(h,todaybar));
xiagui:=valuewhen(todaybar<=30,llv(l,todaybar));
改成
shanggui:=valuewhen(todaybar<=6,hhv(h,todaybar));
xiagui:=valuewhen(todaybar<=6,llv(l,todaybar));
再次感谢jinzhe老师的耐心解答。
那样的话 止损 止盈 是不是无法使用一个固定的限值来说明。
然后就是 能不能在止损止盈以后 不在开单呢,意思就是一天只开一单。我测试了下后,止损过以后 当天还是会开单的。