Download MetaTrader 5

Indicator Miscellaneous Questions - page 3

To add comments, please log in or register
Max Enrik
988
Max Enrik  
whroeder1:

Pre-build 600 (February 3, 2014) there was only start(). Now there is OnTick (EAs,) OnCalculate (indicators,) and OnStart (scripts.) I forgot you were talking about an indicator.

Start using the new Event Handling Functions - Functions - Language Basics - MQL4 Reference. See How to do your lookbacks correctly.

Yeah! Right now I understand you much clearly, and thanks so much more.

And your #20 comment gave me another idea. (once you shared that with me and now I keep it in my mind)

Also I try to write better code for my indicator, and now I try to learning comment #18 - @Marco vd Heijden

Then I will widely research your comment.

Thanks once again!

Max Enrik
988
Max Enrik  
Marco vd Heijden:

Please put it in an expert in stead of indicator this allows easier use in the future when you want to add your trading strategy.

For the bars issue, store the bar opening time in a datetime variable and simply compare the recorded time with the real time then whenever a new bar arises it will trigger.

Here is an example:

datetime M1,M5,M15,M30,H1,H4,D1,W1,MN1;

First of all huge thanks for your much clearly comment.

I still stay on Indicator. I tried something, and it works good for me, but I faced one issue, I can't test it on 'Strategy Tester' - it gives me fatal error: MT4 'Not Responding'.

#1 - Marco can you let me know where it comes from, please?

#2 - Is below code right?

Below code which one I tried.

string _prefix = "_Preriod_M5 - " ;
string _vlineName_M5 ;
int _prd = PERIOD_M5 ;

int _prd_add = PeriodSeconds( _prd ) ;
datetime _dt_Prd_M5 ;

int _time_M5 ;
datetime _prdCvrt_M5 ;
datetime _timeCvrt_M5 ;

//---init
EventSetMillisecondTimer( 10 );
_CreateLines();

//---timer
if ( _dt_Prd_M5 != iTime( Symbol(), _prd, 0 ) )
{
    _dt_Prd_M5 = iTime( Symbol(), _prd, 0 );
    _CreateLines();
}

//---_CreateLines()
    //---
    int _dayCnt_M5 = 0;
    int _cnt_M5 = iBarShift( Symbol(), 0, iTime( Symbol(), PERIOD_M15, _dayCnt_M5 ) );
    for ( int i = 0; i < _cnt_M5; i++ )
    {
        //---time convert
        _time_M5     = Time[i];
        _prdCvrt_M5  = PeriodSeconds( _prd );
        _timeCvrt_M5 = _time_M5 - ( _time_M5 % _prdCvrt_M5 ) + _prdCvrt_M5;

        //---name
        _vlineName_M5 = _prefix + "PERIOD_M5 - " + TimeToStr( _timeCvrt_M5, TIME_DATE|TIME_MINUTES );

        //---
        if ( _Period < PERIOD_M30 )
        {
            {
                ObjectCreate( _vlineName_M5, OBJ_VLINE, 0, _timeCvrt_M5, 0 );
            }
        }
    }
    ObjectMove ( 0, _vlineName_M5, 0, _dt_Prd_M5, 0 );

 

I stopped working on it, I will continue after your comment. (Actually I worry about above code will crush my other indicators while I use it together.)

Big thanks.

Marco vd Heijden
Moderator
6139
Marco vd Heijden  
The timer function does not work in MT4 strategy tester so you have to put it in the tick function.
whroeder1
17125
whroeder1  
Marco vd Heijden: The timer function does not work in MT4 strategy tester so you have to put it in the tick function.
In backtest OnTimer() not performs (M. Ali) - MQL4 forum
Chart Event For MT4 Backtester (Migel) - MQL4 forum
Max Enrik
988
Max Enrik  
Marco vd Heijden:
The timer function does not work in MT4 strategy tester so you have to put it in the tick function.

Big thanks!

I know for sure, that problem does not comes from code. 

