View Single Post
  #125 (permalink)  
Old 04-13-2008, 01:00 PM
Badguy's Avatar
Badguy Badguy is offline
Member
 
Join Date: Jan 2006
Posts: 43
Badguy is on a distinguished road
Hi Coders

I'm still learning by copy and past, because I'm a totally newbie.

I need a function thats close all open trades at specified time.
I have try something.
Don't have any errors with compile. But with strategytester I have follow message:
Testgenerator: unmatched data error(volume limit 719 at 2008.03.27 12:30 exeeded
Testgenerator: unmatched data error(volume limit 135 at 2008.03.27 23:00 exeeded



Black thats the original code. That works
Blue thats what i i like to insert

Thanks for any help

//+-----------------------------------------------------------------------+
//| Check for close order conditions |
//+-----------------------------------------------------------------------+
void CheckForCloseConditions()
{
int ticket;

for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false ) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
if(OrderType()==OP_BUY)
{
if (GetSignal()==1)
{

OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
return(0);
}



}
if(OrderType()==OP_SELL)
{

if (GetSignal()==2)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
return(0);
}


}
}
return(0);
}

//+-----------------------------------------------------------------------+
//| Check for close order conditions trailing |
//+-----------------------------------------------------------------------+
void CheckForCloseConditionsTrailing()
{
int ticket;

for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false ) break;
if(OrderMagicNumber()!=MAGICMA_Trailing || OrderSymbol()!=Symbol()) continue;
if(OrderType()==OP_BUY)
{
if (GetSignal()==1)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
return(0);
}

if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}


}
if(OrderType()==OP_SELL)
{

if (GetSignal()==2)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
return(0);
}

if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Poi nt*TrailingStop,OrderTakeProfit(),0,Magenta);
return(0);
}
}
}

}
}
return(0);
}

//+-----------------------------------------------------------------------+
//| Start function |
//+-----------------------------------------------------------------------+

int start()


//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX

//Close Open Orders by Time

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX

if (UseCloseTime){
if (!(Hour()>=CloseTime && Hour()>=CloseTime)) {
Comment("Time for close trade has come !");
return(0);
} else Comment("");
}else Comment("");


{
int ticket;

for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false ) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
if(OrderType()==OP_BUY)
{
{

OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
return(0);
}



}
if(OrderType()==OP_SELL)
{

{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
return(0);
}


}
}
return(0);
}

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX

//Close Open Trailing Orders by Time

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX


if (UseCloseTime){
if (!(Hour()>=CloseTime && Hour()>=CloseTime)) {
Comment("Time for close trailing trade has come !");
return(0);
} else Comment("");
}else Comment("");




{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false ) //break;
if(OrderMagicNumber()!=MAGICMA_Trailing || OrderSymbol()!=Symbol()) //continue;
if(OrderType()==OP_BUY)
{
// if (GetSignal()==1)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
return(0);
}

if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}


}
if(OrderType()==OP_SELL)
{

{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
return(0);
}

if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Poi nt*TrailingStop,OrderTakeProfit(),0,Magenta);
return(0);
}
}
}

}
}
return(0);



if(CalculateNumberOfOrders(Symbol())<1&&CalculateN umberOfOrdersTrailing(Symbol())<1)
CheckForOpenConditions();
else
{
CheckForCloseConditions();
CheckForCloseConditionsTrailing();
}


return(0);

}

Last edited by newdigital; 04-13-2008 at 01:21 PM.
Reply With Quote