mql5语言的特点、微妙之处以及技巧 - 页 96

 

顺便说一下,GetSystemTimePreciseAsFileTime非常有趣。在MQL中非常缺少这样的函数,或者至少是四舍五入到微/毫秒。 以秒为单位的时间太粗糙了。 在MT本身中,到处都是使用毫秒。 现在我们必须通过使用相同的GetMicrosecondCount 来合成精确的时间。

long TimeLocal_mcs() 
{ 
  static long time0_mcs= 0;
  if (time0_mcs==0) { datetime t=TimeLocal();  while(TimeLocal()==t);  time0_mcs= (t+1)*1 e6 - GetMicrosecondCount(); }
  datetime time= TimeLocal();
  long time_mcs= time0_mcs + GetMicrosecondCount();
  long delta= time_mcs - time*(long)1 e6; 
  if (delta<0) { time0_mcs-=delta;  time_mcs-=delta; }  
  return time_mcs;
}
 
阿列克谢-纳沃伊科夫

顺便说一下,GetSystemTimePreciseAsFileTime非常有趣。我们在MQL中真的需要这样一个函数,或者至少四舍五入到微/毫秒。 以秒为单位的时间太粗糙了。 在MT本身中,毫秒的使用无处不在。 现在我们必须通过使用相同的GetMicrosecondCount函数来合成准确的时间。

通过WinApi功能在MCS中创建你自己的回调,并生成回调。

 
康斯坦丁

通过WinApi功能在MCS中创建你自己的回调,并生成回调。

回调是为了什么?

 
阿列克谢-纳沃伊科夫

回调是为了什么?

好吧,如果你想要整个线程,那么一个函数环就足够了,而如果你想要处理事件,那么一个回调

 
检查你的工作(我不知道市场的情况)是否有隐身机制。你可能会严重 "中招"...
 
老话题,但非常简单的代码就能理解这个问题

关于交易、自动交易系统和测试交易策略的论坛

如何在调用PositionOpen后检查订单是否被执行

fxsaber, 2018.08.09 20:35

试试这个脚本ForexTimeFXTM-Demo01 (或FXOpen-MT5)。

#include <Trade/Trade.mqh>

void OnStart()
{
  const int PrevTotal = PositionsTotal();
  
  CTrade Trade;  
  
  while (PositionsTotal() == PrevTotal)
    Trade.Buy(1);    
}

有时会有两个新职位空缺,而不是一个。


脚本试图打开一个新的位置,但有时我们得到两个。

 
fxsaber:
一个老话题,但相当简单的代码来理解这个问题

脚本试图打开一个新的位置,有时我们得到两个。

这有点像在QB中已经有了一个解决方案。

//+------------------------------------------------------------------+
//| Возвращает "неопределённое" состояние торгового окружения        |
//+------------------------------------------------------------------+
bool IsUncertainStateEnv(const string symbol_name,const ulong magic_number)
  {
   if(MQLInfoInteger(MQL_TESTER)) return false;
   int total=OrdersTotal();
   for(int i=total-1; i>WRONG_VALUE; i--)
     {
      if(OrderGetTicket(i)==0) continue;
      if(OrderGetInteger(ORDER_TYPE)>ORDER_TYPE_SELL) continue;
      if(OrderGetInteger(ORDER_MAGIC)!=magic_number) continue;
      if(!OrderGetInteger(ORDER_POSITION_ID) && OrderGetString(ORDER_SYMBOL)==symbol_name)
         return true;
     }
   return false;
  }

//+------------------------------------------------------------------+
//| Заполняет массивы тикетов позиций                                |
//+------------------------------------------------------------------+
bool FillingListTickets(const uint number_of_attempts)
  {
//--- Проверка состояния окружения
   int n=0,attempts=int(number_of_attempts<1 ? 1 : number_of_attempts);
   while(IsUncertainStateEnv(symb,InpMagic) && n<attempts && !IsStopped())
     {
      n++;
      Sleep(sleep);
     }
   if(n>=attempts && IsUncertainStateEnv(symb,InpMagic))
     {
      Print(__FUNCTION__,": Uncertain state of the environment. Please try again.");
      return false;
     }
//---

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- Проверка нулевых цен
   if(!RefreshRates() || Point()==0) return;
//--- Заполнение списков тикетов позиций
   int positions_total=PositionsTotal();
   if(prev_total!=positions_total)
     {
      if(FillingListTickets(num_attempts))
         prev_total=positions_total;
      else return;
     }

 
fxsaber:
检查你的工作(市场呢--我不知道)是否有隐身机制。你可能会被严重 "抓住"...

按照链接,但没有理解有关的隐身机制。

 
阿列克谢-纳沃伊科夫

按照链接,但没有理解隐形机制。

该指标在图表上处于隐藏模式。它删除了专家顾问。我从手机上的快速浏览中了解到了这一点。

 
阿列克谢-纳沃伊科夫

按照链接,但没有理解隐形机制。

它不能被移除。