Indicator Miscellaneous Questions - page 4

 

You can use the switch operator.

      switch(TimeHour())
        {
         case 0:
          // Do Something...
            break;

         case 1:
          // Do Something...  
            break;

         case 2:

            break;

         case 3:

            break;

         case 4:

            break;

         case 5:

            break;

         case 6:

            break;
         // etc...
        }

Or use simple double if statement:

if(TimeHour()>0 && TimeHour()< 22)
{
  // Do Something...
}

If time hour is above > 0 but also && below < 22 etc.

Or you can use:

if(TimeHour()>=0 && TimeHour()<= 22)
{
  // Do Something...
}

If time hour is above > or == equal to 0 but also && below < or  == equal to 22 etc.

Its slightly different because it includes the hour when its equal, where previous example >0 excludes 0 itself because it is equal so not above.

 

#Month Lines - Closed for me. 

I tested with 'Strategy Tester' & real time so far works perfect.

I learned a lot of things from your comments, and I made my this indicator so good, big thanks @Marco vd Heijden

Special thanks to Mr. Marco & Mr. William.

 

Below code works good for me, but sometimes irrelevant it takes a long time (1250).

EventSetMillisecondTimer( 1250 );

// which is good?

EventSetTimer( 1 );

Additionally, can I use 'Switch' function for that?

//--- 2nd times edited

I do not want to use start() function. Actually I need to set like below.

EventSetMillisecondTimer( 10   ); // 1st will read in 10
EventSetMillisecondTimer( 250  ); // 2nd will read in 250
EventSetMillisecondTimer( 1250 ); // 3rd will read in 1250

But I need help, please.

//--- 3rd times edited

switch ( EventSetMillisecondTimer( 10 ) )
{
    case    1   :   EventSetMillisecondTimer( 100  );
    case    2   :   EventSetMillisecondTimer( 250  );
    case    3   :   EventSetMillisecondTimer( 1250 );
    default     :   EventSetMillisecondTimer( 10   ); break;
}   //---switch Close

It does not work, like I want.

If someone understand my concern, please give me advice or help.

Thanks in advance.

 
Max Enrik: I do not want to use start() function.
  1. Why not? Until you get a new tick, nothing (in the market) has changed. Timer has limited use.
  2. Start using the new Event Handling Functions - Functions - Language Basics - MQL4 Reference. start as been depreciated Since February 3, 2014 (Build 600)
 
Max Enrik:

I do not want to use start() function. Actually I need to set like below.

EventSetMillisecondTimer( 10   ); // 1st will read in 10
EventSetMillisecondTimer( 250  ); // 2nd will read in 250
EventSetMillisecondTimer( 1250 ); // 3rd will read in 1250

But I need help, please.

It does not work, like I want.

If someone understand my concern, please give me advice or help.

Thanks in advance.


no it does not work like that you use one timer and one timer only.

but you can split or splice the time interval by using a simple counter.

int clock;
OnTimer()
{
  clock++;
  
  switch(clock)
   {
    case 500:
    //Do something...
    break;

    case 1000:
    //Do something...
    clock=0; // reset counter if need be.
    break;

    // Etc...
   }
}
 
whroeder1:
  1. Why not? Until you get a new tick, nothing (in the market) has changed. Timer has limited use.
  2. Start using the new Event Handling Functions - Functions - Language Basics - MQL4 Reference. start as been depreciated Since February 3, 2014 (Build 600)
Thanks for your comment.

You mentioned twice 'Event Handling Functions', and I read few times (maybe I did not clearly understanding all of that page - also I use 'OnTimer' function) but I worry about that page, that will pull me another way - but my this indicator almost finished.

But I see just 'EventSetMillisecondTimer( 1250 );' sometimes takes 'irrelevant' long time.


Best.
 
Marco vd Heijden:

but you can split or splice the time interval by using a simple counter.

I tried like below code.

Is that code right?

void OnTimer()
{
    //---
    _clock++;
    //---
    switch ( _clock )
    {
        case    500 :
            if ( // will be same thing in here? ) )
            {
                ...
                _CreateLines_M5();
            }   //---if Close
        break;
        
        case    1000:
            if ( // will be same thing in here? ) )
            {
                ...
                _CreateLines_M5();
            }   //---if Close

        _clock = 0;
        break;
    }   //---switch Close
}

But it does not work for me. 

Thanks.

 
Max Enrik: I tried like below code.
void OnTimer()
{
    //---
    _clock++;
    //---
    switch ( _clock )
    {
        case    500 :
            if ( // will be same thing in here? ) )
            {
                ...
                _CreateLines_M5();
            }   //---if Close
        break;
        
        case    1000:
            if ( // will be same thing in here? ) )
            {
                ...
                _CreateLines_M5();
            }   //---if Close

        _clock = 0;
        break;
    }   //---switch Close
}

But it does not work for me.

  1. You're not trying it in the tester are you? In backtest OnTimer() not performs (M. Ali) - MQL4 forum Chart Event For MT4 Backtester (Migel) - MQL4 forum
  2. Your code simplified
    void OnTimer()
    {
        if(++_clock % 500 == 0)_CreateLines_M5();
    }

 
whroeder1:
  1. Your code simplified
    void OnTimer()
    {
        if(++_clock % 500 == 0)_CreateLines_M5();
    }

Big thanks!

I tried it, it continuously refreshing while in a minute even I choice PERIOD_M5.

Also I would like to know if I need to use PERIOD_M1 & PERIOD_M5 can I use like below?

if(++_clock % 500 == 0)_CreateLines_M1();
if(++_clock % 500 == 0)_CreateLines_M5();

also, Is below method right, please?

if ( ++_clock % 500 == 0 || _dt_Prd_M5 != iTime( Symbol(), _prd_M5, 0 ) )
{
    _dt_Prd_M5 = iTime( Symbol(), _prd_M5, 0 );
    _CreateLines_M5();
}

All the best. 

 
Max Enrik:

Big thanks!

I tried it, it continuously refreshing while in a minute even I choice PERIOD_M5.

Also I would like to know if I need to use PERIOD_M1 & PERIOD_M5 can I use like below?

if(++_clock % 500 == 0)_CreateLines_M1();
if(++_clock % 500 == 0)_CreateLines_M5();

also, Is below method right, please?

if ( ++_clock % 500 == 0 || _dt_Prd_M5 != iTime( Symbol(), _prd_M5, 0 ) )
{
    _dt_Prd_M5 = iTime( Symbol(), _prd_M5, 0 );
    _CreateLines_M5();
}

All the best. 

Please describe what you are trying to do.
Reason: