How to select the order that have profit?

 

I' ve try this method but without effects:

    for (i =   OrdersTotal () - 1   ; i >= 0 ; i -- )            
    {//for2
    if (OrderSelect(i, SELECT_BY_POS)

    && OrderSymbol () == Symbol() 
    && diference <= OrderProfit () )

Also I can use OrderOpenPrice like that:

   int course = Bid ;
    for (i =   OrdersTotal () - 1   ; i >= 0 ; i -- )            
    {//for2
    if (OrderSelect(i, SELECT_BY_POS)

    && OrderSymbol () == Symbol() 
    && course + diference <= OrderOpenPrice () )

But still without effects:(

There could be more orders on the market not only this order.

I only know that on this price level is only one order and if it is here, than it is with some plus or neutral profit.

 

Try to replace

&& course + diference <= OrderOpenPrice () )

to

&& course + diference - OrderOpenPrice ()<Point )

 
BorysekPL:
I' ve try this method but without effects:
    for (i =   OrdersTotal () - 1   ; i >= 0 ; i -- )            
    {//for2
    if (OrderSelect(i, SELECT_BY_POS)

    && OrderSymbol () == Symbol() 
    && diference <= OrderProfit () )
  1. Always count down - good
  2. Always test return code - good
  3. Not filtering by magic number makes the EA incompatible with every other including manual trading.
  4. Since the thought is to select an order, I make it one statement with the open brace at the end. The FOR doesn't need a brace:
        for (int pos = OrdersTotal () - 1; pos >= 0; pos--) if(
           OrderSelect(pos, SELECT_BY_POS)
        && OrderMagicNumber() == magic.number
        && OrderSymbol()      == Symbol()
        && diference          <= OrderProfit () 
        ){
           :

  5.  && course + diference <= OrderOpenPrice () )
    Bid >= OrderOpenPrice() + diference // Bid above OOP by 'diference'

  6. but without effects
    Is the order still open? The above will not get closed orders.
        datetime lastClose;
        for(int pos= OrdersHistoryTotal() - 1; pos--) if (
            OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)   // Only orders w/
        &&  OrderCloseTime()    > lastClose                 // not yet processed,
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol()                 // and my pair.
        &&  OrderType()         <= OP_SELL // Avoid cr/bal forum.mql4.com/32363#325360
        ){
            lastClose = OrderCloseTime();
            double lastTicket = OrderTicket()
            :

 
          for ( i =   OrdersTotal () - 1   ; i >= 0 ; i -- )
        if (OrderSelect(i, SELECT_BY_POS)
        && OrderMagicNumber () == Ticket
        && OrderSymbol () == Symbol() 
        && OrderType () == OP_BUY 
        && diference <= OrderProfit () )
              {

This is also doesn't working:(

Looking for help from anybody who knows what is wrong or another method to select order that have profit.

I am looking for open orders only that have profit >= variable.

 

You have the code already . . . I made some small modifications . . .

 for ( i = OrdersTotal()-1; i>=0; i-- )
        if (OrderSelect(i, SELECT_BY_POS)
        && OrderMagicNumber() == MagicNumber         //  if you don't use a Magic Number leave this out
        && OrderSymbol() == Symbol() 
        && OrderType() < OP_BUYLIMIT                 //   this selects BUY and SELL orders
        && OrderProfit() >= variable )
              {
 
BorysekPL:

This is also doesn't working:(

Looking for help from anybody who knows what is wrong or another method to select order that have profit.

I am looking for open orders only that have profit >= variable.

Can the prb be...
 && diference <= OrderProfit () )<--------- what type of variable you "define" diference? is it pips? price? dollars? or dime? your base currency?
 
&& OrderMagicNumber () == Ticket
will never be true.
 
BorysekPL:

This is also doesn't working:(

&& OrderMagicNumber () == Ticket

will never be true.
 

1.DIOSTAR

Can the prb be...
 && diference <= OrderProfit () )<--------- what type of variable you "define" diference? is it pips? price? dollars? or dime? your base currency?


double point = MarketInfo(Symbol(),MODE_POINT);
double diference = 20 * point;

2.RaptorUK

You have the code already . . . I made some small modifications . . .

 for ( i = OrdersTotal()-1; i>=0; i-- )
        if (OrderSelect(i, SELECT_BY_POS)
        && OrderMagicNumber() == MagicNumber         //  if you don't use a Magic Number leave this out
        && OrderSymbol() == Symbol() 
        && OrderType() < OP_BUYLIMIT                 //   this selects BUY and SELL orders
        && OrderProfit() >= variable )
              {																						
Why You have use?:	 && OrderType() < OP_BUYLIMIT  ?
3.WHRoeder 2011.09.26 20:27 
&& OrderMagicNumber () == Ticket
will never be true.
I know and, only use it as a Variable, sorry it should be written OrderMagicNumber () == MagicNumber 
 

BorysekPL:

Why You have use?: && OrderType() < OP_BUYLIMIT ?

You said . . "or another method to select order that have profit." this selects BUY or SELL orders . . see here: https://docs.mql4.com/constants/trading if you want just BUY orders use OrderType() == OP_BUY, if you want just SELL orders use OrderType() == OP_SELL

 

Then the problem is obvious:

double point = MarketInfo(Symbol(),MODE_POINT);
double diference = 20 * point; -------------------------------> diference is always 20*Point = 20 PIP (or 0.2 if fractional-point instrument)

but:

 && diference <= OrderProfit () )<--------- OrderProfit () returns PROFIT in terms of BASE CURRENCY, (not PIP)

In terms of computational, the above condition may be OK and not erroneous because it gives a BOOLEAN result.
In terms of common sense, it is no sense to compare one value (in PIPS) with another value in (Dollars, Dimes, Pennis, etc, your BASE currncy).

As an illustration only;
Case 0: Suppose Profit for 10 Lot goes above 20 Dollars (not pips), then TRUE. Pips gain = 0.2 Pips. 
Case 1: Suppose Profit for 1 Lot goes above 20 Dollars (not pips), then TRUE. Pips gain = 2 Pips.  
Case 2: Suppose Profit for 0.1 Lot goes above 20 Dollars (not pips), then TRUE. Pips gain = 20 Pips.
Case 3: Suppose Profit for 0.01 Lot order goes above 20 Dollars (not pips), then TRUE. Pips gain = 200 Pips???

Conclusion: 
It may be right computationally only, but senseless to compare such varying PIPs against a fixed amount in (Dollars, Dimes, Pennis, etc, your BASE currncy).