Forex
Google
New signals service!

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions


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
  #381 (permalink)  
Old 10-03-2006, 09:03 AM
Junior Member
 
Join Date: Apr 2006
Posts: 6
MehdiForex is on a distinguished road
Hello all,

I want to close all my orders at the same time but i coudn't.
I tried this code but it didn't work :

''''''''''''''''''''''''''''''''''''''''

total = OrdersTotal();
for(i=0;i < total;i++)
{
if(OrderSelect(i, SELECT_BY_POS)==true)
{
OrderClose(OrderTicket(),OrderLots(),Ask,80,CLR_NO NE);
OrderClose(OrderTicket(),OrderLots(),Bid,80,CLR_NO NE);
}
}

''''''''''''''''''''''''''''''''''''''''
Can anybody help me ?
I would be very grateful if you can help me
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #382 (permalink)  
Old 10-03-2006, 09:16 AM
Member
 
Join Date: Sep 2005
Location: Athens
Posts: 69
Yannis is on a distinguished road
Mehdi,
Put this code (procedure) outside start() section and when you if the condition is met to close all trades, just call the procedure like that:


int start()
{ // your code here .....
If (your condition here) ShutDownAllTrades();
}

void ShutDownAllTrades
{ int Retry;
While (OrdersTotal()>0)
{ for (int cnt=OrdersTotal()-1;cnt>=0;cnt--)
{ OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderType()==OP_BUY)
{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }
RefreshRates();
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage, Yellow);
Sleep(1000);
}
else if (OrderType()==OP_SELL)
{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }
RefreshRates();
OrderClose(OrderTicket(),OrderLots(),Ask,Slippage, Yellow);
Sleep(1000);
}
else
{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }
OrderDelete(OrderTicket());
Sleep(1000);
}
}
}
}

HTH

Yannis
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #383 (permalink)  
Old 10-03-2006, 01:15 PM
Junior Member
 
Join Date: Apr 2006
Posts: 6
MehdiForex is on a distinguished road
Dear Yannis,

Thanks for your help.
I wish you the best.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #384 (permalink)  
Old 10-03-2006, 01:25 PM
Junior Member
 
Join Date: Apr 2006
Posts: 6
MehdiForex is on a distinguished road
Quote:
Originally Posted by Yannis
Mehdi,
Put this code (procedure) outside start() section and when you if the condition is met to close all trades, just call the procedure like that:


int start()
{ // your code here .....
If (your condition here) ShutDownAllTrades();
}

void ShutDownAllTrades
{ int Retry;
While (OrdersTotal()>0)
{ for (int cnt=OrdersTotal()-1;cnt>=0;cnt--)
{ OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderType()==OP_BUY)
{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }
RefreshRates();
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage, Yellow);
Sleep(1000);
}
else if (OrderType()==OP_SELL)
{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }
RefreshRates();
OrderClose(OrderTicket(),OrderLots(),Ask,Slippage, Yellow);
Sleep(1000);
}
else
{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }
OrderDelete(OrderTicket());
Sleep(1000);
}
}
}
}

HTH

Yannis
Dear Yannis,

I added your procedure between " int deinit() { } " (out of start) as you said but there is a problem via compiling after void ShutDownAllTrades { : '{' comma or semicolon expected .

I look forward to hearing from you.
Thanks a lot

Last edited by MehdiForex; 10-03-2006 at 01:42 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #385 (permalink)  
Old 10-03-2006, 02:23 PM
Member
 
Join Date: Sep 2005
Location: Athens
Posts: 69
Yannis is on a distinguished road
Oops sorry.
What's missing is the () after void ShutDownAllTrades()

Be careful also for the variable named 'Slippage' in the orderclose function.
You might need to replace that with the one you are using when you place your orders.

Yannis
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #386 (permalink)  
Old 10-03-2006, 02:34 PM
Junior Member
 
Join Date: Apr 2006
Posts: 6
MehdiForex is on a distinguished road
Quote:
Originally Posted by Yannis
Oops sorry.
What's missing is the () after void ShutDownAllTrades()

Be careful also for the variable named 'Slippage' in the orderclose function.
You might need to replace that with the one you are using when you place your orders.

Yannis
It's working very well !
Thanks again
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #387 (permalink)  
Old 10-03-2006, 06:26 PM
european's Avatar
Senior Member
 
Join Date: Apr 2006
Posts: 284
european is on a distinguished road
Question

I am using MTF CCI indicator ftom Multi Time Frame indicators thread, it is a yellow step line, see image attached.

When the line is above 100 level (overbought)- the price will go down and when its below -100 (oversold) - the price will go up.

The only problem with it that it doesnt always refresh, i have to do it manually by right clicking on the chart and selecting 'Refresh'.

A question to programmers: Is there any function in MQ4 to do that kind of refresh automatically on every tick?

Would appreciate an advice.


euro pean
Attached Images
File Type: jpg MTF_CCI.JPG (36.5 KB, 106 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #388 (permalink)  
Old 10-03-2006, 07:51 PM
Member
 
Join Date: Dec 2005
Posts: 71
richx7 is on a distinguished road
Try this:

void ObjectsRedraw()
Redraws all objects on the chart

Sample
ObjectsRedraw();

You may need to use ObjectCreate first.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #389 (permalink)  
Old 10-03-2006, 10:50 PM
european's Avatar
Senior Member
 
Join Date: Apr 2006
Posts: 284
european is on a distinguished road
Quote:
Originally Posted by richx7
Try this:

void ObjectsRedraw()
Redraws all objects on the chart

Sample
ObjectsRedraw();

You may need to use ObjectCreate first.
Thanks for replying.

As far as I know ObjectsRedraw() refreshes objects that just been 'created' and 'set'.

I need to refresh an indicator which is not on the Object list, so ObjectsRedraw() doesnt work.

Or may be you know how to refer to an existing indicator?

Last edited by european; 10-04-2006 at 07:03 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #390 (permalink)  
Old 10-04-2006, 09:11 AM
Junior Member
 
Join Date: Apr 2006
Posts: 6
MehdiForex is on a distinguished road
Hi all,
I wrote an expert but it doesn't work very well i would be very grateful if anybody can help me .

I checked MACD in H4 in EUR/GBP and the condition is when the MODE_MAIN of MACD is > 0 BUY EUR and SELL GBP and when is < 0 first of all close previous position and open SELL EUR and BUY GBP.

It usually open just one of them .

Thanks

Last edited by MehdiForex; 10-04-2006 at 12:37 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
histogram

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

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 05:37 PM.



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