Equity Close with Stop Orders

 
Hello Everyone,

My trading system relies heavily on equity profits. I've been using different EAs and Scripts to close all open trades and pending orders once an equity profit has been reached. However, because the EA or Script closes the open trades one at a time, the profits can either increase or decrease due to the changing markets.

Instead, does anyone know of an EA (or can create one) that does the following:

1) Keeps track of what the equity would be if pending orders were placed closest the currency pair's price.

2) Once desired equity is reached according to where the pending orders will go, the EA will place a stop order at that price for all currency pairs.

3) As soon as a stop order is placed for all currency pairs, it then turns into a Trailing Stop for every pip movement.

4) All other EAs will not place any more trades until ALL open orders has hit their stops.

Basically, MT4 will allow you to put pending stop orders, for example, 2 pips away for EURUSD, 3 pips away for GBPUSD, 3 pips away for USDJPY, etc etc. for certain brokers. I would like the EA to monitor the equity at where the closest stop would be; not where the actual equity is. For instance, if the "stop order equity" for all currency pairs reaches $500, the EA will place a stop order instantly for all currency pairs.

For example, I would like to close out all my trades when my unrealized profits reach $500. I currently have 5 different trades open with different currency pairs. I would like this EA to calculate what the equity is if it puts in stop orders closest to the price. If my current equity for open trades is +$500, the actual equity of the potential stop orders wouldn't be as high. Because it has to be placed a few pips away, the pending order equity would be around $475 or so. Once the potential pending stop orders reach $500, the EA will instantaneously place stops closest to the currency pairs. Then it automatically turns into a trailing stop. Finally, until all stops are hit, no additional trades cannot be placed BY AN EA.

Does anyone know how to code this? If it's possible? Or if something like this has been made already? I'm not really a programmer and I've tried to do this on my own; and obviously I struck out. If someone could point me in the right direction, that would be great!

Thanks in advance for all your help!
 
jamesmean:
1) Keeps track of what the equity would be if pending orders were placed closest the currency pair's price.
2) Once desired equity is reached according to where the pending orders will go, the EA will place a stop order at that price for all currency pairs.
3) As soon as a stop order is placed for all currency pairs, it then turns into a Trailing Stop for every pip movement.
4) All other EAs will not place any more trades until ALL open orders has hit their stops.
  1. pending orders have no effect on equity, only once they open.
  2. open order with no stop loss will eventually wipe your account.
  3. There are many trailing stops EA in the code base.
  4. You must modify the other EA's.
 

1) I understand that it has no effect on equity, but I wanted an EA that would calculate the equity if the stop prices were the actual live prices.

2) Possibly, but I have other money management methods from keeping this from happening. I use a margin call as my stop. Because I'm using a lot of orders, I get a margin call with only a 4 or 5% drawdown.

3) I needed the trailing EAs to be combined with the equity stop that I'm looking for. I'm not sure how to combine it.

4) I'll go ahead and modify my EAs so that this can happen.

 
  1. double  chart.at.risk   = 0,
            perLotPerPoint  = PointValuePerLot();
    for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol() ){              // and my pair.
            double  DIRection = Direction( OrderType() ),
                    eRisk   = (OrderOpenPrice()-OrderStopLoss()) * DIRection;
            chart.at.risk  += eRisk* OrderLots() * perLotPerPoint;
    }
    ===================================
    double  Direction(int op_xxx){  return( 1. - 2. * (op_xxx%2) );                }
    double  PointValuePerLot() { // Value in account currency of a Point of Symbol.
        /* In tester I had a sale: open=1.35883 close=1.35736 (0.00147)
         * gain$=97.32/6.62 lots/147 points=$0.10/point or $1.00/pip.
         * IBFX demo/mini       EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000
         * IBFX demo/standard   EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000
         *                                  $1.00/point or $10.00/pip.
         *
         * https://forum.mql4.com/33975 CB: MODE_TICKSIZE will usually return the
         * same value as MODE_POINT (or Point for the current symbol), however, an
         * example of where to use MODE_TICKSIZE would be as part of a ratio with
         * MODE_TICKVALUE when performing money management calculations which need
         * to take account of the pair and the account currency. The reason I use
         * this ratio is that although TV and TS may constantly be returned as
         * something like 7.00 and 0.00001 respectively, I've seen this
         * (intermittently) change to 14.00 and 0.00002 respectively (just example
         * tick values to illustrate). */
        return(  MarketInfo(Symbol(), MODE_TICKVALUE)
               / MarketInfo(Symbol(), MODE_TICKSIZE) ); // Not Point.
    }
    
    Might like to look at my code to avoid margin calls
 
Thanks a lot for the suggestion. However, because I do not use stops in my trading strategies, I rely on margin calls to take me out of bad trade setups. Since I place a lot of orders, I can keep my strategy consistently profitable while having a margin call in place of my stop. The 50:1 leverage helps this a lot. If I placed less trades and my account starts losing money where a margin call wouldn't stop my trades, I would probably use some type of equity stop.
Reason: