Download MetaTrader 5
To add comments, please log in or register
Publish your trading signal. Gain access to millions of traders!
Max Enrik
753
Max Enrik 2016.11.14 20:46 

Hello,

#'Period H1' - Issue Open

I has been put below code in my indicator, but I am not sure below code is good or what?

So please Pro Coders let me know about it.

int start()
{
    if ( Period() >= PERIOD_M30 ) return(0); // this code at the top
}

Thanks. 

Marco vd Heijden
Moderator
4505
Marco vd Heijden 2016.11.14 20:48  
What does it need to do ?
Max Enrik
753
Max Enrik 2016.11.14 21:15  
Marco vd Heijden:
What does it need to do ?

It needs to do when Period will be 'M30' and above indicator would be exit.

Marco vd Heijden
Moderator
4505
Marco vd Heijden 2016.11.14 21:28  
int start()
{
  if ( Period() >= PERIOD_M30 )
   {
    ChartIndicatorDelete();
   }
}
bool  ChartIndicatorDelete(
   long           chart_id,              // chart id
   int            sub_window             // number of the subwindow
   const string   indicator_shortname    // short name of the indicator
   );

Please see:

https://www.mql5.com/en/docs/chart_operations/chartindicatordelete

Documentation on MQL5: Chart Operations / ChartIndicatorDelete
Documentation on MQL5: Chart Operations / ChartIndicatorDelete
  • www.mql5.com
Chart Operations / ChartIndicatorDelete - Reference on algorithmic/automated trading language for MetaTrader 5
Max Enrik
753
Max Enrik 2016.11.14 22:47  

Wow! Much appreciate!

And thanks for the much clearly comment. 

That is which one remove indicator, indicator won't be back even I return back to 'M15'. Period. (Just I tried it.)

(I will use it in my future indicator.) 

---

So, I will use my code which one I mentioned above in my indicator for when Period will be 'M30' and above - all specified 'OBJ_VLINE' will be delete, when I will return Period under 'M30' specified 'OBJ_VLINE' will be appear in my chart. Just I want to ask is that code good for that or what?

Thanks! 

Max Enrik
753
Max Enrik 2016.11.15 01:17  

I can ignore clock '00:00' with below code.

if ( TimeHour( _timeCvrt ) > 0 && TimeHour( _timeCvrt ) <= 23 )

But I need to ignore first hour (it's possible Hour 01:00 or 02:00 and so on) of day.

Please someone help me, I am working for it (for myself).

Thanks.

Marco vd Heijden
Moderator
4505
Marco vd Heijden 2016.11.15 07:42  
int hour=TimeHour(_timeCvrt);

switch (hour)
{
  case 0:
  // do something between 0 and 1 hr
  break;

  case 1:
  // do something between 1 and 2 hr
  break;

  case 2:
  // do something between 2 and 3 hr
  break;

  case 3:
  // do something between 3 and 4 hr
  break;

  case 4:
  // do something between 4 and 5 hr
  break;

  case 5:
  // do something between 5 and 6 hr
  break;
  
// and etc. onto 23 hr
}

Can use switch operator.

Please see:

https://www.mql5.com/en/docs/basis/operators/switch

Documentation on MQL5: Language Basics / Operators / Switch Operator
Documentation on MQL5: Language Basics / Operators / Switch Operator
  • www.mql5.com
Language Basics / Operators / Switch Operator - Reference on algorithmic/automated trading language for MetaTrader 5
Max Enrik
753
Max Enrik 2016.11.15 17:33  
Marco vd Heijden:
int hour=TimeHour(_timeCvrt);

switch (hour)
{
  case 0:
  // do something between 0 and 1 hr
  break;
// and etc. onto 23 hr
}

Can use switch operator.

What a brilliant and much clearly answer, huge thanks.

It helped me a lot. (I try it...)

Max Enrik
753
Max Enrik 2016.11.15 23:08  
On my broker - EURUSD starts from 00:00 and FB 17:30,

so I try just for counts from First Bar of Currently Day and to future Period H1 (with below code)

int _mmin = ( ( Time[0] - iTime( Symbol(), PERIOD_D1, 0 ) ) / 60 ) / _Period;
int _cnt  = MathMin( Bars, _mmin );
for ( int i = 0; i < _cnt; i++ ) {}

Example: 

EURUSD have 23 Hours in a day. (Which one above code works for EURUSD)

FB have 06 Hours in a day. (Above code does not work for FB)

So, I try to get '23 for EURUSD' and '6 for FB' I hope you understand me.

And I really need good advice and comment.

All the best.

Max Enrik
753
Max Enrik 2016.11.16 12:44  
Someone, I really need your good comment, please.
Marco vd Heijden
Moderator
4505
Marco vd Heijden 2016.11.16 12:48  
I am sorry but i do not understand what you are trying to do.
/ /12
To add comments, please log in or register