|
刚搞出来
macd自带的ea中文版
- input double 止盈 =50;
- input double 手数 =0.1;
- input double 移动止损 =30;
- input double 上水平线 =3;
- input double 下水平线=2;
- input int 均线周期 =26;
- void OnTick(void)
- {
- double 当前MACD值,前一根MACD值;
- double 当前信号线值,前一根信线值;
- double 当前均线值,前一根均线值;
- int 整数一,订单号,订单总数;
- if(Bars<100)
- {
- Print("bars less than 100");
- return;
- }
- if(止盈<10)
- {
- Print("止盈 less than 10");
- return;
- }
- 当前MACD值=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
- 前一根MACD值=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
- 当前信号线值=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
- 前一根信线值=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
- 当前均线值=iMA(NULL,0,均线周期,0,MODE_EMA,PRICE_CLOSE,0);
- 前一根均线值=iMA(NULL,0,均线周期,0,MODE_EMA,PRICE_CLOSE,1);
- 订单总数=OrdersTotal();
- if(订单总数<1)
- {
- if(AccountFreeMargin()<(1000*手数))
- {
- Print("We have no money. Free Margin = ",AccountFreeMargin());
- return;
- }
- if(当前MACD值<0 && 当前MACD值>当前信号线值 && 前一根MACD值<前一根信线值 &&
- MathAbs(当前MACD值)>(上水平线*Point) && 当前均线值>前一根均线值)
- {
- 订单号=OrderSend(Symbol(),OP_BUY,手数,Ask,3,0,Ask+止盈*Point,"macd sample",16384,0,Green);
- if(订单号>0)
- {
- if(OrderSelect(订单号,SELECT_BY_TICKET,MODE_TRADES))
- Print("BUY order opened : ",OrderOpenPrice());
- }
- else
- Print("Error opening BUY order : ",GetLastError());
- return;
- }
- if(当前MACD值>0 && 当前MACD值<当前信号线值 && 前一根MACD值>前一根信线值 &&
- 当前MACD值>(上水平线*Point) && 当前均线值<前一根均线值)
- {
- 订单号=OrderSend(Symbol(),OP_SELL,手数,Bid,3,0,Bid-止盈*Point,"macd sample",16384,0,Red);
- if(订单号>0)
- {
- if(OrderSelect(订单号,SELECT_BY_TICKET,MODE_TRADES))
- Print("SELL order opened : ",OrderOpenPrice());
- }
- else
- Print("Error opening SELL order : ",GetLastError());
- }
- return;
- }
- for(整数一=0;整数一<订单总数;整数一++)
- {
- if(!OrderSelect(整数一,SELECT_BY_POS,MODE_TRADES))
- continue;
- if(OrderType()<=OP_SELL && // check for opened position
- OrderSymbol()==Symbol()) // check for symbol
- {
- if(OrderType()==OP_BUY)
- {
- if(当前MACD值>0 && 当前MACD值<当前信号线值 && 前一根MACD值>前一根信线值 &&
- 当前MACD值>(下水平线*Point))
- {
- if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet))
- Print("OrderClose error ",GetLastError());
- return;
- }
- if(移动止损>0)
- {
- if(Bid-OrderOpenPrice()>Point*移动止损)
- {
- if(OrderStopLoss()<Bid-Point*移动止损)
- {
- if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*移动止损,OrderTakeProfit(),0,Green))
- Print("OrderModify error ",GetLastError());
- return;
- }
- }
- }
- }
- else // go to short position
- {
- if(当前MACD值<0 && 当前MACD值>当前信号线值 &&
- 前一根MACD值<前一根信线值 && MathAbs(当前MACD值)>(下水平线*Point))
- {
- if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet))
- Print("OrderClose error ",GetLastError());
- return;
- }
- if(移动止损>0)
- {
- if((OrderOpenPrice()-Ask)>(Point*移动止损))
- {
- if((OrderStopLoss()>(Ask+Point*移动止损)) || (OrderStopLoss()==0))
- {
- if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*移动止损,OrderTakeProfit(),0,Red))
- Print("OrderModify error ",GetLastError());
- return;
- }
- }
- }
- }
- }
- }
- }
复制代码 |
|