指标杂项问题 - 页 5

 
Marco vd Heijden:
请描述你想做什么。

对不起,我弄糊涂 了。

我需要像下面那样设置3个'EventSetMillisecondTimer' (你说它不起作用...)请问有其他的方法吗?

EventSetMillisecondTimer( 10   ); // 1st will read in 10   | if won't read try next
EventSetMillisecondTimer( 250  ); // 2nd will read in 250  | if won't read try next
EventSetMillisecondTimer( 1250 ); // 3rd will read in 1250 | if read then stop reading till next PERIOD_M5

最好。

 

计时器只在OnInit()函数中设置一次。

如果你想重新初始化,你必须先杀死旧的定时器,这通常发生在OnDeinit()函数上。

就像我说的,你也可以使用一个计数器。

如果你把代码放在例如一个10毫秒的定时器中,那么代码将每10毫秒执行一次。

这很可能会使你的终端冻结,因为它太快了。

int counter;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(1);// 1 second

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//--- increment counter
   counter++;
//--- comment status on the chart
   Comment(IntegerToString(counter));  
//--- switch timer  
   switch(counter)
     {
      case 60:
         Alert(" 1 Minute ");
         // Do Something...
         break;
      case 300:
         Alert(" 5 Minutes ");
         // Do Something...
         break;
      case 900:
         Alert(" 15 Minutes ");
         // Do Something...
         counter=0;// Reset counter on highest value.
         break;
     }
// end switch timer    
   if(counter>900)
     {
      counter=0;// Safety Mechanism
     }
  }
//+------------------------------------------------------------------+

请注意,1分钟只触发一次,所以不是每分钟。

5分钟也只在前5分钟后触发一次,所以不是在10分钟也不是在15分钟的时候。

如果你想每分钟触发一次,你必须为60秒、120秒、180秒等添加代码

15分钟的标记将每15分钟触发一次,因为它把计数器设置为零。


你想使用什么机制,你想在定时的时间间隔内触发什么代码?

你想达到什么目的?
 

void OnTimer()
  {
   static int counter=0;
   static int next1m=60;
   static int next5m=300;
   static int next15m=900;
//--- increment counter
   counter++;
//--- comment status on the chart
   Comment(IntegerToString(counter));  
//--- timer
   if(counter==next1m)
         {
         Alert(" 1 Minute ");
         // Do Something...
         next1m+=60;
         }
   if(counter==next5m)
         {
         Alert(" 5 Minutes ");
         // Do Something...
         next5m+=300;
         }
   if(counter==next15m)
         {
         Alert(" 15 Minutes ");
         // Do Something...
         counter=0;// Reset counter on highest value.
         next1m=60;
         next5m=300;
         }
  }

好主意,马可。

你可以做这样的事情,在每个时间间隔触发

 

Marco vd Heijden:

你想用什么机制,你想用什么代码来触发定时的间隔?

你想达到什么目的?
谢谢你的精彩评论,那条评论更清楚地解释了 "开关 "操作符时间间隔

再次感谢你的评论,非常感谢

//---

现在,我需要给你关于我这个指标的信息
因为 可能没有描述我所关心的问题(但你的最新评论对我帮助越来越大)...

......我的指标是按照我的要求 /是) 工作的。

指标是这样工作的。

自动向前 移动/显示 "VLINE"(我想要的)
向我显示过去一周 的 "VLINE"(我想要的)
没有交叉的 周期线(我想要的)
连续升级(有间隔) 每隔一次就显示一次 下一个PERIOD_**的 (我想要的)
还有更多 更多...
再次特别感谢 Marco whroeder1 (不仅帮助了我,还教了我很多)。

我需要用例子来说明 我的问题

我打开欧元兑美元 的图表,并将我的指标附在图表上,工作得很完美,就像我想要的那样,移动/显示向前(甚至过去) 的VLINE,我可以改变TIMEFRAME PERIOD,并自动适应 该PERIODs(这是我想要的)

