在自定义函数中定义了如下函数:
Function QQMSSG(Formula,QQNum,QQMSG)
'系统会在逐K线模式解释公式时的每个周期都会调用此函数一遍,因此设计时应该注重程序的执行效率,不要重复的执行一些没必要的代码
QQMSSG=0
Set obj = CreateObject("WWSCommon.TCGroup")
call obj.TransMessage(QQNum, QQMSG)
Set obj = Nothing
End Function
然后在PEL语言书写的策略中如下调用:
if VBuy then
begin
buy(1,1,limitr,VOP); {开多}
VQQM:=QQMSSG('金字塔自动交易群X','hello-由金字塔程序发出');
end;
逐K线模式下,运行没有反应.请客服人员帮助解决.谢谢.
你的代码存在2个问题
1,自定义函数只能传递数值参数,不支持字符串
2,在逐周期模式下使用,要加过滤手段,否则会导致多次频繁的发送
一般是应对最后一个周期有效的信号才起作用
GLOBALVARIABLE bb=0;//申明一个全局变量,用于控制过滤
if VBuy then
begin
buy(1,1,limitr,VOP); {开多}
if islastbar and bb<>barpos then
begin
bb:= barpos;
VQQM:=QQMSSG(close,open);
end
end;
上面已将写全了,
按你的方式创建自定义函数,
有具体问题在问吧
按照ADMIN老大的意思写了个测试用的,在逐K线模式下,出了信号后还是不停地发报警声音,直到这个K线走完才停, 怎么样才能只发一次报警声音呢?求再解答一次,监测分笔盘中时的计数器VCountAlert已经与barpos相等,不知为什么还会不停地执行.
///////////////////////////////////////////////////////////////////////////////
//测试用策略:前收盘突破前10周期高点做多,突破前10周期低点做空
//////////////////////////////////////////////////////////////////////////////
GLOBALVARIABLE: VCountAlert=0;//申明一个全局变量,用于控制过滤
VOpenPrice:=open; //定义开仓价
VC:=ref(close,1); //前收盘
VH:=ref(hhv(high,10),2); //前2周期的10周期内高点
VL:=ref(llv(low,10),2); //前2周期的10周期内低点
if VC>VH then
begin
if holding<0 then sellshort(1,0,limitr,VOpenPrice);{平空}
if holding=0 then
begin
buy(1,1,limitr,VOpenPrice); {开多}
if islastbar and VCountAlert<>barpos then
begin
VCountAlert:= barpos;
playsound(1,'.\Alarm.wav');
end;
end;
end;
if VC<VL then
begin
if holding>0 then sell(1,0,limitr,VOpenPrice); {平多}
if holding=0 then
begin
buyshort(1,1,limitr,VOpenPrice); {开空}
if islastbar and VCountAlert<>barpos then
begin
VCountAlert:= barpos;
playsound(1,'.\Alarm.wav');
end;
end;
end;
在程序最后加上ViewVCountAlert:VCountAlert,linethick0,coloryellow;
分笔回放显示,在条件成立时VCountAlert等于barpos,条件结束后下一K线时,VCountAlert=0了,和设计它保存
条件成立时的barpos值不同,为什么呢,它不是全局变量吗?百思不得其解啊.为何新K线时被清零了.
针对上面的问题,我总结一下,可以用两个步骤解决传递字符串问题:
1、在Perl语言中使用extgbdatsset函数将要传递的字符串写到全局变量;
2、在自定义函数中使用document.getExtData获取该全局变量,然后进行发送。
如:
if VBuy then
begin
buy(1,1,limitr,VOP); {开多}
if islastbar and bb<>barpos then
begin
bb:= barpos;
extgbdataSet('字符串','开多信号:'+numtostr(close,0)); //这里的‘字符串’是你自己取的变量名
VQQM:=QQMSSG(close,open);
end
end;
在VBA的自定义函数中这样写:
QQMSG=document.getextData("字符串") '获取公式中设置的变量值
Set obj = CreateObject("WWSCommon.TCGroup")
call obj.TransMessage(QQNum, QQMSG)
Set obj = Nothing