some questions about adding text by "A" on K line chart and time counting.

 

1. a question about adding text on "K" line chart by text tool--"A" on MT4

when I add the text--"Words on Test" on "M15" line chart as below:

then I change to "H1" line chart, and I get the below image:

in the fact, I add "Word on Test" on "M15" line chart and just want these words showed on "M15" line chart rather than any other line chart.

My question is : how shall I do for this?

2. a question about time counting

for example, I want to send an order after 10 minutes by an EA which I have set it well for this.

Now I am reviewing "M15" line chart and execute above EA, then 10 minutes later, the order can be sent; that is ok.

But if 5 minutes later, I go to "H1" line chart, then the time is counted from 0 rather than 5, so the order should be sent after 15 minutes from the very beginning rather than 10 minutes, even if I set the variable of counting time as " extern" variable outside of function--start().I want to the order should be sent after 10 minutes, whatever I go to any line chart within the 10 minutes.

My question is : how shall I do for this?

 
vx0532:

1. a question about adding text on "K" line chart by text tool--"A" on MT4

when I add the text--"Words on Test" on "M15" line chart as below:

then I change to "H1" line chart, and I get the below image:

in the fact, I add "Word on Test" on "M15" line chart and just want these words showed on "M15" line chart rather than any other line chart.

My question is : how shall I do for this?

You can set the TimeFrames that the Object is shown on, ObjectSet() with OBJPROP_TIMEFRAMES

2. a question about time counting

for example, I want to send an order after 10 minutes by an EA which I have set it well for this.

Now I am reviewing "M15" line chart and execute above EA, then 10 minutes later, the order can be sent; that is ok.

But if 5 minutes later, I go to "H1" line chart, then the time is counted from 0 rather than 5, so the order should be sent after 15 minutes from the very beginning rather than 10 minutes, even if I set the variable of counting time as " extern" variable outside of function--start().I want to the order should be sent after 10 minutes, whatever I go to any line chart within the 10 minutes.

My question is : how shall I do for this?

When you change timeframe the EA will reinitialise and your start time variable gets reset so an order is not placed for a additional 10 minutes . . . the simple solution is to not change timeframes. If you need to review a H1 chart open a new H1 chart . . . if this is not to your liking then you need to explain what triggers the start time ? is it from the time the EA is attached or some other event ?
 
RaptorUK:


When you change timeframe the EA will reinitialise and your start time variable gets reset so an order is not placed for a additional 10 minutes . . . the simple solution is to not change timeframes. If you need to review a H1 chart open a new H1 chart . . . if this is not to your liking then you need to explain what triggers the start time ? is it from the time the EA is attached or some other event ?

yes, it is from the time the EA is attached.

the code is as below:

#include <WinUser32.mqh>
#property show_inputs
//--- input parameters
extern int       time_count=1;
extern datetime  time_current;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
if (time_count==1)
{
  time_current=TimeCurrent();
  time_count--;
}
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  Print("time_passed(Minutes) is:",(TimeCurrent()-time_current)/60);
....
...
}
I think the variable will never be initialized again for above code, but it is. how shall i do?
 
vx0532:

yes, it is from the time the EA is attached.

the code is as below:


https://www.mql5.com/en/forum/143987

 


thank you,these problems have been resolved.

I have another question:

what is the difference between "A" and "B" as below?

A:

bool isFirst = true;
datetime  time_current;
int init(){
   if(isFirst) 
   { isFirst = false; 
    time_current=TimeCurrent();
    }

B:

extern bool isFirst = true;
extern datetime  time_current;
int init(){
   if(isFirst) 
   { isFirst = false; 
    time_current=TimeCurrent();
    }
 
vx0532:


thank you,these problems have been resolved.

I have another question:

what is the difference between "A" and "B" as below?

In B: the parameters/inputs isFirst and time_current can be set by the user in the Inputs tab of the EA/Indicator/Script in the case of A: the values can not be set by the user.


extern
 
RaptorUK:
In A: the parameters/inputs isFirst and time_current can be set by the user in the Inputs tab of the EA/Indicator/Script in the case of B: the values can not be set by the user.


extern
You inverted A and B.
 
angevoyageur:
You inverted A and B.
Yep, fixed . . .
 
extern bool isFirst = true;
extern datetime  time_current;
int init(){
   if(isFirst) 
   { isFirst = false; 
    time_current=TimeCurrent();
    }

Remember, that static and common (globally declared) variables are only reset on EA recompile (or you reseting the extern or you removing and re-adding the EA.)

When you change pairs or time frames the EA will go through a deinit() / init() cycle but the variables will not be reset.

Your isFirst only indicates if this is the first time init() has been called or not.

 
RaptorUK:
In B: the parameters/inputs isFirst and time_current can be set by the user in the Inputs tab of the EA/Indicator/Script in the case of A: the values can not be set by the user.


extern


Just now I have test the difference between A and B according to your points.

What you said is correct but not all, because I find that as below:

1. A has match my purpose very well, but B can't. when B has been attached to chart(suppose: extern datetime time_current=2013.11.14 0:00 in B), if I go to other pair or other time frame chart, "time_current" will be 2013.11.14 0:00 again. so i think there must be other difference between A and B.

2. So I think "extern" has only one effect which can allow us assign its variables before EA's attached.

 
vx0532: (suppose: extern datetime time_current=2013.11.14 0:00 in B), if I go to other pair or other time frame chart, "time_current" will be 2013.11.14 0:00 again.
No it will not. Test it.
Reason: