MQL4 - automated forex trading   /  

Code Base

ODL Securities

Code Base  Scripts  Close Orders To post a new code, please log in or register

This script is for
MetaTrader 4
Download MT 4 - 3.5 Mb

Mobile trading!
Buy a license and be mobile in your trading!

Name:
Close Orders
Author: sxTed (2007.11.21 05:35)
Downloaded: 2558
Download:
 _CloseOrders.mq4 (7.1 Kb) View

    Author:

    sxTed

    Description:

    Close all multi currency open orders and cancel pending orders according to various scenarios. Slippage for open orders is calculated for each currency.
    Choose only one scenario per visit, the script processes the first menu item selected.

    20 comments: 1 2   To post a new comment, please log in or register
    bnbb2004, thank you for the compliment.
    21.09.2008 14:38 sxTed
    chris phs, sorry for the delay I only check mail at the week end, if open orders are EURUSD and USDJPY and current chart where the script is launched from is GBPUSD then orders for EURUSD and USDJPY will be closed.
    21.09.2008 14:36 sxTed
    Does this script close just the orders from the currently viewd pair/chart, or does it close all open orders in the terminal regardless of how many pairs are being traded?
    16.09.2008 03:09 chris_phs
    Works great!  Thx!!  :-)
    25.07.2008 23:06 bnbb2004
    thank you for interest.
    19.03.2008 15:29 he74
    he74, If you are trading on a live account - then close all orders and stop. Ask your question on the main forum - as I do not understand, sorry.
    19.03.2008 14:46 sxTed
    i don't know why but system made more lost than digit in system (inside). at the present i can't open any orders. everyone is close directly after opening. is there any minimum capital i need on the acoount or other parameters?
    19.03.2008 13:41 he74
    he74, I do not understand your problem, sorry.
    19.03.2008 12:56 sxTed
    thanks, but i don't understand how system works. qeuity was 6900 i set up 5000 (level after close orders). system closed orders but queity was 3900. when i type 3000 (level of lost), every order is automaticly close. it doesn't matter quantity 100k, 50k, 10k. what should i put that system works good?
    19.03.2008 11:47 he74
    sxTed wrote:
    //+------------------------------------------------------------------+
    //|                              CloseOrdersLessThanStatedEquity.mq4 |
    //|                                          Copyright © 2008, sxTed |
    //|                                               sxted@talktalk.net |
    //+------------------------------------------------------------------+
    #property copyright "Copyright © 2008, sxTed"
    #property link      "sxted@talktalk.net"
     
    //+------------------------------------------------------------------+
    //| EX4 imports                                                      |
    //+------------------------------------------------------------------+
    #include <stdlib.mqh>
     
    //+------------------------------------------------------------------+
    //| input parameters:                                                |
    //+-----------0---+----1----+----2----+----3]------------------------+
    extern double CloseOrdersWhenEquityLessThan = 0.0;
     
    //+------------------------------------------------------------------+
    //| global variables to program:                                     |
    //+------------------------------------------------------------------+
    double Price[2];
    int    giSlippage;
     
    //+------------------------------------------------------------------+
    //| expert initialization function                                   |
    //+------------------------------------------------------------------+
    int init() {
      return(0);
    }
     
    //+------------------------------------------------------------------+
    //| expert deinitialization function                                 |
    //+------------------------------------------------------------------+
    int deinit() {
      return(0);
    }
     
    //+------------------------------------------------------------------+
    //| expert start function                                            |
    //+------------------------------------------------------------------+
    int start() {
      int iOrders=OrdersTotal(), i;
      if(AccountEquity() < CloseOrdersWhenEquityLessThan && iOrders > 0) {
        for(i=iOrders-1; i>=0; i--) {
          if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
            if((OrderType()<=OP_SELL) && GetMarketInfo()) {
              if(!OrderClose(OrderTicket(),OrderLots(),Price[1-OrderType()],giSlippage)) Print(OrderError());
            }
            else if(OrderType()>OP_SELL) {
              if(!OrderDelete(OrderTicket())) Print(OrderError());
            }
          }
        }
        Alert("Equity low - all open orders closed and pending orders cancelled");
      }
      return(0);
    }
     
    //+------------------------------------------------------------------+
    //| Function..: OrderError                                           |
    //+------------------------------------------------------------------+
    string OrderError() {
      int iError=GetLastError();
      return(StringConcatenate("Order:",OrderTicket()," GetLastError()=",iError," ",ErrorDescription(iError)));
    }
     
    //+------------------------------------------------------------------+
    //| Function..: GetMarketInfo                                        |
    //| Returns...: bool Success.                                        |
    //+------------------------------------------------------------------+
    bool GetMarketInfo() {
      RefreshRates();
      Price[0]=MarketInfo(OrderSymbol(),MODE_ASK);
      Price[1]=MarketInfo(OrderSymbol(),MODE_BID);
      double dPoint=MarketInfo(OrderSymbol(),MODE_POINT);
      if(dPoint==0) return(false);
      giSlippage=(Price[0]-Price[1])/dPoint;
      return(Price[0]>0.0 && Price[1]>0.0);
    }
    //+------------------------------------------------------------------+
    he74, please try the above expert.

    19.03.2008 11:39 he74