我的指标问题在哪里? //也许这不是一个问题,但它需要多一点 "不相关 "的时间来更新。

如果我选择'EventSetMillisecondTimer( 10 );',然后我将TIMEFRAME PERIODs改为任何 TIMEFRAME PERIODs,几乎 我看不到(当它) 加载新的VLINE到图表上(我想要的)

此时,如果我将欧元兑美元 改为"其他符号 (如英镑兑美元,等等)",我的指标就不会加载完整的VLINE。这只是一个问题 (/对我来说)

否则。如果我选择 "EventSetMillisecondTimer( 1250 );",我没有看到任何关于加载的问题。它工作得非常好
但这里有一个问题 (/对我来说)当我改变TIMEFRAME PERIODs时,它需要更多的"不相关 " 时间

所以,如果你能清楚地 理解我,请花点时间来评论(并帮助我如何解决这个问题),或者你不能清楚 理解 我,不要浪费你的时间,

非常感谢你的评论 - Marco & whroeder1


(注意:我没有使用'开关运算符'--因为你的#18评论比一切都好,这是我升级了它,并且正在努力--它对我非常有用)

(英语不是我的母语)

 

Keith Watford:

好样的,马可。

你可以这样做,在每个时间间隔触发

也很好,基思。)

这对我帮助很大,我将在我的下一个指标中使用它

祝您一切顺利。

 

我不知道其他人怎么想,但我发现你的字体、颜色、粗体和斜体等的组合让人心烦意乱,令人讨厌。事实上,我都懒得看这个帖子了。

Max Enrik:
谢谢你的精彩评论,那条评论更清楚地解释了 "开关 "运算符时间间隔

再次感谢你的评论,非常感谢

//---

现在,我需要给你关于我这个指标的信息
因为 可能没有描述我所关心的问题(但你的最新评论对我帮助越来越大)...

......我的指标是按照我的要求 /是) 工作的。

指标是这样工作的。

自动向前 移动/显示 "VLINE"(我想要的)
向我显示过去一周 的 "VLINE"(我想要的)
没有交叉的 周期线(我想要的)
连续升级(有间隔) 每隔一次就显示一次 下一个PERIOD_**的 (我想要的)
还有更多 更多...
再次特别感谢 Marco whroeder1 (不仅帮助了我,还教了我很多)。

我需要用例子来说明 我的问题

我打开欧元兑美元 的图表,并将我的指标附在图表上,工作得很完美,就像我想要的那样,移动/显示向前(甚至过去) 的VLINE,我可以改变TIMEFRAME PERIOD,并自动适应 该PERIODs(这是我想要的)

我的指标问题在哪里? //也许这不是一个问题,但它需要多一点 "不相关 "的时间来更新。

如果我选择'EventSetMillisecondTimer( 10 );',然后我将TIMEFRAME PERIODs改为任何 TIMEFRAME PERIODs,几乎 我看不到(当它) 加载新的VLINE到图表上(我想要的)

此时,如果我将欧元兑美元 改为"其他符号 (如英镑兑美元,等等)",我的指标就不会加载完整的VLINE。这只是一个问题 (/对我来说)

否则。如果我选择 "EventSetMillisecondTimer( 1250 );",我没有看到任何关于加载的问题。它工作得非常好
但这里有一个问题 (/对我来说)当我改变TIMEFRAME PERIODs时,它需要更多的"不相关 " 时间

所以,如果你能清楚地 理解我,请花点时间来评论(并帮助我如何解决这个问题),或者你不能清楚 理解 我,不要浪费你的时间,

非常感谢你的评论 - Marco & whroeder1


