你看看是不是这样子加法的?
#property copyright "三步曲之一"
#property link "三步曲之一"
/*
*/
extern int 魔术号=8881;
enum 做单方向
{
多空都开=0, 开多=1,开空=2,
};
extern 做单方向 开仓方向=0;
extern int 建仓时段=30;
extern int 建仓MACD快EMA=34;
extern int 建仓MACD慢EMA=55;
extern int 建仓MACDSMA=13;
extern int 趋势时段=240;
extern int 趋势时段短均线=5;
extern int 趋势时段长均线=34;
extern int 趋势MACD快EMA=34;
extern int 趋势MACD慢EMA=55;
extern int 趋势MACDSMA=13;
extern double 当获利X点时就平仓一半=350;
extern bool 是否启用平仓一半=true;
extern double 止损点数=500;
extern double 止盈点数=9900;
extern double 滑点=50;
extern double 下单量=0.1;
extern bool 是否启用追踪止损=true;
extern double 追踪止损点数=750;
string 注释="三步曲之一";
int sj;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int Ticket = -1;
if(开多()&&sj!=iTime(NULL,建仓时段,0)&&(开仓方向==0||开仓方向==1)&&IsNewTFbar30())
{ Ticket=OrderSend(Symbol(),OP_BUY,下单量,Ask,滑点,Ask-止损点数*Point,Ask+止盈点数*Point,注释,魔术号,0,Red);
}
if(开空()&&sj!=iTime(NULL,建仓时段,0)&&(开仓方向==0||开仓方向==2)&&IsNewTFbar30())
{ Ticket=OrderSend(Symbol(),OP_SELL,下单量,Bid,滑点,Bid+止损点数*Point,Bid-止盈点数*Point,注释,魔术号,0,Blue);
}
if(是否启用追踪止损)移动止损();
if(是否启用平仓一半)平仓一半();
return(0);
}
//+------------------------------------------------------------------+
bool IsNewTFbar30()
{
static datetime t=0;
if(t!=iTime(NULL,30,0))
{
t=iTime(NULL,30,0);
return(true);
}
return (false);
}
bool 开多()
{
double H4JX51=iMA(NULL,趋势时段,趋势时段短均线,0,MODE_SMMA,PRICE_CLOSE,1);
double H4JX191=iMA(NULL,趋势时段,趋势时段长均线,0,MODE_SMMA,PRICE_CLOSE,1);
double Mzhu1=iMACD(NULL,建仓时段,建仓MACD快EMA,建仓MACD慢EMA,建仓MACDSMA,PRICE_CLOSE,MODE_MAIN,1);
double Mzhu2=iMACD(NULL,建仓时段,建仓MACD快EMA,建仓MACD慢EMA,建仓MACDSMA,PRICE_CLOSE,MODE_MAIN,2);
double Mxian1=iMACD(NULL,建仓时段,建仓MACD快EMA,建仓MACD慢EMA,建仓MACDSMA,PRICE_CLOSE,MODE_SIGNAL,1);
double Mxian2=iMACD(NULL,建仓时段,建仓MACD快EMA,建仓MACD慢EMA,建仓MACDSMA,PRICE_CLOSE,MODE_SIGNAL,2);
double H4Mzhu1=iMACD(NULL,趋势时段,趋势MACD快EMA,趋势MACD慢EMA,趋势MACDSMA,PRICE_CLOSE,MODE_MAIN,1);
double H4Mzhu2=iMACD(NULL,趋势时段,趋势MACD快EMA,趋势MACD慢EMA,趋势MACDSMA,PRICE_CLOSE,MODE_MAIN,2);
double H4Mxian1=iMACD(NULL,趋势时段,趋势MACD快EMA,趋势MACD慢EMA,趋势MACDSMA,PRICE_CLOSE,MODE_SIGNAL,1);
double H4Mxian2=iMACD(NULL,趋势时段,趋势MACD快EMA,趋势MACD慢EMA,趋势MACDSMA,PRICE_CLOSE,MODE_SIGNAL,2);
if( H4JX51>H4JX191&& Mzhu1>Mxian1&&Mzhu2
H4Mxian1)return(true);//
else return(false);
}
bool 开空()
{
double H4JX51=iMA(NULL,趋势时段,趋势时段短均线,0,MODE_SMMA,PRICE_CLOSE,1);
double H4JX191=iMA(NULL,趋势时段,趋势时段长均线,0,MODE_SMMA,PRICE_CLOSE,1);
double Mzhu1=iMACD(NULL,建仓时段,建仓MACD快EMA,建仓MACD慢EMA,建仓MACDSMA,PRICE_CLOSE,MODE_MAIN,1);
double Mzhu2=iMACD(NULL,建仓时段,建仓MACD快EMA,建仓MACD慢EMA,建仓MACDSMA,PRICE_CLOSE,MODE_MAIN,2);
double Mxian1=iMACD(NULL,建仓时段,建仓MACD快EMA,建仓MACD慢EMA,建仓MACDSMA,PRICE_CLOSE,MODE_SIGNAL,1);
double Mxian2=iMACD(NULL,建仓时段,建仓MACD快EMA,建仓MACD慢EMA,建仓MACDSMA,PRICE_CLOSE,MODE_SIGNAL,2);
double H4Mzhu1=iMACD(NULL,趋势时段,趋势MACD快EMA,趋势MACD慢EMA,趋势MACDSMA,PRICE_CLOSE,MODE_MAIN,1);
double H4Mzhu2=iMACD(NULL,趋势时段,趋势MACD快EMA,趋势MACD慢EMA,趋势MACDSMA,PRICE_CLOSE,MODE_MAIN,2);
double H4Mxian1=iMACD(NULL,趋势时段,趋势MACD快EMA,趋势MACD慢EMA,趋势MACDSMA,PRICE_CLOSE,MODE_SIGNAL,1);
double H4Mxian2=iMACD(NULL,趋势时段,趋势MACD快EMA,趋势MACD慢EMA,趋势MACDSMA,PRICE_CLOSE,MODE_SIGNAL,2);
if( H4JX51Mxian2&&H4Mzhu1=0;i--)
{
if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==魔术号)
{k++;}
}
} return(k);
}
void 平买仓()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if(OrderSymbol()==Symbol()&&OrderType()==OP_BUY&&OrderMagicNumber()==魔术号){
bool result = false;
result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 30, Red );
if(result) Print(Symbol()+"平多单成功!!");
if(result == false)
{
Print("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
}
}}}
}
void 平卖仓()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if(OrderSymbol()==Symbol()&&OrderType()==OP_SELL&&OrderMagicNumber()==魔术号){
bool result = false;
result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 30, Red );
if(result) Print(Symbol()+"平空单成功!!");
if(result == false)
{
Print("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
}
}}}
}
void 移动止损()
{
for (int cnt=0;cnt=OrderOpenPrice())
{
if (Bid-OrderStopLoss()>Point*追踪止损点数||OrderStopLoss()==0)
{
bool chenggong= OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*追踪止损点数,OrderTakeProfit(),0,CLR_NONE);
if (chenggong)Print("单号:"+OrderTicket()+"移动止损成功");
}}
}
if (OrderType()==OP_SELL)
{
if(Ask<=OrderOpenPrice())
{
if (OrderStopLoss()-Ask>Point*追踪止损点数||OrderStopLoss()==0){
chenggong= OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*追踪止损点数,OrderTakeProfit(),0,CLR_NONE);
if (chenggong)Print("单号:"+OrderTicket()+"移动止损成功");
}}}
}
}
}
}
void 平仓一半()
{
for (int i=0;i=当获利X点时就平仓一半 && OrderMagicNumber()==魔术号 && StringFind(OrderComment(),"from")==-1)
{
if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots()/2,Bid,滑点);
if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots()/2,Ask,滑点);
}
}
}
}