Closing only profitable trades in the account

 

Hi,

Can anyone help me to find an EA which should close only the profitable trades in the account.

There could be multiple trades, may be 5, 10 or 20 regardless of the currency pair.

Thank you in advance

 
EDIT: back to the drawing board
 

Thanks for the EA, but there are no settings...

It must be able to set the profit target ( how many Dollars or pips)

Otherwise better a trailer to move the price and lock - In this case should have a separate EA for the stop loss or built in stop

Should be able to set the limits in the trailer and/or stop

Thanks again

 

In actual fact - amend it first.


Ziebol - you have built an incrementing loop rather than a decrementing loop because you have not performed a dry run of your code in order to envisage what will happen if there are multiple orders in the pool. It frustrates me not only that people continue to do this, when it is FREQUENTLY documented on this forum, but worse, that they see fit to spread poor code.


Here's what would happen if, say there were 5 orders (all in profit in this case):

Orders exist: 0,1,2,3,4

Order 0 - Closed, Orders exist: 0,1,2,3 (because they now fill those positions in the pool)

Counter incremented to 1

Order 1 - Closed, Orders exist 0,1,2

Counter incremented to 2

Order 2 - Closed, Orders exist 0,1

Counter incremented to 3

Nonexistent order

Counter incremented to 4

Nonexistent order

Loop exited

2 orders remain - those originally at positions 1 and 3 (ie. 2nd and 5th orders)


To fix this, make the loop decrement instead from the total number of orders minus 1 down to zero.


Additionally:

- the code is inconsistent in its use of the bid/ask prices - MarketInfo(Symbol(),MODE_BID) in one line and Bid in the next

- And there is absolutely no error checking or logging - what happens if an order fails to close?

- Relative value of TP should be set as an extern to make this EA any use

- There is no check that the orders in the pool belong to the symbol of the current chart


Please put a bit more thought into your code before taking the step to decide that its worthy of being published.


CB

 

Powerstar - to be fair to the previous poster, you did not fully explain what you were asking for in your original post.


You're asking for free help. At least put some effort into defining your requirement.


eg. What does "regardless of the currency pair" mean to you? Does that mean an EA that will work on any chart and will act upon orders of that specific currency pair? Or does it mean an EA that will work on any chart and will close all orders regardless of their currency pair?


CB

 

<rant>

This forum gets worse by the day.


Sloppy questions.


And sloppy answers.


Programming is a world where precision is required.


What's the world coming to?

</rant>

CB

 
cloudbreaker wrote >>

<rant>

This forum gets worse by the day.

Sloppy questions.

And sloppy answers.

Programming is a world where precision is required.

What's the world coming to?

</rant>

CB

I guess I can relate to your frustration. But MQL is not like conventional programming and I guess it does require different thinking or visualising market/price behaviour before we think about possible question/solutions.

 
Kent:

I guess I can relate to your frustration. But MQL is not like conventional programming and I guess it does require different thinking or visualising market/price behaviour before we think about possible question/solutions.

On the contrary MQL is no different from any other sort of programming.

For example, when writing an event-driven windows application, we need to envisage all the range of possibilities regarding a user's actions.

If anything, users are less predictable than any market ;-)


CB

 

Hi all of you,

Sorry if you have missunderstood what I mean.

Ok lets say I have a special EA to enter orders by selecting the best position. This EA only open buy or open sell at the correct timing and position.

After some time there will be floating orders in the pool, we assume we have 10 orders and 5 have already in profit.

I need a separate EA to close these orders in which are in profit and should be able to set the limits ( profit in pips or Dollars)

If we say that we set to have a profit of 15 pips, then the second EA will close only the 5 orders with 15 pip profit and the balance 5 will remain until it reaches 15 pips or more.

Say again out of the balance 5, 4 goes to profit and 1 goes against, we set a stop and limit the drawdown. Here I want to set the stop limits too.

I think this should explain better.

Thank you

Reason: