Download MetaTrader 5

Indicator Miscellaneous Questions - page 12

To add comments, please log in or register
honest_knave
Moderator
2403
honest_knave  

There is no reason why that print statement shouldn't generate something.

If you add the indicator to a new chart, does it print (without having to change the timeframe)?

If so, it could be an issue of already having the indicator on a chart and then recompiling expecting to see the change.

Max Enrik
945
Max Enrik  
honest_knave:

There is no reason why that print statement shouldn't generate something.

If you add the indicator to a new chart, does it print (without having to change the timeframe)?

If so, it could be an issue of already having the indicator on a chart and then recompiling expecting to see the change.


Thanks for prompt comment, appreciate that.

Yeah! It prints below message either Load Template or Add Indicator.

20...   ... EURUSD,M1: This Year1900

But as you know that code could give me " 2017 ".

//--- 2nd time edited

When I recompiling it shows correct result.

But I can't open MetaEditor that I recompiling when I try to add indicator and load template... I hope you understand what I mean.

honest_knave
Moderator
2403
honest_knave  
Max Enrik:


Thanks for prompt comment, appreciate that.

Yeah! It prints below message either Load Template or Add Indicator.

But as you know that code could give me " 2017 ".

//--- 2nd time edited

When I recompiling it shows correct result.

But I can't open MetaEditor that I recompiling when I try to add indicator and load template... I hope you understand what I mean.


Possibly the reason it is giving you the "wrong" year is OnInit() is running before you've connected to your broker.

Year() is based on server time... if there isn't a connection, it doesn't know the year.

Compare it with:

TimeYear(TimeLocal())
Max Enrik
945
Max Enrik  
honest_knave:


Possibly the reason it is giving you the "wrong" year is OnInit() is running before you've connected to your broker.

Year() is based on server time... if there isn't a connection, it doesn't know the year.

Compare it with:


I know for sure OnInit() and OnCalculate(...) needs different code style...
I will try rewrite my indicators again.
( it's possible I will give up )

Thanks for your comment.

Max Enrik
945
Max Enrik  

I think I could write a code for first delete all indicator objects then rewrite them.
I tried like below code. But I have doubt that method.

Q:  Is that method enough to delete all objects of indicator, please?

Any advice would be better thanks.

int OnInit()
 {
  ObjectsDeleteAll( 0, prefix );
  
  // then all my indicator code here...
 }
honest_knave
Moderator
2403
honest_knave  
Max Enrik:

I think I could write a code for first delete all indicator objects then rewrite them.
I tried like below code. But I have doubt that method.

Q:  Is that method enough to delete all objects of indicator, please?

Any advice would be better thanks.


That is the correct way to delete all objects from the current chart that start with 'prefix'
Max Enrik
945
Max Enrik  
honest_knave:

That is the correct way to delete all objects from the current chart that start with 'prefix'

Cool! Thanks for your reply.
Now, I just need to see how will work my indicator next day.

( p.s I do not like to test my indicator with Tester )

Max Enrik
945
Max Enrik  

( Once I told )

I use below method code for my few indicators, that indicators have not any problems, but only have a problem when I start MT4 platform which is that indicators needs to restart platform that updates just for correct values. I face with that issue ONLY once each day.

Q:  So, is below part of code can cause a problem that can't updates correct values, please?

Thanks in advance.

int OnInit()
{
    //---
    datetime a = iTime( Symbol(), 0, 0 );
    int      b = iBarShift( Symbol(), 0, a );
    datetime c = iOpen( Symbol(), 0, b );
    //---
    return(0);
}
honest_knave
Moderator
2403
honest_knave  

Code in OnInit() only runs once.

When you restart your terminal, OnInit() can finish before you have connected to your broker.

Without a connection to your broker, the time is going to be wrong.

I'd suggest moving your code out of OnInit(), or at least check IsConnected()

Max Enrik
945
Max Enrik  
honest_knave:

I'd suggest moving your code out of OnInit(), or at least check IsConnected()

Never use this IsConnected(), I will research about that.

Thanks a lot.

1...567891011121314
To add comments, please log in or register