求助,根据ADMIN的建议,写了如下测试用策略,
实现目的:要求逐K线模式下在符合条件的1根K线内只执行一次符合条件的指令
(符合条件的K线中,要求只执行一次报警声音)
程序中有一处不解:为何单步执行到VCountAlert:= barpos之后时,在调试窗口看此值仍为0,并未被赋值,
结果在当前K线一直符合条件的过程中,下一条件VCountAlert<>barpos也始终=1,接着就执行了下面的不停
报警声音的过程.
程序如下:请高手解答,或有其他方式实现.
//===========================================================
//测试用策略,分笔回放测试,在1分钟图表中,橡胶1205
//突破前10周期高点开多,突破前10周期低点开空
//===========================================================
GLOBALVARIABLE: VCountAlert=0;//申明一个全局变量,用于控制过滤
runmode:0; //逐K线模式
VOpenPrice:=open; //定义开仓价
VC:=ref(close,1); //定义前收盘
VH:=ref(hhv(high,10),2); //前10周期最高
VL:=ref(llv(low,10),2); //前10周期最低
//===========================================================
//画高低线
ViewVH:VH,linethick1,coloryellow;
ViewVL:VL,linethick1,colorblue;
//===========================================================
//前收盘大于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
//此处赋值语句在调试窗口单步执行完后看此值为0,不解,造成当前K线不能实现执行一次此过程的目的.
VCountAlert:= barpos;
//同上,在当前K线当中声音报警语句还是被不停在执行直到当前K线结束
playsound(1,'.\Alarm.wav');
end;
end;
end;
//===========================================================
//前收盘小于10周期低点则平多开空
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
//此处赋值语句在调试窗口单步执行完后看此值为0,不解,造成当前K线不能实现执行一次此过程的目的.
VCountAlert:= barpos;
//同上,在当前K线当中声音报警语句还是被不停在执行直到当前K线结束
playsound(1,'.\Alarm.wav');
end;
end;
end;
//===========================================================
//显示计数器
ViewVCountAlert:VCountAlert,linethick0,coloryellow;
//===========================================================
playsound(最后一个周期有效):该函数一般用在后台预警时使用,不建议在图表使用因为会导致每来一笔数据就刷新重新播报一次。
只执行一次报警声音的,以前帖子中给出的一个方法
//已经是完整代码, condition换为自己的条件即可
//怎样通过全局变量控制PLAYSOUND函数只播报一遍声音
//后台
condition:=1;
if condition and islastbar and barpos>extgbdata('t') then begin//condition改为相应的条件
playsound(1,'C:\Weisoft Stock\SOUND1.wav');
extgbdataset('t',barpos);
end