老周 发表于 2016-11-8 15:04:32

有效交易时间段函数

在实战策略中常常要求在指定的时间段内进行交易, 这里提供一个标准的 “有效交易时间段函数” ,函数返回 true,表示有效,返回 false 表示无效。


调用范例:

iValidTime(“02:30”,”22:50”,true);

如果服务器时间在 2:30~22:50 之间,返回 true。

iValidTime(“16:30”,”12:20”,false);
如果计算机时间在当日 16:30~次日 12:20 之间,返回 true。

以下是函数源码。

/*
函 数:有效时间段
输入参数:string myStartTime:开始时间,标准格式为 MM:SS
string myEndTime:结束时间,标准格式为 MM:SS
bool myServerTime:true 为服务器时间, false 为计算机时间
输出参数:true:有效 false:无效
算 法:
*/
bool iValidTime(string myStartTime,string myEndTime,bool myServerTime)
{
bool myValue=false;
int myST=StrToTime(myStartTime);
int myET=StrToTime(myEndTime);
if (myST>myET) myET=myET+1440*60;
if (TimeCurrent()>myST && TimeCurrent()<myET && myServerTime==true)//服务器时间
{
myValue=true;
}
if (TimeLocal()>myST && TimeLocal()<myET && myServerTime==false)//计算机时间
{
myValue=true;
}
if (myST==myET) myValue=true;
return(myValue);
}

eetuvvyovw 发表于 2018-9-20 16:02:06

不错,支持下楼主

Reset 发表于 2023-12-5 04:28:28

感谢,分享,实测了下,完全可用{:1_210:}
页: [1]
查看完整版本: 有效交易时间段函数