(注意:我没有使用'开关运算符'--因为你的#18评论比一切都好,这是我升级了它,并且正在努力--它对我非常有用)

(英语不是我的母语)

 

如果是关于切换时间段,那么计时器不是一个好的选择,因为计时器在切换框架时被破坏。

你可以在OnInit()函数 中创建你的线条,并在OnTick()或OnTimer()函数中更新它们。

这里有一个例子。

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(60);
//--- playsound
   PlaySound("alert2.wav");  
//--- create moving timeline
   ObjectCreate(0,"Time",OBJ_VLINE,0,TimeCurrent(),0);  
//--- detect period
   switch(Period())
     {
      case PERIOD_M1:
        MessageBox("Switched to 1 Minute Frame");
        //Do Something...
        ObjectCreate(0,"1-Minute",OBJ_VLINE,0,Time[0],0);
         break;
      case PERIOD_M5:
        MessageBox("Switched to 5 Minutes Frame");
        //Do Something...
        ObjectCreate(0,"5-Minutes",OBJ_VLINE,0,Time[0],0);
         break;
      case PERIOD_M15:
        MessageBox("Switched to 15 Minutes Frame");
        //Do Something...
        ObjectCreate(0,"15-Minutes",OBJ_VLINE,0,Time[0],0);
         break;
      case PERIOD_M30:
        MessageBox("Switched to 30 Minutes Frame");
        //Do Something...
        ObjectCreate(0,"30-Minutes",OBJ_VLINE,0,Time[0],0);
         break;
      case PERIOD_H1:
        MessageBox("Switched to 1 Hour Frame");
        //Do Something...
        ObjectCreate(0,"1-Hour",OBJ_VLINE,0,Time[0],0);
         break;
      case PERIOD_H4:
        MessageBox("Switched to 4 Hour Frame");
        //Do Something...
        ObjectCreate(0,"4-Hour",OBJ_VLINE,0,Time[0],0);
         break;
      case PERIOD_D1:
        MessageBox("Switched to Daily Frame");
        //Do Something...
        ObjectCreate(0,"Daily",OBJ_VLINE,0,Time[0],0);
         break;
      case PERIOD_W1:
        MessageBox("Switched to Weekly Frame");
        //Do Something...
        ObjectCreate(0,"Weekly",OBJ_VLINE,0,Time[0],0);
         break;
      case PERIOD_MN1:
        MessageBox("Switched to Monthly Frame");
        //Do Something...
        ObjectCreate(0,"Monthly",OBJ_VLINE,0,Time[0],0);
         break;
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
//--- delete objects
   ObjectsDeleteAll(0,0,-1);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   ObjectMove(0,"Time",0,TimeCurrent(),0);// Update timeline
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   ObjectMove(0,"Time",0,TimeCurrent(),0);// Update timeline
  }
//+------------------------------------------------------------------+
还请注意OnDeint()函数中的ObjectsDeleteAll(),这将确保在新帧上再次创建之前所有的东西都被删除。
 

另外,如果你想在出现新的蜡烛时更新这些线,你可以把前一页的例子和上一页的例子结合起来,这样就可以了。

datetime M1,M5,M15,M30,H1,H4,D1,W1,MN1;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(60);
//--- playsound
   PlaySound("alert2.wav");
//--- load open times
   M1=iTime(Symbol(),PERIOD_M1,0);
   M5=iTime(Symbol(),PERIOD_M5,0);
   M15=iTime(Symbol(),PERIOD_M15,0);
   M30=iTime(Symbol(),PERIOD_M30,0);
   H1=iTime(Symbol(),PERIOD_H1,0);
   H4=iTime(Symbol(),PERIOD_H4,0);
   D1=iTime(Symbol(),PERIOD_D1,0);
   W1=iTime(Symbol(),PERIOD_W1,0);
   MN1=iTime(Symbol(),PERIOD_MN1,0);  
//--- create moving timeline
   ObjectCreate(0,"Time",OBJ_VLINE,0,TimeCurrent(),0);  
//--- detect period
   switch(Period())
     {
      case PERIOD_M1:
        MessageBox("Switched to 1 Minute Frame");
        //Do Something...
        ObjectCreate(0,"1-Minute",OBJ_VLINE,0,Time[0],0);
        M1=Time[0];// store current time
         break;
      case PERIOD_M5:
        MessageBox("Switched to 5 Minutes Frame");
        //Do Something...
        ObjectCreate(0,"5-Minutes",OBJ_VLINE,0,Time[0],0);
        M5=Time[0];// store current time
         break;
      case PERIOD_M15:
        MessageBox("Switched to 15 Minutes Frame");
        //Do Something...
        ObjectCreate(0,"15-Minutes",OBJ_VLINE,0,Time[0],0);
        M15=Time[0];// store current time
         break;
      case PERIOD_M30:
        MessageBox("Switched to 30 Minutes Frame");
        //Do Something...
        ObjectCreate(0,"30-Minutes",OBJ_VLINE,0,Time[0],0);
        M30=Time[0];// store current time
         break;
      case PERIOD_H1:
        MessageBox("Switched to 1 Hour Frame");
        //Do Something...
        ObjectCreate(0,"1-Hour",OBJ_VLINE,0,Time[0],0);
        H1=Time[0];// store current time
         break;
      case PERIOD_H4:
        MessageBox("Switched to 4 Hour Frame");
        //Do Something...
        ObjectCreate(0,"4-Hour",OBJ_VLINE,0,Time[0],0);
        H4=Time[0];// store current time
         break;
      case PERIOD_D1:
        MessageBox("Switched to Daily Frame");
        //Do Something...
        ObjectCreate(0,"Daily",OBJ_VLINE,0,Time[0],0);
        D1=Time[0];// store current time
         break;
      case PERIOD_W1:
        MessageBox("Switched to Weekly Frame");
        //Do Something...
        ObjectCreate(0,"Weekly",OBJ_VLINE,0,Time[0],0);
        W1=Time[0];// store current time
         break;
      case PERIOD_MN1:
        MessageBox("Switched to Monthly Frame");
        //Do Something...
        ObjectCreate(0,"Monthly",OBJ_VLINE,0,Time[0],0);
        MN1=Time[0];// store current time
         break;
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
//--- delete objects
   ObjectsDeleteAll(0,0,-1);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- update timeline
   ObjectMove(0,"Time",0,TimeCurrent(),0);
//--- check for new candles
   if(M1!=iTime(Symbol(),PERIOD_M1,0))
    {
     Alert("New candle on M1");
     ObjectMove(0,"1-Minute",0,iTime(Symbol(),PERIOD_M1,0),0); // Move line
     M1=iTime(Symbol(),PERIOD_M1,0);// Overwrite old with new value
    }  
   if(M5!=iTime(Symbol(),PERIOD_M5,0))
    {
     Alert("New candle on M5");
     M1=iTime(Symbol(),PERIOD_M5,0);// Overwrite old with new value
    }      
   if(M15!=iTime(Symbol(),PERIOD_M15,0))
    {
     Alert("New candle on M15");
     M15=iTime(Symbol(),PERIOD_M15,0);// Overwrite old with new value
    }
   if(M30!=iTime(Symbol(),PERIOD_M30,0))
    {
     Alert("New candle on M30");
     M30=iTime(Symbol(),PERIOD_M30,0);// Overwrite old with new value
    }
    // and so on to MN1...        
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   ObjectMove(0,"Time",0,TimeCurrent(),0);// Update timeline
  }
//+------------------------------------------------------------------+
如果还有什么问题,请展示一些代码。
 
Keith Watford:

我不知道其他人怎么想,但我发现你的字体、颜色、粗体和斜体等的组合让人心烦意乱,令人讨厌。事实上,我都懒得看这个帖子 了。

我被告知不要浪费你的时间。
 

Max Enrik:

基思-沃特福德

我不知道其他人怎么想,但我发现你的字体、颜色、粗体和斜体等的组合让人心烦意乱,令人讨厌。事实上,我都懒得看这个帖子 了。


我说过不要浪费你的时间。
你为什么只引用我的帖子而不发表任何评论?