请教,怎么让两个单子分别平仓?谢谢
{:soso_e183:}谢谢
源码如下:
extern double SHORT=500;
extern double LONG=520;
extern double MID=180;
int bb=0, ss=0;
input double TrailingStop=600;
double total, ticket,Lots;
int start()
{
double MacdCurrent, MacdPrevious, SignalCurrent;
double SignalPrevious;
double MacdCurrent1, MacdPrevious1, SignalCurrent1;
double SignalPrevious1;
int cnt;
MacdCurrent=iMACD(NULL,0,SHORT,LONG,MID,PRICE_CLOSE,MODE_MAIN,1);
MacdPrevious=iMACD(NULL,0,SHORT,LONG,MID,PRICE_CLOSE,MODE_MAIN,11);
SignalCurrent=iMACD(NULL,0,SHORT,LONG,MID,PRICE_CLOSE,MODE_SIGNAL,1);
SignalPrevious=iMACD(NULL,0,SHORT,LONG,MID,PRICE_CLOSE,MODE_SIGNAL,11);
MacdCurrent1=iMACD(NULL,PERIOD_M15,SHORT,LONG,MID,PRICE_CLOSE,MODE_MAIN,1);
MacdPrevious1=iMACD(NULL,PERIOD_M15,SHORT,LONG,MID,PRICE_CLOSE,MODE_MAIN,11);
SignalCurrent1=iMACD(NULL,PERIOD_M15,SHORT,LONG,MID,PRICE_CLOSE,MODE_SIGNAL,1);
SignalPrevious1=iMACD(NULL,PERIOD_M15,SHORT,LONG,MID,PRICE_CLOSE,MODE_SIGNAL,11);
Lots=NormalizeDouble(AccountFreeMargin()*1/10000.0,1);
total=OrdersTotal();
if(total<1)
{ bb=0; ss=0;
if(MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious )
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"macd sample",16384,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
bb=1;
}
}
}
if((0<total<2)&&(OrderType()== OP_BUY)){
Strateg(1);
}
if( MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious )
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"macd sample",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
ss=1;
}
return(0);
}
if((0<total<2)&&(OrderType()== OP_SELL)){
Strateg(2);
}
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(ss=1&&OrderType()==OP_SELL) // long position is opened
{
if( MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious )
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); // close position
return(0); // exi }
}
else // go to short position
{
if(MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Red); // close position
return(0); // exit
}
}
}
return(0);
}
}
if(OrderType()<=OP_BUY && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(bb=1&&OrderType()==OP_BUY) // long position is opened
{
if( MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious )
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); // close position
return(0); // exi }
}
else // go to short position
{
if(MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); // close position
return(0); // exit
}
}
}
}
}
//2222222222222222222222222222======================
void Strateg (int vv)
{
total=OrdersTotal();
if(total<2)
{
if (vv==1 && bb==1&&(OrderOpenPrice()-Point*TrailingStop>=Bid) )
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"macd sample",2007,0,Yellow);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
return(0);
}
if (vv==2 && ss==1&&(Ask>=OrderOpenPrice()+Point*TrailingStop) )
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"macd sample",2007,0,White);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
return(0);
}
}
}
// the end.
牛版,出手帮帮忙吧。{:soso_e183:} 看看。。。。。
页:
[1]