The chart will only show the last thing you show with Comment.
So it sounds like the Time comment is the last thing your showing. so, if you had:
Comment("first thing "+ var);
Comment("second thing "+ var2 );
Comment("third thing");
Comment("Time: "+TimeCurrent());
You will only see the Time
What you need to do instead is place everything in one Comment. You can even show them on thier own line using "\n" like this:
Comment("first thing" + var1 + "\nsecond thing" + var2 + "\nthird thing\nTime: " + TimeCurrent());
Then you should get the results you're probably looking for.
Code:
//+------------------------------------------------------------------+
//| NewEA.mq4 |
//| Copyright © 2009, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
string mBuffer="Time: "+TimeCurrent();
// Comment(mBuffer);
Print("Staring....");
Print("Time: "+Time[0]);
Print("Running....");
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
string mBuffer="Time: "+TimeCurrent();
Comment(mBuffer);
Comment("Bid x Ask: "+Bid+"x"+Ask);
Print("Time: "+Time[0]);
Print("Bid x Ask: "+Bid+"x"+Ask);
//----
return(0);
}
//+------------------------------------------------------------------+
Only thing printed is the Print statements from Init() in the Experts window at the bottom. None of the Comment/Print statements from start() execute.
I did read your reply and it helps. But _nothing_ is printed either in the Experts window or on the chart. not even the last one. I have removed all comments and prints lines leaving just one Comment() call, it still prints nothing.
Interestingly enough, using metatrader from another brokers' demo, the code works. So something is wrong with the first MT.
Now, since you say the code works, this is no longer a code issue. It's now a matter of, why one instance of metatrader doesn't work properly.
Something like that did happen to me. It happened when I first used metatrader on Vista. I learned that I should open metatrader as Admin.
I don't know what other advice to give. maybe restart the instance of MT that doesnt work or the whole PC. But definitely take my advice on Vista.
Thanks guys. They're both working now. The first instance had the EA disabled on the toolbar. Once enabled, they worked fine too. circlesquare, thankfully this is not vista. :)
The following code is a print function with autoscroll, using the comment field for outputting its text. Include this code and then call print() instead of Print() (lower case p).
/**
* use the Comments() display to simulate the behaviour of
* the good old print command, useful for debugging.
* text will be appended as a new line on every call
* and if it has reached 20 lines it will start to scroll.
* if clear is set to True the buffer will be cleared.
*/
void print(string text, bool clear=False){ static string print_lines[20]; static int print_line_position = 0; if (IsOptimization()){ return(0); } string output="\n"; string space = " "; int max_lines = 20; int i; if (clear){ for (i=0; i<max_lines; i++){ print_lines[i] = ""; print_line_position = 0; } } if (print_line_position == max_lines){ for (i=0; i<max_lines; i++){ print_lines[i] = print_lines[i+1]; } print_line_position--; } print_lines[print_line_position] = text; print_line_position++; for(i=0; i<print_line_position; i++){ output = output + print_lines[i] + "\n"; } output = stringReplace(output, "\n", "\n" + space); Comment(output); } /** * search for the string needle in the string haystack and replace all * occurrecnes with replace. */ string stringReplace(string haystack, string needle, string replace=""){ string left, right; int start=0; int rlen = StringLen(replace); int nlen = StringLen(needle); while (start > -1){ start = StringFind(haystack, needle, start); if (start > -1){ if(start > 0){ left = StringSubstr(haystack, 0, start); }else{ left=""; } right = StringSubstr(haystack, start + nlen); haystack = left + replace + right; start = start + rlen; } } return (haystack); }
The following code is a print function with autoscroll, using the comment field for outputting its text. Include this code and then call print() instead of Print() (lower case p).
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello all, I have a a blank EA created in MetaTrader 4. In Start() function I put:
Comment("Time: "+TimeCurrent());
If I attach it to a chart and leave it running at some later point I see if prints some time on the chart. But from description of the start function, it should be doing that on every quote. Is a new tick not a new quote?
I modify the EA to adding more comments and compile and re-attach to the chart and only the time keeps showing. The new information doesn't show. I am curious as to whether something is wrong or if my understanding of start() is incorrect.