|
沙发
楼主 |
发表于 2016-11-27 04:39
|
只看该作者
入场方式如下
if(ma30H1>ma50H1 && ma50H1>ma100H1 && Close[0]>ma30 && Close[1]<ma30p)
以下是源码。
#property copyright "Copyright ?2016, MetaQuotes Software Corp."
#property link "HANLUN"
extern double Lots=0.1;
extern int ying=300;
int init()
{
return(0);
}
int deinit()
{
return(0);
}
int start()
{
double ma30=iMA(Symbol(),PERIOD_H1,30,0,MODE_SMA,PRICE_CLOSE,0);
double ma50=iMA(Symbol(),PERIOD_H1,50,0,MODE_SMA,PRICE_CLOSE,0);
// double ma80=iMA(Symbol(),0,80,0,MODE_SMA,PRICE_CLOSE,0);
double ma100=iMA(Symbol(),PERIOD_H1,100,0,MODE_SMA,PRICE_CLOSE,0);
//double ma13p=iMA(Symbol(),0,13,0,MODE_SMA,PRICE_CLOSE,1);
//double ma21p=iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,1);
double ma30p=iMA(Symbol(),PERIOD_H1,30,0,MODE_SMA,PRICE_CLOSE,1);
double ma50p=iMA(Symbol(),PERIOD_H1,50,0,MODE_SMA,PRICE_CLOSE,1);
// double ma80p=iMA(Symbol(),0,80,0,MODE_SMA,PRICE_CLOSE,1);
double ma100p=iMA(Symbol(),PERIOD_H1,100,0,MODE_SMA,PRICE_CLOSE,1);
double ma=iMA(Symbol(),0,30,0,MODE_SMA,PRICE_CLOSE,0);
double map=iMA(Symbol(),0,30,0,MODE_SMA,PRICE_CLOSE,1);
//if(((ma30>ma100)&&(ma100>ma50))||((ma30>ma100)&&(ma100>ma50))||((ma50>ma100)&&(ma100>ma30))||((ma50>ma30)&&(ma30>ma100))||((ma50>ma30)&&(ma30>ma100))||((ma50>ma100)&&(ma100>ma30))||((ma100>ma30)&&(ma30>ma50))||((ma100>ma30)&&(ma30>ma50)))
if((ma30>ma50)&&(ma50>ma100))
{
if((Close[0]>ma)&&(Close[1]<map))//价格上穿均线
{
if(danshu()==0)
{
buy(Lots,0,ying,Symbol()+"buy"+Lots,0);
}
}
}
//if(((ma30>ma100)&&(ma100>ma50))||((ma30>ma100)&&(ma100>ma50))||((ma50>ma100)&&(ma100>ma30))||((ma50>ma30)&&(ma30>ma100))||((ma50>ma30)&&(ma30>ma100))||((ma50>ma100)&&(ma100>ma30))||((ma100>ma30)&&(ma30>ma50))||((ma100>ma30)&&(ma30>ma50)))
if((ma30<ma50)&&(ma50<ma100))
{
if((Close[0]<ma)&&(Close[1]>map))//价格下穿均线
{
if(danshu()==0)
{
sell(Lots,0,ying,Symbol()+"sell"+Lots,0);
}
}
}
if(danshu()>0)
{
if(buylastprice()>0)
{
if((buylastprice()-Bid)>=(ying*Point))
{
buy(getbuylastLots()*2,0,ying,Symbol()+"buy"+getbuylastLots()*2,0);
}
}
if(selllastprice()>0)
{
if((Bid-selllastprice())>=(ying*Point))
{
sell(getselllastLots()*2,0,ying,Symbol()+"sell"+getselllastLots()*2,0);
}
}
double buylastTP=getbuylastTP();
double selllastTP=getselllastTP();
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(buylastTP>0)
{
if(OrderTakeProfit()!=buylastTP)
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),buylastTP,0);
}
}
}
if(OrderType()==OP_SELL)
{
if(selllastTP>0)
{
if(OrderTakeProfit()!=selllastTP)
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),selllastTP,0);
}
}
}
}
}
}
}
return(0);
}
double getbuylastTP()
{
if(buylastticket()!=0)
{
if(OrderSelect(buylastticket(),SELECT_BY_TICKET,MODE_TRADES)==true)
{
return(OrderTakeProfit());
}
else
{
return(0);
}
}
else
{
return(0);
}
}
double getbuylastLots()
{
if(buylastticket()!=0)
{
if(OrderSelect(buylastticket(),SELECT_BY_TICKET,MODE_TRADES)==true)
{
return(OrderLots());
}
else
{
return(0);
}
}
else
{
return(0);
}
}
double getselllastTP()
{
if(selllastticket()!=0)
{
if(OrderSelect(selllastticket(),SELECT_BY_TICKET,MODE_TRADES)==true)
{
return(OrderTakeProfit());
}
else
{
return(0);
}
}
else
{
return(0);
}
}
double getselllastLots()
{
if(selllastticket()!=0)
{
if(OrderSelect(selllastticket(),SELECT_BY_TICKET,MODE_TRADES)==true)
{
return(OrderLots());
}
else
{
return(0);
}
}
else
{
return(0);
}
}
int buylastticket()
{
int maxticket=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(maxticket<OrderTicket())
{
maxticket=OrderTicket();
}
}
}
}
}
return(maxticket);
}
double buylastprice()
{
if(buylastticket()!=0)
{
if(OrderSelect(buylastticket(),SELECT_BY_TICKET,MODE_TRADES)==true)
{
return(OrderOpenPrice());
}
else
{
return(0);
}
}
else
{
return(0);
}
}
int selllastticket()
{
int maxticket=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_SELL)
{
if(maxticket<OrderTicket())
{
maxticket=OrderTicket();
}
}
}
}
}
return(maxticket);
}
double selllastprice()
{
if(selllastticket()!=0)
{
if(OrderSelect(selllastticket(),SELECT_BY_TICKET,MODE_TRADES)==true)
{
return(OrderOpenPrice());
}
else
{
return(0);
}
}
else
{
return(0);
}
}
int danshu()
{
int a=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
a=a+1;
}
}
}
return(a);
}
int buy(double Lots,double sun,double ying,string comment,int magic)
{
int kaiguan=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if((OrderComment()==comment)&&(OrderMagicNumber()==magic))
{
kaiguan=1;
}
}
}
if(kaiguan==0)
{
int ticket=OrderSend(Symbol( ) ,OP_BUY,Lots,Ask,300,0,0,comment,magic,0,White);
if(ticket>0)
{
if(OrderSelect(ticket, SELECT_BY_TICKET)==true)
{
if((sun!=0)&&(ying!=0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-sun*MarketInfo(Symbol(),MODE_POINT),OrderOpenPrice()+ying*MarketInfo(Symbol(),MODE_POINT),0,Red);
}
if((sun==0)&&(ying!=0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()+ying*MarketInfo(Symbol(),MODE_POINT),0,Red);
}
if((sun!=0)&&(ying==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-sun*MarketInfo(Symbol(),MODE_POINT),0,0,Red);
}
}
}
return(ticket);
}
else
{
return(0);
}
}
int sell(double Lots,double sun,double ying,string comment,int magic)
{
int kaiguan=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if((OrderComment()==comment)&&(OrderMagicNumber()==magic))
{
kaiguan=1;
}
}
}
if(kaiguan==0)
{
int ticket=OrderSend(Symbol( ) ,OP_SELL,Lots,Bid,300,0,0,comment,magic,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket, SELECT_BY_TICKET)==true)
{
if((sun!=0)&&(ying!=0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+sun*MarketInfo(Symbol(),MODE_POINT),OrderOpenPrice()-ying*MarketInfo(Symbol(),MODE_POINT),0,Red);
}
if((sun==0)&&(ying!=0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()-ying*MarketInfo(Symbol(),MODE_POINT),0,Red);
}
if((sun!=0)&&(ying==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+sun*MarketInfo(Symbol(),MODE_POINT),0,0,Red);
}
}
}
return(ticket);
}
else
{
return(0);
}
} |
|