正确执行 MQL4 EA 因为我在 multicharts(EasyLanguage) 中执行了相同的策略,任何人都可以帮助我

问题描述

我是元交易者的新手,因此尝试在 MQL4 上创建一个相当简单的智能交易系统,但即使在编译后没有任何错误,它也无法执行。实际上,我通过其中一个简单的英文代码执行了这段代码,它在简单的语言多图表中完美运行,但是这里的很多语法让我感到困惑,无法编写这样的代码,抱歉并帮助我 概念如下:

bool CanTrade = true;
bool TradingIsAllowed=false;
bool shorting = false;
bool longing = false;

double CurrentAveTrueRange = iATR(_Symbol,_Period,14,0);
double OLDAveTrueRange = iATR(_Symbol,5);
double OpenP = iOpen(Symbol(),PERIOD_D1,0);
input string StartTradingTime="08:30";
input string StopTradingTime="15:15";
double TakeProfit = OrderTakeProfit();
input int   InpStopLosspoints    =  0;


string ESTNowStr;
string ESTNow;
datetime time;

string fullDate;
string fullTime;
double ClosePrice;
double OrdCls;
int gBuyTicket = 0;
int gSellTicket = 0;

double Stop_Loss_Points = OrderStopLoss();
double RSI5  = irsI(_Symbol,PERIOD_M5,PRICE_CLOSE,5);
double CloSEOfCurrentDay  = iClose(Symbol(),0);
double CloSEOfYesterday  = iClose(Symbol(),1);
double CloSEOfdayBYesterDay  = iClose(Symbol(),2);
double   stopLossprice;

void OnTick()
  {


  
   if(CheckTradingTime()== true)
     {
      SetStoploss();
      
      if(fullDate >= "2014.01.07" && VolatilityFilter()== true)
        {



         if(fullTime == "08:40")
           {
           
            
  
            if((Low[1] > OpenP && RSI5 < 50)|| ((Close[0]>Close[1]&&Close[0]>Close[1])&&(CloSEOfCurrentDay< CloSEOfdayBYesterDay)))
              {

               longing = false;
               shorting = true;
           
         
             OrderSend(Symbol(),OP_BUY,0.10,Ask,3,Stop_Loss_Points,Ask+TakeProfit*_Point,NULL,Green);
     
              }
            if((High[1] < OpenP && RSI5 > 50)|| ((Close[0]<Close[1]&&Close[0]<Close[1])&&(CloSEOfCurrentDay>CloSEOfdayBYesterDay)))
              {
               longing = true;
               shorting = false;
             
              if(OrdersTotal()==0) {
       
             OrderSend(Symbol(),Green);
              }
              else{
         
             OrderSend(Symbol(),OP_SELL,Bid,Bid-TakeProfit*_Point,Red);
              }
             
              }

           }
         if(fullTime == "11:00" && shorting == true && TakeProfit > 0)
           {
           
            RefreshRates();
            if(OrderType()==OP_BUY)
               ClosePrice=normalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),Digits);
            if(OrderType()==OP_SELL)
               ClosePrice=normalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),Digits);
           }


        }
      else
        {
         CloSEOpenorders();
         StopTrading();
       
        }

     }//CheckTradingTime


  }

