Can someone explain to me, how to get all trades to close at the same place.

 
Can someone explain to me, how to get all trades to close at the same place, this is EA we are talking about?
You have one that sells at 1.30000, but the market has not thought so, you add a trade at 1.30090, but the market has not thought so either so you add a trade when the market turns at 1.30200 then we add the last trade with a takeprofit at 1.29950, and I want all those trades to close at 1.29950, how do I do that?
 
You can apply the same 1.29950 take profit in all trades.
 

When you buy, you enter at the Ask price, and when you sell, you enter at the Bid price.

To close a buy position, you close at the Bid price and to close a sell position, you close at the Ask price.


so you will loop through all open positions and have conditions in the loop:


input double CloseAtPrice = 1.29950; // price to close positions 

for (int i = PositionsTotal() - 1; i >= 0; i--){
             
       ulong posTicket = PositionGetTicket(i);

       if(posTicket > 0 && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY && currentBid == CloseAtPrice){
            
          trade.PositionClose(posTicket);
       }     
       if(posTicket > 0 && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL && currentAsk == CloseAtPrice){
            
          trade.PositionClose(posTicket);
       }  
        
}
(this would be if you wanted another way instead of using a normal take profit in the position)
 
Conor Mcnamara #:
input double CloseAtPrice = 1.29950;

There was an example price of 1.29950, how do I make the price dynamic, so that my EA closes at the same price every time without me having to monitor it, should I put an [i] where you have (input double CloseAtPrice = 1.29950;).

 
Kjell Jan Christer Lundqvist #:

There was an example price of 1.29950, how do I make the price dynamic, so that my EA closes at the same price every time without me having to monitor it, should I put an [i] where you have (input double CloseAtPrice = 1.29950;).

A dynamic price in what context? How should the 'close at price' change dynamically? Are you sure you're not just looking for a standard Take Profit? (ie. the trades close in profit after a certain number of points are reached)

Are you creating orders or positions?
 
Conor Mcnamara #:

A dynamic price in what context? How should the 'close at price' change dynamically? Are you sure you're not just looking for a standard Take Profit? (ie. the trades close in profit after a certain number of points are reached)

Are you creating orders or positions?

I thought this way, if you have several trades going on, why not make them close at the same time, you know how the market behaves, it's impossible to predict, I use 1 hour charts, it happens all too often my EA places a trade, then at a later time it turns in the opposite direction, then there is a sell and another, but after a while it goes in the right direction, if you have 30 pips set as a target, the second trade will also be 30 pips, you have 20 pips in between, why take them both out with 80 pips in takeprofit. It happens all too often that way.

 
Kjell Jan Christer Lundqvist #:

I thought this way, if you have several trades going on, why not make them close at the same time, you know how the market behaves, it's impossible to predict, I use 1 hour charts, it happens all too often my EA places a trade, then at a later time it turns in the opposite direction, then there is a sell and another, but after a while it goes in the right direction, if you have 30 pips set as a target, the second trade will also be 30 pips, you have 20 pips in between, why take them both out with 80 pips in takeprofit. It happens all too often that way.

There are many ways to close positions.

For example:

- Normal take profit

- Trailing take profit

- Close all on a net-mean take profit

- Close all on specific market price

- Close all when the account equity reaches a target

- Close positions if position profit started reducing (reached a positive threshold, then diverged to a negative threshold)

- Close all on the opposite signal if pnl is positive

- Close all if positions passed a time threshold and pnl is positive


The limit is your own imagination. Sometimes you should not overcomplicate it. Think about your trading strategy and really think about what will work best for that strategy.