比如说金叉出现 延时30秒 执行开多仓 这个延时器要怎么写
//------------------------------------------------------------------------
// 简称: waitNSecs
// 名称: 等待N秒函数
// 类别: 用户函数
// 类型: 用户函数
// 输出: 布尔型
//------------------------------------------------------------------------
Params
Numeric waitSecs(10); //等待多少秒
Vars
TimeStamp tm1;
TimeStamp tm2;
Numeric looptime;
Begin
tm1 = Systemtimestamp();
looptime = 0;
While(looptime<waitSecs*1000)
{
tm2 = SystemTimestamp();
looptime = DateTimeDiffV2(tm1,tm2);
}
Return True;
End
测试可以用下面的代码:
Events
OnBar(ArrayRef<Integer> indexs)
{
If(Barstatus==2)
{
Numeric tm1 = SystemDateTime;
FileAppend("d:\\test20221225.txt", "tm1="+DateTimeToString(tm1));
waitNSecs(10);
Numeric tm2 = SystemDateTime;
FileAppend("d:\\test20221225.txt","tm2=" + DateTimeToString(tm2));
FileAppend("d:\\test20221225.txt","延时=" + Text(DateTimeDiff(tm1,tm2)));
}
}
Params
Numeric FastLength(5);// 短期平均线参数
Numeric SlowLength(20);// 长期平均线参数
Vars
Series<Numeric> AvgValue1;
Series<Numeric> AvgValue2;
Events
OnBar(ArrayRef<Integer> indexs)
{
AvgValue1 = AverageFC(Close,FastLength);
AvgValue2 = AverageFC(Close,SlowLength);
PlotNumeric("MA1",AvgValue1);
PlotNumeric("MA2",AvgValue2);
//多头止盈止损
If(MarketPosition >0 && High>EntryPrice+100)
{
Sell(0,Max(O,EntryPrice+10));//止盈
}
//空头止盈止损
If(MarketPosition >0 && Low<EntryPrice-100)
{
Buytocover(0,Min(O,EntryPrice-100));//止盈
}
If(MarketPosition <>1 && AvgValue1[1]> AvgValue2[1])
{
Buy(0,Open);
}
If(MarketPosition <>-1 && AvgValue1[1]< AvgValue2[1])
{
SellShort(0,Open);
}
}
帮我写到策略里
您好。延时30秒的函数,我回头给您写一个
在吗4
、
没看懂
函数和示例都给您写好了,策略就自己写吧。