How I set the TP less than 5 pips? - page 4

 
Is it correct? It will close only the orders of the last 100minutes
if(Bid>CloseforBuy)
{
   for(int a=OrdersTotal()-1;a>=0;a--)
      if( OrderSelect(a,SELECT_BY_POS, MODE_TRADES) && 
      OrderType()==OP_BUY && TimeCurrent()-OrderOpenTime() <= 100  &&
      OrderSymbol()==Symbol() )
         if( !OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, White) )
            Print("OrderClose failed, error: ", GetLastError());
            }



if(Ask<CloseforSell)
{
   for(int b=OrdersTotal()-1;b>=0;b--)
      if( OrderSelect(b,SELECT_BY_POS, MODE_TRADES) && 
      OrderType()==OP_SELL &&  TimeCurrent()-OrderOpenTime() <= 100  &&
      OrderSymbol()==Symbol() )
         if( !OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, White) )
            Print("OrderClose failed, error: ", GetLastError());
            }
 
ats:
Is it correct? It will close only the orders of the last 100minutes

Almost, TimeCurrent() gives a datetime representing the server time of the last tick . . .

Note: datetime type (integer representing the amount of seconds elapsed from midnight, 1 January, 1970).

So you need to check that . . .

TimeCurrent()-OrderOpenTime() <=

100 minutes . . . . or (100 * 60) seconds

 

Thank you very very much for your help!

Happy trading!

 

Hello!

I tried to modify the EA but it doesn´t work properly. Do you have any idea where is the mistake?

Thank you

extern double TPforBuys=1;
extern double TPforSells=1;
extern double TimeForEA=120;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{

return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{

return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{


double TPbuy = TPforBuys / 10000;
double TPB=OrderOpenPrice()+ TPbuy;

// Close Buys
if(Bid>TPB)
{
   for(int a=OrdersTotal()-1;a>=0;a--)
      if( OrderSelect(a,SELECT_BY_POS, MODE_TRADES) && 
      OrderType()==OP_BUY && TimeCurrent()-OrderOpenTime() <= (TimeForEA * 60)  &&
      OrderSymbol()==Symbol() )
         if( !OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, White) )
            Print("OrderClose failed, error: ", GetLastError());
            }



double TPsell = TPforSells / 10000;
double TPS=OrderOpenPrice()- TPsell;



// Close Sells
if(Ask<TPS)
{
   for(int b=OrdersTotal()-1;b>=0;b--)
      if( OrderSelect(b,SELECT_BY_POS, MODE_TRADES) && 
      OrderType()==OP_SELL &&  TimeCurrent()-OrderOpenTime() <= (TimeForEA * 60) &&
      OrderSymbol()==Symbol() )
         if( !OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, White) )
            Print("OrderClose failed, error: ", GetLastError());
            }


return(0);
}
 

Try to change to this and see if this "works properly" ...

TimeCurrent()- OrderOpenTime() >= (TimeForEA * 60) // time to close
 

That is correct! The EA closes only orders that are not older than 2 hours! The problem is that it doesn´t close correctly all the orders after 1 pip! But I don´t know where is the mistake!

Thank you

 
ats:

That is correct! The EA closes only orders that are not older than 2 hours! The problem is that it doesn´t close correctly all the orders after 1 pip! But I don´t know where is the mistake!

Thank you

So it's working as you want it, am I correct ?. Coz I have no idea what you mean by "work properly" and I'm lazy enough and so not reading 4 pages of replies and codes.

So actually, I don't know exactly why I gave you that answer :)

 
onewithzachy:

So actually, I don't know exactly why I gave you that answer :)

It's nice to see honesty on the Internet for a change :-)
 
onewithzachy:

So it's working as you want it, am I correct ?. Coz I have no idea what you mean by "work properly" and I'm lazy enough and so not reading 4 pages of replies and codes.

So actually, I don't know exactly why I gave you that answer :)

No problem! Thank you!
 

When you do this . . . .

double TPB=OrderOpenPrice()+ TPbuy;

. . . which Order are you using the Open Price of ?? OrderOpenPrice() Note: "Order must be first selected by the OrderSelect() function."

Reason: