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
datetime M1,M5,M15,M30,H1,H4,D1,W1,MN1; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ intOnInit() { //--- 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()) { casePERIOD_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; casePERIOD_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; casePERIOD_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; casePERIOD_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; casePERIOD_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; casePERIOD_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; casePERIOD_D1: MessageBox("Switched to Daily Frame"); //Do Something... ObjectCreate(0,"Daily",OBJ_VLINE,0,Time[0],0); D1=Time[0];// store current time break; casePERIOD_W1: MessageBox("Switched to Weekly Frame"); //Do Something... ObjectCreate(0,"Weekly",OBJ_VLINE,0,Time[0],0); W1=Time[0];// store current time break; casePERIOD_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 | //+------------------------------------------------------------------+ voidOnDeinit(constint reason) { //--- destroy timer EventKillTimer(); //--- delete objects ObjectsDeleteAll(0,0,-1); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ voidOnTick() { //--- 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 | //+------------------------------------------------------------------+ voidOnTimer() { //--- ObjectMove(0,"Time",0,TimeCurrent(),0);// Update timeline } //+------------------------------------------------------------------+
何をしようとしているのか、説明してください。
分かり にくくて申し訳ありません。
以下のように3つの「EventSetMillisecondTimer」を設定 する必要があります (うまくいかないとのことですが・・・)。別の方法はないでしょうか?
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ミリ秒ごとに実行されます。
この場合、あまりの速さに端末がフリーズする可能性があります。
//+------------------------------------------------------------------+
//| 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分間は1回しか実行されないので、1分ごとではないことに注意してください。
5分も最初の5分後に一度だけ実行されるので、10分後でも15分後でもない。
例えば、1分ごとにトリガーさせたい場合は、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。
次のような方法で、時間間隔ごとにトリガーすることができます。
Marco vd Heijden:
どのようなメカニズムで、どのようなコードを時間間隔にトリガーさせたいのでしょうか?
あなたは何を達成しようとしている?もう一度、素晴らしいコメント、大きな感謝男。
//---
...私のインジケータは、私が望んでいた(/ / ) である動作します。
インジケータはこのように動作します。
私の懸念を 例として説明 する必要があります。
EURUSDの チャートを開き、私のインジケータをチャートに貼り付けました。私が望むように完璧に動作 し、VLINEを前進(過去も) させ、タイムフレームの期間を変更でき、自動的にその期間に合わせて 間隔を調整します(これは私が望む ことです)。
私のインジケータの問題はどこにあるのでしょうか? // それは問題ではないかもしれませんが、更新するためにもう少し'無関係'な時間がかかります。
もし私が'EventSetMillisecondTimer( 10 );' を選択 し、TIMEFRAME PERIODsを任意の TIMEFRAME PERIODsに変更すると、ほとんど 私は見ない(その時) 新しいVLINEをチャートにロードします(私が欲しいものです)。
ずっとずっとあなたのコメントに感謝します - Marco & whroeder1
(注:私は 'スイッチ演算子'を使用しないでください - あなたの#18コメントは、私がそれをアップグレードし、それに取り組んでいるすべてその後良いので - そしてそれは私のために非常に有用である)。
(英語は私の母国語ではありません)
Keith Watford:
いいね、マルコ。
こんな感じで、時間間隔ごとにトリガーすることもできます。
あと、Keithも いいね :)
本当に助かりました、次のインジケーターに使い たいと思います。
ありがとうございました。
私は他の人のことは知りませんが、あなたのフォント、色、太字、斜体などの組み合わせは気が散って迷惑だと思います。実際、私はこの記事を読むのが面倒くさかったです。
もう一度素晴らしいコメント、大きな感謝男。
//---
...私のインジケータは、私が望んでいた(/ / ) である動作します。
インジケータはこのように動作します。
私の懸念を 例として説明 する必要があります。
EURUSDの チャートを開き、私のインジケータをチャートに貼り付けました。私が望むように完璧に動作 し、VLINEを前進(過去も) させ、タイムフレームの期間を変更でき、自動的にその期間に合わせて 間隔を調整します(これは私が望む ことです)。
私のインジケータの問題はどこにあるのでしょうか? // それは問題ではないかもしれませんが、更新するためにもう少し'無関係'な時間がかかります。
もし私が'EventSetMillisecondTimer( 10 );' を選択 し、TIMEFRAME PERIODsを任意の TIMEFRAME PERIODsに変更すると、ほとんど 私は見ない(その時) 新しいVLINEをチャートにロードします(私が欲しいものです)。
ずっとずっとあなたのコメントに感謝します - 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
}
//+------------------------------------------------------------------+
さらに、新しいキャンドルが発生するたびに行を更新したい場合は、前ページの例と最後の例を組み合わせて、このようにすることができます。
//+------------------------------------------------------------------+
//| 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
}
//+------------------------------------------------------------------+
私は他の人のことは知りませんが、あなたのフォント、色、太字、斜体などの組み合わせは気が散って迷惑だと思います。実際、私はこの記事を読む のが面倒でした。
Max Enrik:
私は他の人のことは知りませんが、あなたのフォント、色、太字、斜体などの組み合わせは気が散って迷惑だと思います。実際、私はこの記事を読む のが面倒でした。