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

 
I made the correction for sell or buy orders, I trade only eurusd so there is no problem with the symbols. I don´t use EA´s so all the orders are manually placed! The problem is how to differentiate to close the orders I have for scalping to the longtime orders
 
extern double CloseforBuy=1.4;
extern double CloseforSell=1.3;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

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

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


{
if(OrderType()==OP_BUY)
{
if(Bid>CloseforBuy)
{
for(int a=OrdersTotal()-1;a>=0;a--)
if(OrderSelect(a,SELECT_BY_POS, MODE_TRADES) )
//if(OrderSymbol()==Symbol())
OrderClose(OrderTicket(),OrderLots( ),OrderClosePrice(),1000,White);
//----

}}
if(OrderType()==OP_SELL)
{
if(Ask<CloseforSell)
{
for(int b=OrdersTotal()-1;b>=0;b--)
if(OrderSelect(b,SELECT_BY_POS, MODE_TRADES) )
//if(OrderSymbol()==Symbol())
OrderClose(OrderTicket(),OrderLots( ),OrderClosePrice(),1000,White);
//----
}}

return(0);
}
 

You can't do this . . .

if(OrderType()==OP_BUY)

. . . until after your OrderSelect() . . . . read the documentation for OrderType(), it says "Note: order must be selected by OrderSelect() function."

Try . . .

if(Bid>CloseforBuy)
   {
   for(int a=OrdersTotal()-1;a>=0;a--)
      if( OrderSelect(a,SELECT_BY_POS, MODE_TRADES) && 
      OrderType()==OP_BUY &&
      OrderSymbol()==Symbol() )
         if( !OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, White) )
            Print("OrderClose failed, error: ", GetLastError());

   }
 
deVries:

you can set tp at 25 pips and close the trade then at 5 pips

Yes, but if suddenly the prices change more than 5 pips, you'll be unable to close the order in time. It's part of the risks.

Best regards and happy trading!!!

 
RaptorUK:

You can't do this . . .

. . . until after your OrderSelect() . . . . read the documentation for OrderType() , it says "Note: order must be selected by OrderSelect() function."

Try . . .

Thank you very much for your help I made the correction! Great!!!

Do you have any proposals to filtrate and close one of the buys/sells and not all the orders. So it will be possible to scalp and keep the long term orders!

Thank you for your help!!!

 
ats:

Thank you very much for your help I made the correction! Great!!!

Do you have any proposals to filtrate and close one of the buys/sells and not all the orders. So it will be possible to scalp and keep the long term orders!

Probably but that is determined by your strategy . . . which order do you want to close and which do you want to leave running, when you have determined that it should be simple enough to code it.
 

To determine which order you want to close is easy. That is the order for scalping! Let´say the last order!

 

The basic idea is: 1. You have open long term positions and you want to scalp

2. you set a pending order

3. You switch the EA on

4. The EA closes only THIS order

5. You switch the EA off

 
ats:

To determine which order you want to close is easy. That is the order for scalping! Let´say the last order!

The last order placed should have the biggest order position number . . . you can double check by OrderOpenTime()
 
RaptorUK:
The last order placed should have the biggest order position number . . . you can double check by OrderOpenTime()

Good idea! I didn´t think about it
Reason: