Forex



Go Back   Forex Trading > Downloads > Expert Advisors - Metatrader 4
Forex Forum Register More recent Calendar Advertising Others Help






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.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 04-09-2006, 02:00 AM
BC Brett's Avatar
Member
 
Join Date: Mar 2006
Location: Vancouver, British Columbia
Posts: 33
BC Brett is on a distinguished road
EA Program Execution

I have been working on my first EA for a few weeks now, and from the start I wanted the EA to execute some code immediately after starting the MT4 program, before entering the start() function.
I thought that if I put the code in the init() function, that would work.
What I found was that, although the code would execute, calls to funtions for retrieving account information, like OrdersTotal(), returned values of 0 when this was not true. If I recompiled the EA, the same function calls would then return the correct values.
I'm not sure what to conclude from this but it looks like the init() function needs to complete once before account information functons will return the correct values.
So anyway, my question is, can any code somehow be executed after the init() function and before the start() function?

Last edited by BC Brett; 04-09-2006 at 02:28 AM.
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!
Reply With Quote
  #2 (permalink)  
Old 04-09-2006, 02:30 AM
BC Brett's Avatar
Member
 
Join Date: Mar 2006
Location: Vancouver, British Columbia
Posts: 33
BC Brett is on a distinguished road
Wrong Conclusion

Quote:
Originally Posted by BC Brett
I'm not sure what to conclude from this but it looks like the init() function needs to complete once before account information functons will return the correct values.
OK, I just ran another test to see if init() really did need to complete before the account functions would work or if it was just MT4 needed more time to finish its startup launch.
I added the statement sleep(1000) as the first line in the init() function, recompiled, shutdown MT4, and then restarted it. Now the account function calls in the init() funtion are returning the correct values.
Conclusion: MT4 starts running the EA before it finishes retrieving account information on startup. The sleep(1000) function gives it more time to complete downloading account information. But if anyone can answer my original question ...
Quote:
Originally Posted by BC Brett
can any code somehow be executed after the init() function and before the start() function?

Last edited by BC Brett; 04-09-2006 at 05:21 PM.
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!
Reply With Quote
  #3 (permalink)  
Old 04-09-2006, 08:13 AM
elihayun's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 397
elihayun is on a distinguished road
whay not add this

int start()
{
static bool bFirstTime = true;

if (bFirstTime)
{
...... execute 1st time commands
bFirstTime = false;
}
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!
Reply With Quote
  #4 (permalink)  
Old 04-09-2006, 08:38 AM
Nicholishen's Avatar
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
metatraders trade pool functions have proven to be problematic for me as well. i notice there are problems after compiling...especially when using many functions in your code. that is my major complaint with mt!
__________________
"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!
Reply With Quote
  #5 (permalink)  
Old 04-09-2006, 05:39 PM
BC Brett's Avatar
Member
 
Join Date: Mar 2006
Location: Vancouver, British Columbia
Posts: 33
BC Brett is on a distinguished road
How about IndicatorCounted() == 0?

Quote:
Originally Posted by elihayun
int start()
{
static bool bFirstTime = true;

if (bFirstTime)
{
...... execute 1st time commands
bFirstTime = false;
}
Very clever elihayun! I think this works also:

int start()
{
if (IndicatorCounted() == 0)
{
...... execute 1st time commands
}

The first time through start(), IndicatorCounted() == 0.
After the first time through, IndicatorCounted() == Bars-1.
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!
Reply With Quote
  #6 (permalink)  
Old 04-10-2006, 03:50 PM
elihayun's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 397
elihayun is on a distinguished road
Quote:
Originally Posted by BC Brett
Very clever elihayun! I think this works also:

int start()
{
if (IndicatorCounted() == 0)
{
...... execute 1st time commands
}

The first time through start(), IndicatorCounted() == 0.
After the first time through, IndicatorCounted() == Bars-1.
It will work but you count on something the if your computer will be very very fast maybe it wont work. My solution is not relies on any assumptions
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!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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
Can someone program this EA please symtec23 Expert Advisors - Metatrader 4 12 04-23-2008 10:25 PM
EA trade execution question iboersma Metatrader 4 7 04-07-2008 02:46 PM
Will pay if you program me a DLL for MT4 SirKhan Metatrader 4 3 05-16-2007 09:56 PM
Order Execution Problems with my EA mrebersv Metatrader 4 6 04-01-2007 10:08 AM


All times are GMT. The time now is 11:39 PM.



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