如何启用即时行情模式(平台设置);我的代码要在集合竟价时段下单。
Params
Numeric StartTime(925); // 9:25
Numeric jEndTime(929); // 9:29
Vars
Bool LockPositionSent(False);
Numeric CurrentHHMM;
Numeric LastPrice;
Numeric Upper;
Numeric Lower;
Events
OnBar(ArrayRef<Integer> indexs)
{
// 添加调试信息,确认事件触发时间
// Print("OnBar触发于:", Text(Time));
CurrentHHMM = Hour * 100 + Minute;
// 9:30后重置标记
if (CurrentHHMM > 930)
{
LockPositionSent = False;
return;
}
// 仅在9:25-9:29区间处理锁仓平单
if (CurrentHHMM >= StartTime && CurrentHHMM <= jEndTime)
{
// 添加持仓信息打印
// Print("当前持仓 - 多仓:", A_BuyPosition, " 空仓:", A_SellPosition);
if (A_BuyPosition > 0 && A_SellPosition > 0 && !LockPositionSent)
{
// 获取价格
LastPrice = Close;
Upper = Q_UpperLimit;
Lower = Q_LowerLimit;
// 确保价格在涨跌停范围内
if (Upper > 0 && Lower > 0)
{
// 添加价格验证
if (LastPrice < Lower) LastPrice = Lower;
if (LastPrice > Upper) LastPrice = Upper;
}
// 平多仓
Numeric orderRef1 = A_SendOrder(Enum_Sell, Enum_Exit, A_BuyPosition, LastPrice);
if (orderRef1 < 0)
Print("平多仓失败! 错误:", GetLastError);
// 平空仓
Numeric orderRef2 = A_SendOrder(Enum_Buy, Enum_Exit, A_SellPosition, LastPrice);
if (orderRef2 < 0)
Print("平空仓失败! 错误:", GetLastError);
LockPositionSent = True;
// 添加交易确认信息
Commentary("锁仓平单已发送 | 时间:", Text(CurrentHHMM),
" | 价格:", Text(LastPrice),
" | 多仓:", Text(A_BuyPosition),
" | 空仓:", Text(A_SellPosition));
}
}
}如何启用即时行情模式(平台设置)?