Slawa How to Close trade and Open new one at same NEW Bar???

 
Slawa How to Close trade and Open new one at same Bar???
Example:
Short trade is open already or TotalTrades=1 (OPEN SELL).At the begining of new bar there is signal for long trade.EA first close short trade and after that open long trade but at same BAR(for example M15).
Please help???
Jeff
 
the simple example
if (BuySignal)
  {
  if (OrdersTotal()>0)
    {
    for(int i=OrdersTotal()-1,i>=0,i--)
       }
       if (OrderSelect(i,SelectByPos))
          {
          if (OrderType()==OP_SELL)
             {
             OrderClose(OrderTicket(),OrderLots()...)
             }
          }
       {
    }
    OrderSend(Symbol(),OP_BY,...) 
  }



 
[quote]the simple example
[code]if (BuySignal)
{
if (OrdersTotal()>0)
{
for(int i=OrdersTotal()-1,i>=0,i--)
}
if (OrderSelect(i,SelectByPos))
{
if (OrderType()==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots()...)
}
}
{
}
OrderSend(Symbol(),OP_BY,...)
}

Thank You.
 
You're welcome.
 
there is error at EA(Can you fix it):
//+------------------------------------------------------------------+
//| A.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

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

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

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double BuySignal;
if (BuySignal)
{
if (OrdersTotal()>0)
{
for(int i=OrdersTotal()-1,i>=0,i--)
}
if (OrderSelect(i,SELECT_BY_POS))
{
if (OrderType()==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,White)
}
}
{
}
OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"",0,0,Blue);
}

//----

//----
return(0);
}
//+------------------------------------------------------------------+
 
int start()
{
double BuySignal=0;
if (BuySignal==0)
{
if (OrdersTotal()>0)
{
for(int i=OrdersTotal()-1;i>=0;i--)
{
if (OrderSelect(i,SELECT_BY_POS))
{
if (OrderType()==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
}
}
}
{
OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"",0,0,Blue);
}
}
}
//----

//----
return(0);
}
 
Thank you.But there is no trade.Try it.
int start()
{
double BuySignal=0;
if (Close[2]>Close[1])
{
if (OrdersTotal()>0)
{
for(int i=OrdersTotal()-1;i>=0;i--)
{
if (OrderSelect(i,SELECT_BY_POS))
{
if (OrderType()==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
}
}
}
{
OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"",0,0,Blue);
}
}
}
//----

//----
return(0);
}

Also can you insert code for short position(SellSignal).Thank you.
 
if (Close[1]>Open[1])
.....buy....
....
Reason: