MQL4 - automated forex trading   /  

Forum

How can i close any order with out Order window

Back to topics list To post a new topic, please log in or register

avatar
5
samangp4 2007.06.25 10:29 

How can i close any order without this Dialog windows

I Wanna close position by code without any Human Plz Help me

With out this Window...

article

Automated Trading Championship 2006 Has Begun

Both Participants and ourselves worked hard during these two months. Since now, nothing will depend on us or on expert developers, everything will be done automatically. We have just to watch the development of the Championship.


avatar
Moderator
33780
Rosh 2007.06.25 11:49 

avatar
5
samangp4 2007.06.25 12:14 

When Expert Run & Execute this code:

Example:

OrderClose(3432945,0.10,1.3445,1,CLR_NONE);
return(0);

this Form Show Again & Need 1 person to close order

How can i click close button of this form by code?!

I Wanna click close button by code at current point.


avatar
Moderator
33780
Rosh 2007.06.25 12:17 
No. It's impossible. You need use dll in this matter.

avatar
231
fireflies 2007.06.25 12:26 
Is it probably because in Tools > Options > Expert Advisors you have selected "Allow live trading" AND "Ask manual confirmation" ?


avatar
Moderator
33780
Rosh 2007.06.25 12:32 
fireflies wrote:
Is it probably because in Tools > Options > Expert Advisors you have selected "Allow live trading" AND "Ask manual confirmation" ?


Yes. Uncheck this option and confirmation won't appear.

avatar
5
samangp4 2007.06.25 12:32 

can u give me an Api Function to do this?

Or Dll name in system 32

do u know Name of this button??

btnClose Or....

:)


avatar
5
samangp4 2007.06.25 12:34 

it doesn't work its impossible


avatar
Moderator
5089
stringo 2007.06.25 15:27 
samangp4 wrote:

How can i close any order without this Dialog windows

I Wanna close position by code without any Human Plz Help me

With out this Window...


Disable "Ask manual confirmation" in the expert properties

avatar
5
xnasir 2007.06.26 01:44 

1. MAKE A NEW SCRIPT AND ADD THE FOLLOWING CODE TO IT

2. SELECT THE CURRENTLY OPENED POSITION AND DOUBLE CLICK THE ABOVE SAVED SCRIPT, WHICH WILL APPEAR IN THE NAVIGATOR WINDOW (VIEW > NAVIGATOR)

3. THE SCRIPT WILL CONFIRM IF YOU REALLY WISH TO CLOSE THE SELECTED POSITION.

//+------------------------------------------------------------------+
//| close. mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property show_confirm

//+------------------------------------------------------------------+
//| script "close first market order if it is first in the list" |
//+------------------------------------------------------------------+
int start()
{
bool result;
double price;
int cmd,error;
//----
if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES))
{
cmd=OrderType();
//---- first order is buy or sell
if(cmd==OP_BUY || cmd==OP_SELL)
{
while(true)
{
if(cmd==OP_BUY) price=Bid;
else price=Ask;
result=OrderClose(OrderTicket(), OrderLots(), price, 3, CLR_NONE);
if(result!=TRUE) { error=GetLastError(); Print("LastError = ", error); }
else error=0;
if(error==135) RefreshRates();
else break;
}
}
}
else Print( "Error when order select ", GetLastError());
//----
return(0);
}
//+------------------------------------------------------------------+


avatar
5
samangp4 2007.06.26 23:41 
by this code u can click any Button in any location by SetCursorPosition
Example in C#:
       [DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y); 
 
[DllImport("user32.dll")]
static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData,  int dwExtraInfo);
 
[Flags]
  public enum MouseEventFlags
  {
    LEFTDOWN   = 0x00000002,
    LEFTUP     = 0x00000004,
    MIDDLEDOWN = 0x00000020,
    MIDDLEUP   = 0x00000040,
    MOVE       = 0x00000001,
    ABSOLUTE   = 0x00008000,
    RIGHTDOWN  = 0x00000008,
    RIGHTUP    = 0x00000010
  }
....
//Set cursor position 
            SetCursorPos(500, 480);
            //Mouse Right Down and Mouse Right Up
            mouse_event((uint)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
            mouse_event((uint)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
---------------------------------------------------------------------
Note:
SetCursorPos(int X,int Y);
X: x of mouse Location for Click(in close button rectangle) 
Y: Y of mouse Location for Click(in close button rectangle)
Back to topics list  

To add comments, please log in or register