Indicator Miscellaneous Questions - page 5

 
Marco vd Heijden:
Please describe what you are trying to do.

Sorry for the confusion.

I need to set 3 'EventSetMillisecondTimer' like below (you said it does not work...). Is there available alternative way, please?

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

Best.

 

The timer is set only once in the OnInit() function.

If you want to reinitialize you have to kill the old timer first this usually happens on OnDeinit() function.

Like i said alternatively you could use a counter.

If you put code in for example a 10 Millisecond timer then the code will be executed every 10 Milliseconds.

This will most likely freeze your terminal because it is too fast.

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
     }
  }
//+------------------------------------------------------------------+

Note that the one minute is only triggered once, so not every minute.

The 5 minutes will trigger also only once after the first five minutes, so not at the ten and not at the 15 min mark.

If you want for example to trigger on every minute you have to add code for 60 sec for 120 sec for 180 sec and etc.

The 15 minutes mark will trigger every 15 min because it sets the counter to zero.


What mechanism do you want to use, what code do you want to trigger on the timed intervals?

What are you trying to achieve ?
 

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;
         }
  }

Good one Marco.

You could do something like this to trigger at every time interval

 

Marco vd Heijden:

What mechanism do you want to use, what code do you want to trigger on the timed intervals?

What are you trying to achieve ?
Thanks for the great comment, which one that comment explains much more clearly about 'switch' operator, and time intervals.

Once again excellent comment, big thanks man.

//---

Now, I need to give you info about my this indicator.
Because maybe I did not describe about my concern, (but your latest comment more and more helped me)...

...my indicator works which was (/ is) I wanted (/ want).

Indicator works like this:

    automatically move / shows forward 'VLINE' (which one I want)
    shows me past one week 'VLINE's               (which one I want)
    no crossover Period Lines                           (which one I want)
    continuously upgrade (with intervals) just once in a every next PERIOD_**'s (which one I want)
    and more and more...
    once again SPECIAL THANKS to Marco & whroeder1 (not just helped me and also teach me a lot)

I need to describe my concern with example:

I open EURUSD chart and attached my indicator to the chart, and works perfect which is like I want, moves / shows forward (even past) VLINE's, I can change TIMEFRAME PERIOD and automatically intervals adapted that PERIODs (which is I want).

Where is my indicator problem? // maybe it is not a problem but it takes a little a bit more 'irrelevant' times to update.

    If I choice 'EventSetMillisecondTimer( 10 );' and then I change TIMEFRAME PERIODs to any TIMEFRAME PERIODs and almost I do not see (when that) loads new VLINE's to the chart (which one I want)

        At this time if I change EURUSD to 'other symbols (like GBPUSD, and so on)' my indicator won't load full of VLINE's. That is just a problem (/ for me).

    Otherwise: If I choice 'EventSetMillisecondTimer( 1250 );' I do not see any problem about loads. It works perfectly.
        But here is a problem (/ for me) it takes a bit more 'irrelevant' times - when I change TIMEFRAME PERIODs.

    So if you understand me so clearly, please take a time to comment (and help me how can I solve this issue) or you do not understand me so clearly do not waste your time, please.

Much and much more appreciate yours comments - Marco & whroeder1


(NOTE: I do not use 'switch operator' - because your #18 comment better then everything which is I upgrade it and working on it - and it is very useful for me)

(English is not my native language) 

 

Keith Watford:

Good one Marco.

You could do something like this to trigger at every time interval

Also nice one Keith. :)

Really that help me a lot, I will use it in my next indicator.

 

All the best. 

 

I don't knpw about anyone else, but I find your mix of font, colours, bold and italic etc distracting and annoying. In fact I couldn't be bothered to read this post.

Max Enrik:
Thanks for the great comment, which one that comment explains much more clearly about 'switch' operator, and time intervals.

Once again excellent comment, big thanks man.

//---

Now, I need to give you info about my this indicator.
Because maybe I did not describe about my concern, (but your latest comment more and more helped me)...

...my indicator works which was (/ is) I wanted (/ want).

Indicator works like this:

    automatically move / shows forward 'VLINE' (which one I want)
    shows me past one week 'VLINE's               (which one I want)
    no crossover Period Lines                           (which one I want)
    continuously upgrade (with intervals) just once in a every next PERIOD_**'s (which one I want)
    and more and more...
    once again SPECIAL THANKS to Marco & whroeder1 (not just helped me and also teach me a lot)

I need to describe my concern with example:

I open EURUSD chart and attached my indicator to the chart, and works perfect which is like I want, moves / shows forward (even past) VLINE's, I can change TIMEFRAME PERIOD and automatically intervals adapted that PERIODs (which is I want).

Where is my indicator problem? // maybe it is not a problem but it takes a little a bit more 'irrelevant' times to update.

    If I choice 'EventSetMillisecondTimer( 10 );' and then I change TIMEFRAME PERIODs to any TIMEFRAME PERIODs and almost I do not see (when that) loads new VLINE's to the chart (which one I want)

        At this time if I change EURUSD to 'other symbols (like GBPUSD, and so on)' my indicator won't load full of VLINE's. That is just a problem (/ for me).

    Otherwise: If I choice 'EventSetMillisecondTimer( 1250 );' I do not see any problem about loads. It works perfectly.
        But here is a problem (/ for me) it takes a bit more 'irrelevant' times - when I change TIMEFRAME PERIODs.

    So if you understand me so clearly, please take a time to comment (and help me how can I solve this issue) or you do not understand me so clearly do not waste your time, please.

Much and much more appreciate yours comments - Marco & whroeder1


(NOTE: I do not use 'switch operator' - because your #18 comment better then everything which is I upgrade it and working on it - and it is very useful for me)

(English is not my native language) 

 

Well if it is about switching timeframes then the timer is not a good option because the timer get's destroyed upon switching frame.

You can create your lines in the OnInit() function, and update them in either the OnTick() or OnTimer() functions.

Here's an example:

//+------------------------------------------------------------------+
//| 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
  }
//+------------------------------------------------------------------+
Also note the ObjectsDeleteAll() in OnDeint() function this will make sure everything gets removed before it is created again on your new frame.
 

And additionally if you want to update the lines whenever a new candle arises you can combine the example on previous page with the last one to give you this:

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
  }
//+------------------------------------------------------------------+
If there are any more problems, please show some code.
 
Keith Watford:

I don't knpw about anyone else, but I find your mix of font, colours, bold and italic etc distracting and annoying. In fact I couldn't be bothered to read this post.

I was said do not waste your time.
 

Max Enrik:

Keith Watford:

I don't knpw about anyone else, but I find your mix of font, colours, bold and italic etc distracting and annoying. In fact I couldn't be bothered to read this post.


I was said do not waste your time.
Why have you just quoted my post without any comment?