5分钟动量系统.mq4 #property version "1.00"#property strict#define MAGICMA 2016817//--- input parametersinput double Maximum_riske=0.01;//资金最大风险系数input int MovingPeriod=21;input int ENEPeriod=55;input double ENEdeviation=0.03;//ENE偏值input int Maximum_TP=5000;//最大止损点数input int TimeFame_2=15;input int L_ma1=2000;//离均线差值 bool woke=true;//允许运行 //+------------------------------------------------------------------+//|Caculate open positions //检查开仓是否 |//+------------------------------------------------------------------+int CalculateCurrentOrders(string symbol)//计算当前持仓数量函数 { int buys=0,sells=0;//定义两个临时变量//--- for(int i=0;i0) return(buys); //如果买>0,则返回值为(buys) else return(-sells);//否则为带符号的sells个数值 本函数返回查询计算结束时的持仓单的个数。 } //+------------------------------------------------------------------+//| Check for open order conditions //检查开仓条件。 |//+------------------------------------------------------------------+void CheckForOpen() {double One_lot=MarketInfo(Symbol(),MODE_MARGINMAINTENANCE);//一标准手手需要的保证金。 double lot =NormalizeDouble(AccountFreeMargin()*Maximum_riske/One_lot,2);//开仓数量。 //--------------------------------------------------------------------------------- // 根据最大风险比例计算的开仓手数 //------------------------------------------------------------------------------ double ma1,ene1_up,ene1_dn,macd,ma2,ene2_dn,ene2_up,Osma2; double bid=MarketInfo(Symbol(),MODE_BID);//市场实时价格 Comment("bid",MarketInfo(Symbol(),MODE_BID)); double vspread = MarketInfo(Symbol(),MODE_SPREAD); Print("vspred",MarketInfo(Symbol(),MODE_SPREAD));//市场点差 double Vpoint = MarketInfo(Symbol(),MODE_POINT);//市场最小波动单位 Print("Vpoint",MarketInfo(Symbol(),MODE_POINT)); double res; ma1=iMA(NULL,0,MovingPeriod,0,MODE_EMA,PRICE_CLOSE,1);//前次EMA21定义 ene1_up=iEnvelopes( NULL, 0, ENEPeriod , MODE_EMA, 0,PRICE_CLOSE, ENEdeviation, MODE_UPPER,1) ;//前次ENE上轨定义; ene1_dn=iEnvelopes( NULL, 0, ENEPeriod , MODE_EMA, 0,PRICE_CLOSE, ENEdeviation, MODE_LOWER, 1) ;//前次ENE下轨定义 ma2=iMA(NULL,0,MovingPeriod,0,MODE_EMA,PRICE_CLOSE,0);//当前EMA21定义 macd=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1); ene2_up=iEnvelopes( NULL, 0, ENEPeriod , MODE_EMA, 0,PRICE_CLOSE, ENEdeviation, MODE_UPPER,0) ;//当次ENE上轨定义 ene2_dn=iEnvelopes( NULL, 0, ENEPeriod , MODE_EMA, 0,PRICE_CLOSE, ENEdeviation, MODE_LOWER, 0) ;//当次ENE下轨定义 Osma2=iOsMA(NULL,TimeFame_2,12,26,9,PRICE_CLOSE,1); double stoploss_s=NormalizeDouble(ma1-bid+(vspread+L_ma1)*Vpoint,Digits); double stoploss_b=NormalizeDouble(bid-ma1+(vspread+L_ma1)*Vpoint,Digits); Print("最大止损点数"==NormalizeDouble(Maximum_TP*Point,Digits)); //------------------------------------------------------------------------------- //以上全是定义函数 //------------------------------------------------------------------------------- //--- sell conditions//做空条件。 if(ma1ene1_up&&macd>0&&Bid>ma2>ene2_up&& stoploss_b0) { res=OrderSend(Symbol(),OP_BUY,lot,Ask,50000,Bid-L_ma1*Point,0,"",MAGICMA,0,Blue); Print("下多单",OrderSend(Symbol(),OP_BUY,lot,Ask,50,stoploss_b,0,"0",MAGICMA,0,Blue)); return; } } //+-------------------------------------------------------------------+//|Check for close oder conditions.//检查平单条件。 |//+--------------------------------------------------------------------+void CheckForClose() {double v1spread = MarketInfo(Symbol(),MODE_SPREAD); //市场点差 double V1point = MarketInfo(Symbol(),MODE_POINT);//市场最小波动单位 double ma2=iMA(NULL,0,MovingPeriod,0,MODE_EMA,PRICE_CLOSE,0);//当前EMA21定义 double bid=MarketInfo(Symbol(),MODE_BID);//市场实时价格 double Vpoint = MarketInfo(Symbol(),MODE_POINT);//市场最小波动单位 double ma1=iMA(NULL,0,MovingPeriod,0,MODE_EMA,PRICE_CLOSE,1);//前次EMA21定义 for(int i=0;i=0.5*tl) if (OrderClose(OrderTicket(),NormalizeDouble(0.5*lots,2),Bid,5,White) ) continue; for(i = 0; i ma1) {if(OrderModify(OrderTicket(),0.5*lots,ma2-L_ma1*Vpoint ,OrderTakeProfit(),Orchid)==true) continue; } } } } return; } } for(int i=0;ima2+L_ma1||ma2<ma1) {if(OrderModify(OrderTicket(),0.5*lot,ma2-L_ma1*Vpoint ,OrderTakeProfit(),Orchid)==true) continue; } } } } return; } } } //+-----------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+void OnTick() {//--- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return;//--- calculate open orders by current symbol if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else CheckForClose(); }
|