Expert Advisors: 2MA Bunny Cross Expert - Seite 2

 

hmm, und ich habe Kompilierungsfehler init schlägt in den Zeilen 281 und 287 fehl. Und als Folge davon kann ich nichts ausführen=(

 
Александр Князев:

hmm, und ich habe Kompilierungsfehler init schlägt in den Zeilen 281 und 287 fehl. Und als Folge davon kann ich nichts ausführen=(

Achten Sie genau darauf, WAS und WO Sie herunterladen. Im Moment habe ich die Version 1.003 vom russischen Teil von KodoBase heruntergeladen und sie kompiliert ohne Fehler.

 

cảm ơn bạn về code

nhưng nó không hoạt động

khi nén lại n ó báo lỗi

bạn có thể chỉ tôi cách khắc phục không ?

xin cảm ơn.


 
Le Nam :

cảm ơn bạn về code.

nhưng nó không hoạt động

khi nén lại n ó báo lỗi

bạn có thể chỉ tôi cách khắc phục không ?

xin cảm ơn.


Version 1.003 ist über das russische Forum erhältlich: https: //www.mql5.com/ru/code/16783

 

Hallo,

Vielen Dank für Ihre ea, ich modifiziert es, um die MA-Perioden zu ändern, ist es gut profitabel.

Unten der geänderte Code

//+------------------------------------------------------------------+
//| 2MA Bunny Cross Expert(barabashkakvn's edition).mq5 |
//|Urheberrecht © Ron Thompson |
//|http://www.lightpatch.com/forex/ |
//+------------------------------------------------------------------+
#property copyright "Ron Thompson"
#property link      "http://www.lightpatch.com/forex"
#property version   "1.003"
//---
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>  
#include <Trade\AccountInfo.mqh>
#include <Expert\Money\MoneyFixedMargin.mqh>
CPositionInfo  m_position;                   // Handelsposition Objekt
CTrade         m_trade;                      // Handelsobjekt
CSymbolInfo    m_symbol;                     // Symbol-Info-Objekt
CAccountInfo   m_account;                    // Kontoinfo-Verpackung
CMoneyFixedMargin *m_money;
//--- Eingabeparameter
input double   InpLots     = 0;              // Lose (oder "Lose">0 und "Risiko"==0 oder "Lose"==0 und "Risiko">0)
input double   Risk        = 5;              // Risiko (oder "Lose">0 und "Risiko"==0 oder "Lose"==0 und "Risiko">0)
input int PeriodMAS=20;                      // Period of the fast MA
input int PeriodMAF=5;                       


input ulong    m_magic=319906800;      // magische Zahl
//---
ulong          m_slippage=10;                // Schlupf
int    handle_iMA_5;                         // Variable zum Speichern des Handles des iMA-Indikators 
int    handle_iMA_20;                        // Variable zum Speichern des Handles des iMA-Indikators 
//+------------------------------------------------------------------+
//| Experten-Initialisierungsfunktion|
//+------------------------------------------------------------------+
int OnInit()
  {
   if(!m_symbol.Name(Symbol())) // setzt den Symbolnamen
      return(INIT_FAILED);
   RefreshRates();
//---
   m_trade.SetExpertMagicNumber(m_magic);
   m_trade.SetMarginMode();
   m_trade.SetTypeFillingBySymbol(m_symbol.Name());
   m_trade.SetDeviationInPoints(m_slippage);
//--- Abstimmung für 3 oder 5 Ziffern
   int digits_adjust=1;
   if(m_symbol.Digits()==3 || m_symbol.Digits()==5)
      digits_adjust=10;
//---
   if(!LotsOrRisk(InpLots,Risk,digits_adjust))
      return(INIT_PARAMETERS_INCORRECT);
//---
   if(m_money!=NULL)
      delete m_money;
   m_money=new CMoneyFixedMargin;
   if(m_money!=NULL)
     {
      if(!m_money.Init(GetPointer(m_symbol),Period(),m_symbol.Point()*digits_adjust))
         return(INIT_FAILED);
      m_money.Percent(Risk);
     }
   else
     {
      Print(__FUNCTION__,", ERROR: Object CMoneyFixedMargin is NULL");
      return(INIT_FAILED);
     }
//--- Handle des Indikators iMA erstellen
   handle_iMA_5=iMA(m_symbol.Name(),Period(),PeriodMAF,0,MODE_SMA,PRICE_WEIGHTED);
//--- wenn der Handle nicht erstellt wird 
   if(handle_iMA_5==INVALID_HANDLE)
     {
      //--- über den Fehler informieren und den Fehlercode ausgeben 
      PrintFormat("Failed to create handle of the iMA indicator for the symbol %s/%s, error code %d",
                  m_symbol.Name(),
                  EnumToString(Period()),
                  GetLastError());
      //--- der Indikator wird vorzeitig gestoppt 
      return(INIT_FAILED);
     }
//--- Handle des Indikators iMA erstellen
   handle_iMA_20=iMA(m_symbol.Name(),Period(),PeriodMAS,3,MODE_SMA,PRICE_WEIGHTED);
//--- wenn der Handle nicht erstellt wird 
   if(handle_iMA_20==INVALID_HANDLE)
     {
      //--- über den Fehler informieren und den Fehlercode ausgeben 
      PrintFormat("Failed to create handle of the iMA indicator for the symbol %s/%s, error code %d",
                  m_symbol.Name(),
                  EnumToString(Period()),
                  GetLastError());
      //--- der Indikator wird vorzeitig gestoppt 
      return(INIT_FAILED);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Experten-Deinitialisierungsfunktion|
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   if(m_money!=NULL)
      delete m_money;
  }
//+------------------------------------------------------------------+
//| Experten-Tick-Funktion|
//+------------------------------------------------------------------+
void OnTick()
  {
//--- wir arbeiten nur zum Zeitpunkt der Geburt eines neuen Balkens
   static datetime PrevBars=0;
   datetime time_0=iTime(m_symbol.Name(),Period(),0);
   if(time_0==PrevBars)
      return;
   PrevBars=time_0;
//---

   double ArrayMA5[];
   ArraySetAsSeries(ArrayMA5,true);
   double ArrayMA20[];
   ArraySetAsSeries(ArrayMA20,true);
   if(!iMAGetArray(handle_iMA_5,0,3,ArrayMA5) || !iMAGetArray(handle_iMA_20,0,3,ArrayMA20) || !RefreshRates())
     {
      PrevBars=0;
      return;
     }
//---
   bool signal_buy=(ArrayMA5[2]<ArrayMA20[2] && ArrayMA5[1]>ArrayMA20[1]);
   bool signal_sell=(ArrayMA5[2]>ArrayMA20[2] && ArrayMA5[1]<ArrayMA20[1]);
//---
   if(signal_buy)
     {
      ClosePositions(POSITION_TYPE_SELL);
      OpenBuy(0.0,0.0);
     }
   if(signal_sell)
     {
      ClosePositions(POSITION_TYPE_BUY);
      OpenSell(0.0,0.0);
     }
//---

  }
//+------------------------------------------------------------------+
//| TradeTransaction-Funktion|
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//---

  }
//+------------------------------------------------------------------+
//| Wert der Puffer für die iMA im Array abrufen |
//+------------------------------------------------------------------+
bool iMAGetArray(const int handle_iMA,const int start_pos,const int count,double &arr_buffer[])
  {
//---
   bool result=true;
   if(!ArrayIsDynamic(arr_buffer))
     {
      Print("This a no dynamic array!");
      return(false);
     }
   ArrayFree(arr_buffer);
   int       buffer_num=0;          // Nummer des Anzeigepuffers 
//--- Fehlercode zurücksetzen 
   ResetLastError();
//--- einen Teil des iMABuffer-Arrays mit Werten aus dem Indikatorpuffer füllen, der den Index 0 hat 
   int copied=CopyBuffer(handle_iMA,buffer_num,start_pos,count,arr_buffer);
   if(copied<0)
     {
      //--- falls das Kopieren fehlschlägt, geben Sie den Fehlercode an 
      PrintFormat("Failed to copy data from the iMA indicator, error code %d",GetLastError());
      //--- Beenden mit Ergebnis Null - das bedeutet, dass der Indikator als nicht berechnet gilt 
      return(false);
     }
   else if(copied<count)
     {
      PrintFormat("Moving Average indicator: %d elements from %d were copied",copied,count);
      DebugBreak();
      return(false);
     }
//---
   return(result);
  }
//+------------------------------------------------------------------+
//| Positionen schließen|
//+------------------------------------------------------------------+
void ClosePositions(const ENUM_POSITION_TYPE pos_type)
  {
   for(int i=PositionsTotal()-1;i>=0;i--) // gibt die Anzahl der aktuellen Positionen zurück
      if(m_position.SelectByIndex(i))     // wählt die Position über den Index aus, um weiteren Zugriff auf ihre Eigenschaften zu erhalten
         if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic)
            if(m_position.PositionType()==pos_type) // ermittelt den Positionstyp
               m_trade.PositionClose(m_position.Ticket()); // Schließen einer Position durch das angegebene Symbol
  }
//+------------------------------------------------------------------+
//| Aktualisiert die Daten der Symbolzitate|
//+------------------------------------------------------------------+
bool RefreshRates(void)
  {
//--- Aktualisierungsraten
   if(!m_symbol.RefreshRates())
     {
      Print("RefreshRates error");
      return(false);
     }
//--- Schutz gegen den Rückgabewert "Null"
   if(m_symbol.Ask()==0 || m_symbol.Bid()==0)
      return(false);
//---
   return(true);
  }
//+------------------------------------------------------------------+
//| Überprüfen Sie die Korrektheit des Positionsvolumens.
//+------------------------------------------------------------------+
bool CheckVolumeValue(double volume,string &error_description)
  {
//--- minimal zulässiges Volumen für Handelsgeschäfte
   double min_volume=m_symbol.LotsMin();
   if(volume<min_volume)
     {
      error_description=StringFormat("Volume is less than the minimal allowed SYMBOL_VOLUME_MIN=%.2f",min_volume);
      return(false);
     }
//--- maximal zulässiges Volumen von Handelsgeschäften
   double max_volume=m_symbol.LotsMax();
   if(volume>max_volume)
     {
      error_description=StringFormat("Volume is greater than the maximal allowed SYMBOL_VOLUME_MAX=%.2f",max_volume);
      return(false);
     }
//--- Minimaler Schritt der Volumenänderung
   double volume_step=m_symbol.LotsStep();
   int ratio=(int)MathRound(volume/volume_step);
   if(MathAbs(ratio*volume_step-volume)>0.0000001)
     {
      error_description=StringFormat("Volume is not a multiple of the minimal step SYMBOL_VOLUME_STEP=%.2f, the closest correct volume is %.2f",
                                     volume_step,ratio*volume_step);
      return(false);
     }
   error_description="Correct volume value";
   return(true);
  }
//+------------------------------------------------------------------+
//| Lots oder Risiko in Prozent für ein Geschäft aus einer freien Marge |
//+------------------------------------------------------------------+
bool LotsOrRisk(const double lots,const double risk,const int digits_adjust)
  {
   if(lots<0.0 && risk<0.0)
     {
      Print(__FUNCTION__,", ERROR: Parameter (\"lots\" or \"risk\") can't be less than zero");
      return(false);
     }
   if(lots==0.0 && risk==0.0)
     {
      Print(__FUNCTION__,", ERROR: Trade is impossible: You have set \"lots\" == 0.0 and \"risk\" == 0.0");
      return(false);
     }
   if(lots>0.0 && risk>0.0)
     {
      Print(__FUNCTION__,", ERROR: Trade is impossible: You have set \"lots\" > 0.0 and \"risk\" > 0.0");
      return(false);
     }
   if(lots>0.0)
     {
      string err_text="";
      if(!CheckVolumeValue(lots,err_text))
        {
         Print(__FUNCTION__,", ERROR: ",err_text);
         return(false);
        }
     }
   else if(risk>0.0)
     {
      if(m_money!=NULL)
         delete m_money;
      m_money=new CMoneyFixedMargin;
      if(m_money!=NULL)
        {
         if(!m_money.Init(GetPointer(m_symbol),Period(),m_symbol.Point()*digits_adjust))
            return(false);
         m_money.Percent(risk);
        }
      else
        {
         Print(__FUNCTION__,", ERROR: Object CMoneyFixedMargin is NULL");
         return(false);
        }
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+
//| Kaufposition eröffnen|
//+------------------------------------------------------------------+
void OpenBuy(double sl,double tp)
  {
   sl=m_symbol.NormalizePrice(sl);
   tp=m_symbol.NormalizePrice(tp);

   double check_open_long_lot=0.0;
   if(Risk>0.0)
     {
      check_open_long_lot=m_money.CheckOpenLong(m_symbol.Ask(),sl);
      Print("sl=",DoubleToString(sl,m_symbol.Digits()),
            ", CheckOpenLong: ",DoubleToString(check_open_long_lot,2),
            ", Balance: ",    DoubleToString(m_account.Balance(),2),
            ", Equity: ",     DoubleToString(m_account.Equity(),2),
            ", FreeMargin: ", DoubleToString(m_account.FreeMargin(),2));
      if(check_open_long_lot==0.0)
        {
         Print(__FUNCTION__,", ERROR: method CheckOpenLong returned the value of \"0.0\"");
         return;
        }
     }
   else
      check_open_long_lot=InpLots;
//--- Volumen vor OrderSend prüfen, um Fehler "nicht genug Geld" zu vermeiden (CTrade)
   double check_volume_lot=m_trade.CheckVolume(m_symbol.Name(),check_open_long_lot,m_symbol.Ask(),ORDER_TYPE_BUY);

   if(check_volume_lot!=0.0)
     {
      if(check_volume_lot>=check_open_long_lot)
        {
         if(m_trade.Buy(check_open_long_lot,NULL,m_symbol.Ask(),sl,tp))
           {
            if(m_trade.ResultDeal()==0)
              {
               Print("#1 Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
                     ", description of result: ",m_trade.ResultRetcodeDescription());
               PrintResult(m_trade,m_symbol);
              }
            else
              {
               Print("#2 Buy -> true. Result Retcode: ",m_trade.ResultRetcode(),
                     ", description of result: ",m_trade.ResultRetcodeDescription());
               PrintResult(m_trade,m_symbol);
              }
           }
         else
           {
            Print("#3 Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
                  ", description of result: ",m_trade.ResultRetcodeDescription());
            PrintResult(m_trade,m_symbol);
           }
        }
      else
        {
         string text="";
         if(Risk>0.0)
            text="< method CheckOpenLong ("+DoubleToString(check_open_long_lot,2)+")";
         else
            text="< Lots ("+DoubleToString(InpLots,2)+")";
         Print(__FUNCTION__,", ERROR: method CheckVolume (",DoubleToString(check_volume_lot,2),") ",
               text);
         return;
        }
     }
   else
     {
      Print(__FUNCTION__,", ERROR: method CheckVolume returned the value of \"0.0\"");
      return;
     }
//---
  }
//+------------------------------------------------------------------+
//| Verkaufsposition eröffnen|
//+------------------------------------------------------------------+
void OpenSell(double sl,double tp)
  {
   sl=m_symbol.NormalizePrice(sl);
   tp=m_symbol.NormalizePrice(tp);

   double check_open_short_lot=0.0;
   if(Risk>0.0)
     {
      check_open_short_lot=m_money.CheckOpenShort(m_symbol.Bid(),sl);
      Print("sl=",DoubleToString(sl,m_symbol.Digits()),
            ", CheckOpenLong: ",DoubleToString(check_open_short_lot,2),
            ", Balance: ",    DoubleToString(m_account.Balance(),2),
            ", Equity: ",     DoubleToString(m_account.Equity(),2),
            ", FreeMargin: ", DoubleToString(m_account.FreeMargin(),2));
      if(check_open_short_lot==0.0)
        {
         Print(__FUNCTION__,", ERROR: method CheckOpenShort returned the value of \"0.0\"");
         return;
        }
     }
   else
      check_open_short_lot=InpLots;
//--- Volumen vor OrderSend prüfen, um Fehler "nicht genug Geld" zu vermeiden (CTrade)
   double check_volume_lot=m_trade.CheckVolume(m_symbol.Name(),check_open_short_lot,m_symbol.Bid(),ORDER_TYPE_SELL);

   if(check_volume_lot!=0.0)
     {
      if(check_volume_lot>=check_open_short_lot)
        {
         if(m_trade.Sell(check_open_short_lot,NULL,m_symbol.Bid(),sl,tp))
           {
            if(m_trade.ResultDeal()==0)
              {
               Print("#1 Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),
                     ", description of result: ",m_trade.ResultRetcodeDescription());
               PrintResult(m_trade,m_symbol);
              }
            else
              {
               Print("#2 Sell -> true. Result Retcode: ",m_trade.ResultRetcode(),
                     ", description of result: ",m_trade.ResultRetcodeDescription());
               PrintResult(m_trade,m_symbol);
              }
           }
         else
           {
            Print("#3 Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),
                  ", description of result: ",m_trade.ResultRetcodeDescription());
            PrintResult(m_trade,m_symbol);
           }
        }
      else
        {
         string text="";
         if(Risk>0.0)
            text="< method CheckOpenShort ("+DoubleToString(check_open_short_lot,2)+")";
         else
            text="< Lots ("+DoubleToString(InpLots,2)+")";
         Print(__FUNCTION__,", ERROR: method CheckVolume (",DoubleToString(InpLots,2),") ",
               text);
         return;
        }
     }
   else
     {
      Print(__FUNCTION__,", ERROR: method CheckVolume returned the value of \"0.0\"");
      return;
     }
//---
  }
//+------------------------------------------------------------------+
//| CTrade-Ergebnis drucken|
//+------------------------------------------------------------------+
void PrintResult(CTrade &trade,CSymbolInfo &symbol)
  {
   Print("Code of request result: "+IntegerToString(trade.ResultRetcode()));
   Print("code of request result: "+trade.ResultRetcodeDescription());
   Print("deal ticket: "+IntegerToString(trade.ResultDeal()));
   Print("order ticket: "+IntegerToString(trade.ResultOrder()));
   Print("volume of deal or order: "+DoubleToString(trade.ResultVolume(),2));
   Print("price, confirmed by broker: "+DoubleToString(trade.ResultPrice(),symbol.Digits()));
   Print("current bid price: "+DoubleToString(trade.ResultBid(),symbol.Digits()));
   Print("current ask price: "+DoubleToString(trade.ResultAsk(),symbol.Digits()));
   Print("broker comment: "+trade.ResultComment());
//int d=0;
  }
//+------------------------------------------------------------------+