How to close an order on first profitable open price?

 

Hello,

I programm an EA that runs on D1 charts and uses few standard MT indicators. I'd like to close the positions on first open price when trade is in profit. Would someone advise me, how to program that?


Thanks in advance,

Daffi

 
daffi:

Hello,

I programm an EA that runs on D1 charts and uses few standard MT indicators. I'd like to close the positions on first open price when trade is in profit. Would someone advise me, how to program that?


Just to clarify . . . you mean when the next D1 bar starts ?
 
daffi:
I'd like to close the positions on first open price when trade is in profit.
int start(){
    static datetime Time0;
    if (Time0 != Time[0]){  Time0 = Time[0];    // A new bar
        for(int 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
        &&  OrderProfit()       >  0.                       // and in profit.
        ){
            if (!OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(),
                    Slippage.Pips*pips2points/*, op.color*/ ))
                Alert( "OrderClose(ticket=", OrderTicket(), 
                       ", ...) [1] failed: ", GetLastError() );
        }
    }   // Newbar
    :
 
daffi:

Hello,

I programm an EA that runs on D1 charts and uses few standard MT indicators. I'd like to close the positions on first open price when trade is in profit. Would someone advise me, how to program that?


Thanks in advance,

Daffi

I really wonder, if you were able to "programm an EA that runs on D1 charts and uses few standard MT indicators", then I don't see any prb, in going about with this much simpler closing logic.

Reason: