Forex
Google
New signals service!

Go Back   Forex Trading > Programming > Metatrader Programming


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 Thread Tools Display Modes
  #761 (permalink)  
Old 03-12-2008, 08:02 AM
Junior Member
 
Join Date: Jan 2008
Posts: 9
mr_boney is on a distinguished road
How To Code!!

I Think This Ea Is Very Good...

But Only Open One Order In One Pair...why?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #762 (permalink)  
Old 03-13-2008, 11:31 AM
Member
 
Join Date: Dec 2005
Posts: 59
adria is on a distinguished road
To Big Be

I created the similar EA. You have to change TIME value according to your
chart time.
Attached Files
File Type: mq4 DAILY_11H_GBPUSD_M15.mq4 (12.4 KB, 12 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #763 (permalink)  
Old 03-14-2008, 04:59 AM
Junior Member
 
Join Date: Sep 2006
Posts: 17
hedge4x is on a distinguished road
need help with this function closealltrades

I notice broker sometimes requote the price causing the EA not to close
the order. How can I prevent the EA to continue until all of orders according
to its magic number is closed, maybe put a sleep function for 5 second and
a while loop to check and close the orders before continue. Below is the
closealltrades function. Appreciate the help and thanks in advance.


void CloseAllTrades()
{
int rc;
int cnt;

for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderMagicNumber()==GetMagicNumber())
{
rc= OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), MarketInfo(OrderSymbol(), MODE_SPREAD), Yellow);
if(!rc)
Log("Close error="+GetLastError());
}
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #764 (permalink)  
Old 03-14-2008, 07:41 AM
Senior Member
 
Join Date: Feb 2006
Posts: 513
Michel is on a distinguished road
Quote:
Originally Posted by hedge4x View Post
I notice broker sometimes requote the price causing the EA not to close
the order. How can I prevent the EA to continue until all of orders according
to its magic number is closed, maybe put a sleep function for 5 second and
a while loop to check and close the orders before continue. Below is the
closealltrades function. Appreciate the help and thanks in advance.


void CloseAllTrades()
{
int rc;
int cnt;

for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderMagicNumber()==GetMagicNumber())
{
rc= OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), MarketInfo(OrderSymbol(), MODE_SPREAD), Yellow);
if(!rc)
Log("Close error="+GetLastError());
}
}
}



PHP Code:
bool IsAllClosed ;         //Global variable

void CloseAllTrades()
{
   
int cnt;
   
IsAllClosed true;
   for(
cnt=OrdersTotal()-1;cnt>=0;cnt--)
    {
      
OrderSelect(cntSELECT_BY_POSMODE_TRADES);
      if (
OrderMagicNumber()==GetMagicNumber()) 
         
IsAllClosed IsAllClosed && OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), MarketInfo(OrderSymbol(), MODE_SPREAD), Yellow);
    }
}

void start()
{
   while(!
IsAllClosed) {CloseAllTrades(); return;}
   ... 

Last edited by Michel; 03-14-2008 at 07:44 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #765 (permalink)  
Old 03-14-2008, 11:21 AM
Junior Member
 
Join Date: Sep 2006
Posts: 17
hedge4x is on a distinguished road
thanks

thank you Michel for your help.

I will try it out.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #766 (permalink)  
Old 03-14-2008, 11:30 AM
Junior Member
 
Join Date: Sep 2006
Posts: 17
hedge4x is on a distinguished road
This line while(!IsAllClosed) {CloseAllTrades(); return;}
in the main start will close all open positions if MT goes down
and I start it back up. Is there a way to put this line
in the closealltrades function so it won't close all open positions
after MT4 restart?


thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #767 (permalink)  
Old 03-14-2008, 11:39 AM
Junior Member
 
Join Date: Sep 2006
Posts: 17
hedge4x is on a distinguished road
I got it to work now.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #768 (permalink)  
Old 03-14-2008, 04:19 PM
Senior Member
 
Join Date: Feb 2006
Posts: 513
Michel is on a distinguished road
Quote:
Originally Posted by hedge4x View Post
This line while(!IsAllClosed) {CloseAllTrades(); return;}
in the main start will close all open positions if MT goes down
and I start it back up. Is there a way to put this line
in the closealltrades function so it won't close all open positions
after MT4 restart?


thanks.
Yes, sorry you can define the bool at start time like this :
PHP Code:
bool IsAllClosed true ;         //Global variable 
Then it becomes even better to define a extern variable, so you can keep the control :
PHP Code:
extern bool CloseAll false ;         //Global variable

void CloseAllTrades() 

   
int cnt
   
CloseAll false
   for(
cnt=OrdersTotal()-1;cnt>=0;cnt--) 
    { 
      
OrderSelect(cntSELECT_BY_POSMODE_TRADES); 
      if (
OrderMagicNumber()==GetMagicNumber())  
         
CloseAll CloseAll || !OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), MarketInfo(OrderSymbol(), MODE_SPREAD), Yellow); 
    } 


void start() 

   while(
CloseAll) {CloseAllTrades(); return;} 
   ... 
The main advantage of this method is that the EA try to close each postion at each tick until all are closed.

Last edited by Michel; 03-14-2008 at 04:23 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #769 (permalink)  
Old 03-18-2008, 02:47 AM
Junior Member
 
Join Date: Apr 2007
Posts: 3
eldegwy is on a distinguished road
help needed with my semi profetable first EA

Hi All...


i made an EA by the great expert advisor bulder web site and i test it and found it profitble for the last year but i think that can be enhanced ...

so if any one can help to improve that EA ?

detaled about EA..

the EA pased on two indecators one of them is mine and the other is can found on bublic fourms " zero lag macd "

now the expert is working all the time enter buy then close and reverse to sell and so on ...

i need to make it work only in spesfic times, add a money managemint and the last thing i need to delay the excute of buy or sell with the next "1 minute" candel but the EA work on the 1H candel in fact ...

so hope to find how can help in that
Thank you All
best regards
Tamer
Attached Images
File Type: gif harv-test.gif (6.1 KB, 102 views)
Attached Files
File Type: ex4 ZeroLag MACD.ex4 (3.8 KB, 8 views)
File Type: htm harv-test.htm (113.1 KB, 9 views)
File Type: ex4 Eur_harvester.ex4 (3.6 KB, 14 views)
File Type: mq4 !@!-ATE-1.mq4 (10.5 KB, 10 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #770 (permalink)  
Old 03-19-2008, 11:42 PM
Junior Member
 
Join Date: Jan 2008
Posts: 4
star90 is on a distinguished road
how to refer to the filename I'm running?

Hi,
I want to know how can I refer to a filename that I am running.
For example if I run a script called supertrader.mq4 and I want to open a logfile called supertrader_logfile from the script supertrader.
Is there a variable that holds the name of the file I am running?
Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

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 On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code this? iscuba11 Metatrader 4 mql 4 - Development course 1 08-03-2007 04:22 PM


All times are GMT. The time now is 04:27 PM.



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