Marco vd Heijden
Moderator
6139
Marco vd Heijden  
How do you know?
Max Enrik
988
Max Enrik  

Marco vd Heijden:

Here is an example:

datetime M5;

//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetMillisecondTimer(250);

//--- create some things

   CreateLines(); // Function that creates time lines

//--- load open times
   M5=iTime(Symbol(),PERIOD_M5,0);

//--- set timelines

   ObjectMove(0,"Time-M5",0,M5,0);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   if(M5!=iTime(Symbol(),PERIOD_M5,0))
     {
      M5=iTime(Symbol(),PERIOD_M5,0);  // overwrite old value with new value  
      //Alert("New Bar on M5! ",TimeToString(M5,TIME_SECONDS));
      // do something...
      //ObjectMove(0,"Time-M5",0,M5,0);
     }
  }
//+------------------------------------------------------------------+

Thank you so much.

This comment teach me a lot things.

 

Looks like that code works good for me which one I posted it my previous comment.

But I need that code (which one it is working for Period_M5) won't work at the Clock 12:00 (it's maybe 13:00, 14:00...) and below code ignoring 'OBJ_VLINE's past times (that is good for me) but while currently Clock 12:00 below code shows me additionally current time VLINE but I do not want it.

if ( TimeHour( _timeCvrt_M5 ) != 12 )
{
    ObjectCreate( _vlineName_M5, OBJ_VLINE, 0, _timeCvrt_M5, 0 );
}   //---if Close

I tried something that solve my issue, but it did not work correctly.

Also I added screenshot.


Please, help me I really need to solve that issue.

Huge thanks in advance. 

Files:
Max Enrik
988
Max Enrik  
Marco vd Heijden:
How do you know?

Because connection lost and I tried to use 'Strategy Tester' while disconnection time and it works perfectly for me.

After I read your and Mr. William comments, and then I know for sure about it.

Is that not enough, sorry? 

Marco vd Heijden
Moderator
6139
Marco vd Heijden  
if ( TimeHour( _timeCvrt_M5 ) != 12 )
{
    ObjectCreate( _vlineName_M5, OBJ_VLINE, 0, _timeCvrt_M5, 0 );
}   //---if Close

In this example you get a line at every hour BUT 12:00 because you exclude with != differ then 12 statement so when it is == equal to 12 no line.

Max Enrik
988
Max Enrik  
Marco vd Heijden:

In this example you get a line at every hour BUT 12:00 because you exclude with != differ then 12 statement so when it is == equal to 12 no line.

Brilliant man, thanks :))

That is simple but I do not mind it. Just simple and just wow.

(Actually I use '==' in my this indicator but I really focused 'OnTimer')

//--- second times edited...

This works good for me, but when time will be 00:00 - additional current time VLINE shows again.

if (
     TimeHour( _timeCvrt_M5 ) == 1  ||
     TimeHour( _timeCvrt_M5 ) == 2  ||
     TimeHour( _timeCvrt_M5 ) == 3  ||

     TimeHour( _timeCvrt_M5 ) == 5  ||
     TimeHour( _timeCvrt_M5 ) == 6  ||
     TimeHour( _timeCvrt_M5 ) == 7  ||

     TimeHour( _timeCvrt_M5 ) == 9  ||
     TimeHour( _timeCvrt_M5 ) == 10 ||
     TimeHour( _timeCvrt_M5 ) == 11 ||

     TimeHour( _timeCvrt_M5 ) == 13 ||
     TimeHour( _timeCvrt_M5 ) == 14 ||
     TimeHour( _timeCvrt_M5 ) == 15 ||

     TimeHour( _timeCvrt_M5 ) == 17 ||
     TimeHour( _timeCvrt_M5 ) == 18 ||
     TimeHour( _timeCvrt_M5 ) == 19 ||

     TimeHour( _timeCvrt_M5 ) == 21 ||
     TimeHour( _timeCvrt_M5 ) == 22 ||
     TimeHour( _timeCvrt_M5 ) == 23
)

(I few times updated this comment because I was researched) 

Please help me.

To add comments, please log in or register