342

I try to pair position Buy and sell by hedging.

if profit < 0 and not have sell position to square --- open sell and pair it.

if profit < 0 and  have sell position to square and opentime > my expect time --- close this pair(buy and sell)

now my code open and pair just 1 pair.

how can I do it.

Thank you.

```   void hedge_()
{
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderMagicNumber() == MagicNumber)
if(OrderSymbol()==Symbol() && OrderProfit()<0)
{
{
datetime time_op = OrderOpenTime();
{
if(!hed_){Print("Error Open hedge function "+IntegerToString(GetLastError()));}
else{Print("Open sell hedge function tk "+IntegerToString(ttkbuy));}
}

int a=0,b=OrdersTotal()-1;
{
while(a<1)
{
if(OrderMagicNumber() == MagicNumber)
if(OrderSymbol()==Symbol() && OrderType() ==OP_SELL)
{
{
if(TimeCurrent()-time_op >= 100)// 4hour
{
if(!chk2){Print("Error Close hedge function "+IntegerToString(GetLastError()));}
}
a++;
}

b--;
}

b--;
}
}
}
//----------------------
if(OrderType()==OP_SELL)
{

int ttksell = OrderTicket();
datetime time_op = OrderOpenTime();
{
if(!hed_){Print("Error Open hedge function "+IntegerToString(GetLastError()));}
else{Print("Open Buy hedge function tk "+IntegerToString(ttksell));}
}

int a=0,b=OrdersTotal()-1;;
{
while(a<1)
{
if(OrderMagicNumber() == MagicNumber)
if(OrderSymbol()==Symbol() && OrderType() ==OP_SELL)
{
if(OrderComment()==IntegerToString(ttksell))
{
if(TimeCurrent()-time_op >= 14400)// 4hour
{
bool chk2= OrderClose(OrderTicket(),OrderLots(),Bid,5,Pink);
if(!chk2){Print("Error Close hedge function "+IntegerToString(GetLastError()));}
}
a++;
}

b--;
}

b--;
}
}

}

//---------------------------------
}
}
}```