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

 
You mean this way?
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()
{
for(int a=OrdersTotal()-1;a>=0;a--)

double TPbuy = TPforBuys / 10000;
if( OrderSelect(a,SELECT_BY_POS, MODE_TRADES) && 
      OrderType()==OP_BUY && OrderSymbol()==Symbol() )
double TPB=OrderOpenPrice()+ TPbuy;

// Close Buys
if(Bid>TPB)
{
   
      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;
if( OrderSelect(a,SELECT_BY_POS, MODE_TRADES) && 
      OrderType()==OP_SELL && OrderSymbol()==Symbol() )
double TPS=OrderOpenPrice()- TPsell;



// Close Sells
if(Ask<TPS)
{
   
      if( OrderSelect(a,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);
}
 
ats:
You mean this way?
I don't know . . . does that do what you want ?
 
RaptorUK:
I don't know . . . does that do what you want ?
No. It doesn´t! It is not correct again!
 
Perhaps you could explain what exactly you are trying to do ? for my benefit, for onewithzachy's benefit and of course in turn, your benefit.
 

Of course! sorry! I didn´t think about about it!

We made this EA for scalping! The EA should close every scalping-order with 1 pip profit! In order not to close the long term orders we used the command OrderOpenTime(). The scalping orders are set manually! It acts like TP but only with 1 pip profit!

Thank you

 
Ah I see, you don't want the EA to close the non-scalping, short term, orders . . .
 
RaptorUK:
Ah I see, you don't want the EA to close the non-scalping, short term, orders . . .
Exactly!
 

OK, some comments . . .

1. Your loop does virtually nothing, you need to enclose in braces, { } what you want done within the loop . . .

2. You have 2 OrderSelect() calls, if you put everything into the loop you will only need one . . .

3. the close buys section should only be executed for Buy orders, the close sells should only be executed for Sell orders

4. your 1 pip profit is hard coded for 4 digit pairs, so it won't work for pairs like USDJPY

 

Maybe something like this . . . .

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()
{
for(int a=OrdersTotal()-1;a>=0;a--)
   {
   double TPbuy = TPforBuys / 10000;
   
   if( OrderSelect(a,SELECT_BY_POS, MODE_TRADES) && 
   OrderType()==OP_BUY && OrderSymbol()==Symbol() )  // order type and Symbol checked here
      {
      double TPB=OrderOpenPrice()+ TPbuy;
      
      // Close Buys
      if(Bid>TPB)
         {
         
         if( TimeCurrent()-OrderOpenTime() <= (TimeForEA * 60) )  // no need to check type and symbol here
            if( !OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, White) )
               {
               Print("OrderClose failed, error: ", GetLastError());
               }
            else continue;        // if order has been closed move to the next position, no need to check if it's a SELL
         } // end of if(Bid>TPB)
      } // end of if( OrderSelect(a 
      
   double TPsell = TPforSells / 10000;
   
   if( OrderSelect(a,SELECT_BY_POS, MODE_TRADES) && 
   OrderType()==OP_SELL && OrderSymbol()==Symbol() )
      {
      double TPS=OrderOpenPrice()- TPsell;

      // Close Sells
      if(Ask<TPS)
         {
   
         if( TimeCurrent()-OrderOpenTime() <= (TimeForEA * 60) )
            if( !OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, White) )
               Print("OrderClose failed, error: ", GetLastError());
            
         } // end of if(Ask<TPS)
      } // end of if( OrderSelect(a
   } // end of for(int a=OrdersTotal()

return(0);
}
 
RaptorUK:

Maybe something like this . . . .

By the way, I haven't compiled or tested that code . . .
Reason: