凌晨盘口卡十几秒 EA拿旧价算指标 写了个监控脚本
凌晨这盘挺怪的,纳指还涨着1.83,道指跌幅都收窄到0.05了,可报价卡住的时候照样能把EA坑死。我这边凌晨经常2个tick之间隔十几秒,EA拿旧价算出来的指标全是糊的,该止损它也看不见。写了个小脚本跑1分钟采样,统计这段时间来了多少个tick,点差最大拉到多少点,平均间隔太稀或者点差突然炸开就直接弹窗写日志。参数就采样秒数、间隔阈值、点差点数3个,脚本只报警不下单,挂哪个品种都行。凌晨挂单前先跑一遍,别在死盘上开仓。
//+------------------------------------------------------------------+
//| _tickwatch.mq5 报价停滞与点差突变监控(只报警不下单) |
//+------------------------------------------------------------------+
#property copyright "MT54"
#property version "1.00"
#property script_show_inputs
input int InpWaitSec = 60; // 采样时长(秒)
input int InpStaleSec = 15; // 平均报价间隔阈值(秒)
input int InpSpreadPts= 30; // 点差突变阈值(点)
input bool InpAlert = true;// 弹窗提醒
input bool InpLog = true;// 写日志
string g_file = "tickwatch_log.csv";
void Log(string msg)
{
if(!InpLog) return;
int h = FileOpen(g_file, FILE_READ|FILE_WRITE|FILE_CSV|FILE_ANSI);
if(h == INVALID_HANDLE) return;
FileSeek(h, 0, SEEK_END);
FileWrite(h, TimeToString(TimeCurrent(), TIME_DATE|TIME_MINUTES), msg);
FileClose(h);
}
void OnStart()
{
int ticks = 0;
double maxSpread = 0.0;
double minSpread = 0.0;
long lastMs = 0;
ulong start = GetTickCount64();
while((int)((GetTickCount64() - start) / 1000) < InpWaitSec)
{
MqlTick tick;
if(SymbolInfoTick(_Symbol, tick))
{
if((long)tick.time_msc != lastMs)
{
lastMs = (long)tick.time_msc;
ticks++;
double sp = (tick.ask - tick.bid) / _Point;
if(ticks == 1 || sp > maxSpread) maxSpread = sp;
if(ticks == 1 || sp < minSpread) minSpread = sp;
}
}
Sleep(200);
}
string txt = _Symbol + " 采样" + IntegerToString(InpWaitSec) + "秒 tick数="
+ IntegerToString(ticks)
+ " 最大点差=" + DoubleToString(maxSpread, 1)
+ " 最小点差=" + DoubleToString(minSpread, 1);
if(ticks == 0)
txt = txt + " 全程零报价,盘面可能已经断了";
double gap = (ticks > 0) ? (double)InpWaitSec / (double)ticks : 999.0;
if(ticks > 0 && gap > (double)InpStaleSec)
txt = txt + " 平均间隔" + DoubleToString(gap, 1) + "秒,报价太稀";
if(maxSpread >= (double)InpSpreadPts)
txt = txt + " 点差突然炸开,别挂市价单";
Print(txt);
Log(txt);
if(InpAlert) Alert(txt);
}
//+------------------------------------------------------------------+
全部回复(19)
发表回复
请先登录后再回复。
