Forex
Google

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions
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
  #1061 (permalink)  
Old 04-27-2008, 09:20 AM
Michel Michel is offline
Senior Member
 
Join Date: Feb 2006
Posts: 509
Michel is on a distinguished road
Quote:
Originally Posted by bearfoot090 View Post
hi there!

can some here help me add this function. Make it to close trade when the bar is completed or in another word to make it close the trade when the next bar appear.( doesnt matter the trade is profit or loss )
To detect a new bar there are several solutions:

1)
PHP Code:
if(Volume[0] == 1CloseOrders(); 
Not very reliable, for example if the terminal has to be restarted you may loose the first tick of the bar.

2)
PHP Code:
if(BarsCnt Bars) {BarsCnt BarsCloseOrders();} 
Not very reliable, for example if new bars are added to the left of the chart.

3)
PHP Code:
if(Time1 Time[0]) {Time1 Time[0]; CloseOrders();} 
Better, but again, restarting the terminal may produce wrong behaviors.

So my opinion is that the best is to write the lifetime max of each order into the order itself, using the "Comment" field :
PHP Code:
OrderSend(..., ""+(Time[0] + Period()*60), ..); 
Then you can scan the orders and check :
PHP Code:
if(TimeCurrent() > OrderComment()) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0CLR_NONE); 
. This is a good solution because if you have several orders to close, you have all the time needed to do it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1062 (permalink)  
Old 04-27-2008, 01:05 PM
bearfoot090 bearfoot090 is offline
Junior Member
 
Join Date: Dec 2007
Posts: 5
bearfoot090 is on a distinguished road
thanks michel for the reply.

I`ll try. but what should i put in the comment?anything i like?

Last edited by bearfoot090 : 04-27-2008 at 01:21 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1063 (permalink)  
Old 04-27-2008, 03:04 PM
Michel Michel is offline
Senior Member
 
Join Date: Feb 2006
Posts: 509
Michel is on a distinguished road
Quote:
Originally Posted by bearfoot090 View Post
thanks michel for the reply.

I`ll try. but what should i put in the comment?anything i like?
Put the time you want to close the order. The Comment field must be a string, that's why there is ""+ in front of the value. for example:
PHP Code:
""+(Time[0] + Period()*60)   // begin of the next bar on the current timeframe

""+(TimeCurrent() + 2*360 30*60)   // 2 hours 30 minutes after the openning

""+(iTime(NULL,PERIOD_D1,0) + 23*360 45*60// today at 23:45 (server time)

""+(iTime(NULL,PERIOD_W1,0) + (PERIOD_W1 10)*60// next friday at 23:50 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1064 (permalink)  
Old 04-28-2008, 12:39 AM
yyc196's Avatar
yyc196 yyc196 is offline
Senior Member
 
Join Date: Dec 2006
Location: Earth
Posts: 198
yyc196 is on a distinguished road
Thanks

Quote:
Originally Posted by Michel View Post
If needed, check first that you are later than 8 am:
PHP Code:
if(Hour() < 8) return; 
Then, find the max and min of the current day. (if its ok for you, its easier than from 8 am):
PHP Code:
double Max iHigh(Symbol(), PERIOD_D10);
double Min iLow(Symbol(), PERIOD_D10);
int Range = (Max Min) / Point;
if(
Range 90) return;
... 
Hi,

Apology to take such a ling time to say "thank you".

I appreciate your help.

Thanks again.

Shek
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1065 (permalink)  
Old 04-28-2008, 12:56 PM
bearfoot090 bearfoot090 is offline
Junior Member
 
Join Date: Dec 2007
Posts: 5
bearfoot090 is on a distinguished road
Quote:
Originally Posted by Michel View Post
To detect a new bar there are several solutions:

1)
PHP Code:
if(Volume[0] == 1CloseOrders(); 
Not very reliable, for example if the terminal has to be restarted you may loose the first tick of the bar.

2)
PHP Code:
if(BarsCnt Bars) {BarsCnt BarsCloseOrders();} 
Not very reliable, for example if new bars are added to the left of the chart.

3)
PHP Code:
if(Time1 Time[0]) {Time1 Time[0]; CloseOrders();} 
Better, but again, restarting the terminal may produce wrong behaviors.

