Forex



Go Back   Forex Trading > Programming > Metatrader Programming






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

 
 
Thread Tools
 
Old 02-25-2008, 11:33 PM
Junior Member
 
Join Date: May 2006
Posts: 13
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, 135 views)

Last edited by mach_one_man; 02-25-2008 at 11:36 PM. Reason: Code not showing properly
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 02-25-2008, 11:43 PM
Senior Member
 
Join Date: Oct 2007
Posts: 230
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 02-25-2008, 11:56 PM
Nicholishen's Avatar
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 02-26-2008, 12:27 AM
Senior Member
 
Join Date: Nov 2006
Posts: 307
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 02-26-2008, 03:36 AM
Nicholishen's Avatar
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 02-26-2008, 12:41 PM
Junior Member
 
Join Date: May 2006
Posts: 13
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 

Bookmarks

Tags
function definition unexpected, '(' - function definition unexpected
Thread Tools

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

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

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


All times are GMT. The time now is 09:22 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.