Forex
Google

Go Back   Forex Trading > Programming > Metatrader Programming
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack (2) Thread Tools Display Modes
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 02-25-2008, 10:33 PM
mach_one_man mach_one_man is offline
Junior Member
 
Join Date: May 2006
Posts: 9
mach_one_man is on a distinguished road
NewBar() problems for NewProgrammer!

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.
Attached Images
File Type: jpg code.jpg (22.9 KB, 81 views)

Last edited by mach_one_man : 02-25-2008 at 10:36 PM. Reason: Code not showing properly
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-25-2008, 10:43 PM
Dave137 Dave137 is offline
Senior Member
 
Join Date: Oct 2007
Posts: 154
Dave137 is on a distinguished road
Smile

Hit F8 function Key and it will zero into the possible error.

Dave
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-25-2008, 10:56 PM
Nicholishen's Avatar
Nicholishen Nicholishen is offline
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
youre missing a ";" after lastbar = 0

But here is a better function for checking only once per bar. When youre posting code wrap it with the php tags by hitting the little php button in the editor. cheers.
__________________
"Anyone who has never made a mistake has never tried anything new." -Albert Einstein
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-25-2008, 11:27 PM
luxinterior luxinterior is offline
Senior Member
 
Join Date: Nov 2006
Posts: 125
luxinterior is on a distinguished road
You've got the function definition inside a function.

Take the whole Newbar() definiton out and paste it below the start function. If that doesn't make any sense to you you may need to go back and re-read CodeGuru's tutorial and look at some EA code.

Good luck

Lux
__________________
Build An Expert Advisor. FREE E-course As Seen On TV
ForexArea.com
Users of Gap Trader from 'Forex-Assistant' MUST Read This
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-26-2008, 02:36 AM
Nicholishen's Avatar
Nicholishen Nicholishen is offline
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
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.

PHP Code:
int start(){
 
   return(
0);
}

bool NewBar(){
   
int lastbarcurbar;
   static 
datetime lastbar 0;
   
datetime curbar Time[0];
   if(
lastbar!=curbar){
      
lastbar=curbar;
      return(
true);
   }else{
      return(
false);
   }

__________________
"Anyone who has never made a mistake has never tried anything new." -Albert Einstein
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-26-2008, 11:41 AM
mach_one_man mach_one_man is offline
Junior Member
 
Join Date: May 2006
Posts: 9
mach_one_man is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/12558-newbar-problems-newprogrammer.html
Posted By For Type Date
» NewBar() problems for NewProgrammer! This thread Pingback 02-26-2008 05:18 PM
NewBar() problems for NewProgrammer! This thread Pingback 02-26-2008 02:23 PM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with EA's. rodrigojmz General Discussion 3 02-22-2007 01:15 AM
Problems logging in.. Gramski General Discussion 1 01-11-2007 07:08 AM
Help, anyone having problems with MT4? increase General Discussion 10 12-08-2006 01:06 PM
ea problems Eaglehawk Metatrader 4 3 06-13-2006 05:32 PM
Tech Problems nina Metatrader 4 2 12-08-2005 07:14 AM


All times are GMT. The time now is 02:41 PM.