- Order types
- Structures and unions
- Trading account information
When you buy, you enter at the Ask price, and when you sell, you enter at the Bid 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)
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;).
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?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.
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.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use