//|                                                                  |
//+------------------------------------------------------------------+
void SetStoploss()
  {
   datetime checkTime   =  TimeCurrent()-30;

   int      cnt         =  OrdersTotal();
   for(int i=cnt-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TradES))
        {
         if(OrderMagicNumber()==0 && OrderStopLoss()==0
            &&(OrderType()==ORDER_TYPE_BUY || OrderType()==ORDER_TYPE_SELL))
           {
            // magic 0 = manual entry,sl 0 means not set
            if(OrderOpenTime()> checkTime)                       // lets you override after 30 seconds
              {
               double   stopLoss       =  InpStopLosspoints*SymbolInfodouble(OrderSymbol(),SYMBOL_POINT);
               stopLossprice  = (OrderType()==ORDER_TYPE_BUY) ?
                                OrderOpenPrice()-stopLoss :
                                OrderOpenPrice()+stopLoss;
               stopLossprice           =  normalizeDouble(stopLossprice,(int)SymbolInfoInteger(OrderSymbol(),SYMBOL_DIGITS));
               if(OrderModify(OrderTicket(),OrderOpenPrice(),stopLossprice,OrderTakeProfit(),OrderExpiration())) {}
              }
           }
        }
     }

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool VolatilityFilter()
  {

   double rangetoday = iHigh(NULL,0) - iLow(NULL,0);
   double AveTrueRange = iHigh(NULL,5) - iLow(NULL,5);
//Comment ("rangetoday",rangetoday,"\n","OLDAveTrueRange",OLDAveTrueRange,"CurrentAveTrueRange",CurrentAveTrueRange);

   if(rangetoday > OLDAveTrueRange)
     {
      CanTrade = true;
     }
   else
     {
      CanTrade = true;
     }

   return CanTrade;

  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool CheckTradingTime()
  {

   time = TimeLocal();
   fullTime = TimetoString(time,TIME_MINUTES);
   fullDate = TimetoString(time,TIME_DATE);



   if(StringSubstr(fullTime,5)>=StartTradingTime)
      TradingIsAllowed=true;

   if(StringSubstr(fullTime,5)>=StopTradingTime)
      TradingIsAllowed=false;

   return TradingIsAllowed;

  }

/* bool CheckTradingTime()
 {
    time = TimeCurrent();
     //CSET -1
   int TimetoAdd= 1;
   datetime estTime = TimeCurrent() + TimetoAdd;
   fullTime = TimetoString(estTime,TIME_MINUTES);
   fullDate = TimetoString(estTime,TIME_DATE);

   ESTNowStr = TimetoString(estTime,TIME_DATE|TIME_MINUTES);
   //Comment("ESTNowStr =",ESTNowStr);
   int hour = TimeHour(estTime);
   int minutes = TimeMinute(estTime);


   if(hour == 08 && minutes > 30)
   TradingIsAllowed=true;

   if(hour == 15 && minutes > 15)
   TradingIsAllowed=false;

  return TradingIsAllowed;

}*/

//+------------------------------------------------------------------+
//| Close the latest order for this current symbol                   |
//+------------------------------------------------------------------+
void CloseCurrentTrade()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(!OrderSelect(i,MODE_TradES))
         continue;
      if(OrderSymbol()!=Symbol())
         continue;

      if(OrderType()>OP_SELL)
         continue;

      if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),50))
         Print("Error in Closing the Order,Error : ",GetLastError());

      break; // assuming you want to close the latest Trade only,exit the order closing loop
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CloSEOpenorders()
  {

   int TotalClose=0;  // We want to count how many orders have been closed.


// We scan all the orders backwards.
// This is required as if we start from the first order,we will have problems with the counters and the loop.
   for(int i=OrdersTotal()-1; i>=0; i--)
     {

      // We select the order of index i,selecting by position and from the pool of market/pending Trades.
      // If the selection is successful we try to close the order.
      if(OrderSelect(i,MODE_TradES))
        {

         // We define the close price,which depends on the type of order.
         // We retrieve the price for the instrument of the order using MarketInfo(OrderSymbol(),MODE_BID) or MODE_ASK.
         // And we normalize the price found.

         RefreshRates();
         if(OrderType()==OP_BUY)
            ClosePrice=normalizeDouble(MarketInfo(OrderSymbol(),Digits);
         if(OrderType()==OP_SELL)
            ClosePrice=normalizeDouble(MarketInfo(OrderSymbol(),Digits);

         // If the order is closed correctly,we increment the counter of closed orders.
         // If the order fails to be closed,we print the error.
         if(OrderClose(OrderTicket(),ClosePrice,5,CLR_NONE))
           {
            TotalClose++;
           }
         else
           {
            Print("Order Failed to close with error - ",GetLastError());
           }
        }
      // If the OrderSelect() fails,we return the cause.
      else
        {
         Print("Failed to select the order - ",GetLastError());
        }

      // We can use a delay if the execution is too fast.
      // Sleep() will wait X milliseconds before proceeding with the code.
      // Sleep(300);
     }
// If the loop finishes,it means there are no more open orders for the Trading account.
   return(TotalClose);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void StopTrading()
  {

   for(int fmd=OrdersTotal()-1; fmd>=0; fmd--)
     {
      if(OrderSelect(fmd,MODE_TradES))
        {
         if(OrderType()==OP_BUY || OrderType()==OP_SELL)
           {
            OrdCls=OrderClose(OrderTicket(),5);
            break;   //stop Trading untill...

           }
        }
     }

  }
//+------------------------------------------------------------------+
void SetStopLoss1()
  {
   if(fullDate >= "2014.01.07" && fullDate < "2015.01.07")
     {
      Stop_Loss_Points = 400;
     }
   else
      if(fullDate >= "2015.01.07" && fullDate < "2016.01.07")
        {
         Stop_Loss_Points = 400;
        }
      else
         if(fullDate >= "2016.01.07" && fullDate < "2017.01.06")
           {
            Stop_Loss_Points = 350;
           }
         else
            if(fullDate >= "2017.01.06"&& fullDate < "2018.01.08")
              {
               Stop_Loss_Points = 350;
              }
            else
               if(fullDate >= "2018.01.08"&& fullDate < "2019.01.09")
                 {
                  Stop_Loss_Points = 400;
                 }
               else
                  if(fullDate >= "2019.01.09" && fullDate < "2020.01.09")
                    {
                     Stop_Loss_Points = 400;
                    }
                  else
                     if(fullDate >= "2020.01.09" && fullDate < "2021.03.09")
                       {
                        Stop_Loss_Points = 250;
                       }

  }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)