Download MetaTrader 5

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

To add comments, please log in or register
How to test a program before buying?
Fa Cao
1141
Fa Cao 2013.11.13 08:51 

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?

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.11.13 09:01  
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 ?
Fa Cao
1141
Fa Cao 2013.11.13 09:33  
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?
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.11.13 09:47  
vx0532:

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

the code is as below:


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

Fa Cao
1141
Fa Cao 2013.11.13 10:26  


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();
    }
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.11.13 10:33  
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
Alain Verleyen
Moderator
30752
Alain Verleyen 2013.11.13 10:37  
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.
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.11.13 10:43  
angevoyageur:
You inverted A and B.
Yep, fixed . . .
whroeder1
14530
whroeder1 2013.11.13 13:12  
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.

Fa Cao
1141
Fa Cao 2013.11.14 01:13  
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.

whroeder1
14530
whroeder1 2013.11.14 01:52  
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.
123
To add comments, please log in or register