Ha! I didn't even catch that at first glance :-p
Mach, this is how it should look. int start() is a method. make sure your method declaration is never within another method. like this.
int start(){
return(0);
}
bool NewBar(){
int lastbar, curbar;
static datetime lastbar = 0;
datetime curbar = Time[0];
if(lastbar!=curbar){
lastbar=curbar;
return(true);
}else{
return(false);
}
}Hello all, thanks for your wonderful replies as I slept. To wake up this morning to this amount of help is brilliant. I had to go out this morning and did not want to reply until it was fixed, but I have now got it working fine thanks. My learning is coming on well and all of you have really helped.
Dave137: Thanks for the hint about F8, I had figured out by double clicking it does a similar thing, but this helps too.
Nicholishen: Thanks for pointing this out. As a new programmer its hard to spot problems in the most simple of codes. As well as a big thanks for posting the code to use at the end. After a few little mistakes I made when typing it out, I have now got it working well.
luxinterior: Thanks for spotting this obvious, I didnt really understand about the functions but have had another look through the tutorial and am now more confident.
Also thanks for moving this thread to the correct part of the forum - sorry I did have a look around to see where to post it, but missed the programming section!
Hope to be able to learn a little more by myself now, but what you have said has been invaluable and hopefully I will be able to sort out my own problems from now - or at least post them in the correct place, in the correct style!
Howard
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- 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 been manual trading for a few years, looking to automation of a few simple systems and learning programming. I have read through CodersGuru's guide and read a number of posts but cannot work this one out. Its very simple and there is something I am missing. I am just trying to get CodersGuru's NewBar code to work and have spent hours searching around to solve the Compile debug problems.
Here is the code, I am sure it is a simple solution:
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int lastbar, curbar;
bool NewBar()
{
static datetime lastbar = 0
datetime curbar = Time[0];
if(lastbar!=curbar)
{
lastbar=curbar;
return(true);
}
else
{
return(false);
}
}
return(0);
}
//+------------------------------------------------------------------+
The code is from Alert Once Per Bar | www.metatrader.info sorry its just a copy and paste job, but at the moment I just want it to print some text when a new bar forms on the chart! How hard can it be? Very hard for a new programmer!
The compiling errors I currently get are:
'(' - function definition unexpected - which is at bool NewBar() or (43, 16)
and
'}' - unbalanced parentheses - this is the last one, cant work out where I am going wrong!
Thanks so much for any simple answers, also please say if there is a better way to post code. Sorry for being lazy and asking this, but it has been frustrating me all evening and yes, I have tried searching.
Thanks so much for any answers,
Howard
Edit: Sorry, cant remember how to post code properly!? Screenshot attached.