So my opinion is that the best is to write the lifetime max of each order into the order itself, using the "Comment" field :
PHP Code:
OrderSend(..., ""+(Time[0] + Period()*60), ..); 
Then you can scan the orders and check :
PHP Code:
if(TimeCurrent() > OrderComment()) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0CLR_NONE); 
. This is a good solution because if you have several orders to close, you have all the time needed to do it.
i got the error below.what does ot mean?

PHP Code:
'>' different types in comparison    F:Program FilesMetaTrader FXOpenexpertsEMA_10.mq4 (8822
I make it like this
for the send order
PHP Code:
OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask-25*Point,Ask+TakeProfit*Point""+(Time[0] + Period()*60),SystemMagicNumber,0,Blue); 
and for the close order
PHP Code:
if(TimeCurrent() > OrderComment())
    {
     
OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0CLR_NONE);  
    } 
and i got the error shown above.
Is it right?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1066 (permalink)  
Old 04-28-2008, 01:59 PM
Michel Michel is offline
Senior Member
 
Join Date: Feb 2006
Posts: 509
Michel is on a distinguished road
my mistake, sorry.
This should work:
PHP Code:
if(TimeCurrent() > StringToInteger(OrderComment()) 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1067 (permalink)  
Old 04-28-2008, 02:31 PM
bearfoot090 bearfoot090 is offline
Junior Member
 
Join Date: Dec 2007
Posts: 5
bearfoot090 is on a distinguished road
It come to error like this.I try to put
entern int StringToInteger;
but still the error appear.
what should i do?
sorry for keep asking you but I really donno what I`m doing actually.So I would really appreciate your help .

PHP Code:
'StringToInteger' - function is not defined    F:Program FilesMetaTrader FXOpenexpertsEMA_10.mq4 (8728
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1068 (permalink)  
Old 04-28-2008, 03:05 PM
Michel Michel is offline
Senior Member
 
Join Date: Feb 2006
Posts: 509
Michel is on a distinguished road
Quote:
Originally Posted by bearfoot090 View Post
It come to error like this.I try to put
entern int StringToInteger;
but still the error appear.
what should i do?
sorry for keep asking you but I really donno what I`m doing actually.So I would really appreciate your help .

PHP Code:
'StringToInteger' - function is not defined    F:Program FilesMetaTrader FXOpenexpertsEMA_10.mq4 (8728
"entern int StringToInteger;" has no meaning. but it's again my mistake, so again sorry... the function is StrToInteger()
So the code to close the orders sould be something like this :
PHP Code:
for(int i OrdersTotal() - 1>= 0--)
{
   
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   if(
OrderMagicNumber() != Magic) continue;
   if(
TimeCurrent() > StrToInteger(OrderComment())) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0CLR_NONE);  


Last edited by Michel : 04-28-2008 at 03:10 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1069 (permalink)  
Old 04-28-2008, 03:52 PM
bearfoot090 bearfoot090 is offline
Junior Member
 
Join Date: Dec 2007
Posts: 5
bearfoot090 is on a distinguished road
thank you michel!
I can compile it with no errors now.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1070 (permalink)  
Old 05-01-2008, 12:57 PM
solamax's Avatar
solamax solamax is offline
Junior Member
 
Join Date: Apr 2008
Posts: 12
solamax is on a distinguished road
error codes 130 & 131

speaking of error codes - does anybody know what these error codes mean?

they come up all the time when the EA tries to open a trade but cant because of this error


many thnx 4 any help
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/questions/270-ask.html
Posted By For Type Date
OzFx System:) - Page 639 This thread Refback 06-21-2008 09:53 PM
Forex SRDC Sidus Sibkis EA MT4 Forum OTCSmart This thread Refback 12-08-2007 11:46 AM


All times are GMT. The time now is 08:28 AM.