MQL4 Эксперт, сталкивающийся с мета-цитатами - PullRequest
0 голосов
/ 28 сентября 2019

У меня возникла проблема, связанная с проблемой мета-цитат mql4. Если кто-нибудь здесь, пожалуйста, помогите мне.

Пожалуйста, проверьте код ниже, пока я добавляю его с индикатором.1003 *

Когда я добавляю свой индикатор с этим разъемом, он ломается, многие проверяют, что они работают отлично, вместо того, чтобы использовать этот разъем.

Как будто он выдает предупреждение о каждой свече, когда я использовал этот код разъема и вместо этогоразъем работает нормально и не ломается вот так

Заранее спасибо!

#property description "MT2Trading connector: connects MT4 to MT2 Trading Platform"
#property link      "https://www.mt2trading.com"
#property version   "13.0"
#property strict
//#property icon "..\\Images\\mt2tradingplatform.ico"


enum broker {
   All = 0,
   IQOption = 1,
   Binary = 2,
   Spectre = 3,
   Alpari = 4
};

enum martingale {
   NoMartingale = 0,
   OnNextExpiry = 1,
   OnNextSignal = 2, 
   Anti_OnNextExpiry = 3, 
   Anti_OnNextSignal = 4, 
   OnNextSignal_Global=5,
   Anti_OnNextSignal_Global = 6
};

enum result {
   TIE = 0,
   WIN = 1,
   LOSS = 2
};

#import "mt2trading_library.ex4"   // Please use only library version 12.4 or higher !!!
   bool mt2trading  (string symbol, string direction, double amount, int expiryMinutes);
   bool mt2trading  (string symbol, string direction, double amount, int expiryMinutes, string signalname);
   bool mt2trading  (string symbol, string direction, double amount, int expiryMinutes, martingale martingaleType, int martingaleSteps, double martingaleCoef, broker myBroker, string signalName, string signalid);
   int  traderesult (string signalid);
#import


enum onoff {
   NO = 0,
   YES = 1 
};


// Inputs Parameters            
extern string s0 = "===== SIGNAL SETTINGS ============="; // ======================
static onoff AutoSignal = YES;     // Autotrade Enabled
extern broker Broker = All;
extern string SignalName = ""; // Signal Name (optional)
extern string IndicatorName = ""; // Indicator File Name
extern int IndiBufferCall = 0;      // Signal Buffer Up ("Call") 
extern int IndiBufferPut = 1;       // Signal Buffer Down ("Put") 
enum signaltype {
   IntraBar = 0,   // Intrabar
   ClosedCandle = 1       // On new bar
};
extern signaltype SignalType = ClosedCandle; // Entry Type
extern string s_title_settings   = "===== TRADING SETTINGS ============"; // ====================
extern double TradeAmount = 1;            // Trade Amount 
extern int ExpiryMinutes = 5;          // Expiry Time [minutes]
//extern string s_title_martingale = ""; // [Martingale Section]

extern martingale MartingaleType = NoMartingale; // Martingale
extern int MartingaleSteps = 2; // Martingale Steps          
extern double MartingaleCoef = 2.0; // Martingale Coefficient


// Variables          
bool Martingale;
string infolabel_names;
string chkenable;
bool infolabel_created;
int lbnum = 0;
bool initgui = false;

datetime sendOnce;   // Candle time stampe of signal for preventing duplicated signals on one candle
string asset;        // Symbol name (e.g. EURUSD)
string signalID;     // Signal ID (unique ID)
bool alerted = false;
int ForegroundColor;
long DesktopScaling; 
long desktopScreenDpi;
int  TerminalInfoInteger;




//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{     

   // Initialize the time flag
   sendOnce = TimeCurrent();

   // Generate a unique signal id for signals management (based on timestamp, chart id and some random number)
   MathSrand(GetTickCount()); 
   if (MartingaleType == OnNextSignal || MartingaleType == Anti_OnNextSignal)
      signalID = IntegerToString(GetTickCount()) + IntegerToString(MathRand());   // For OnNextSignal martingale will be indicator-wide unique id generated
   else if (MartingaleType == OnNextSignal_Global || MartingaleType == Anti_OnNextSignal_Global) 
      signalID = IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN)) + IntegerToString(TerminalInfoInteger(TERMINAL_BUILD)) + AccountInfoString(ACCOUNT_NAME);   // For global martingale will be terminal-wide unique id generated     


   // Symbol name should consists of 6 first letters
   if (StringLen(Symbol()) >= 6)
      asset = StringSubstr(Symbol(),0,6);
   else
      asset = Symbol();


   // GUI
   desktopScreenDpi = TerminalInfoInteger(TERMINAL_SCREEN_DPI);
   DesktopScaling = desktopScreenDpi > 96.0 ? desktopScreenDpi / 96.0 : 1.0;  
   ForegroundColor = ChartGetInteger(0, CHART_COLOR_FOREGROUND);
   for (int i = 0; i < 100; i++) {
      if (ObjectFind(0, "Obj_LB" + IntegerToString(i)) >= 0)
         continue;
      else {
         lbnum = i; 
         break;
      }
   }   
   infolabel_names = "Obj_LB" + IntegerToString(lbnum);   
   ObjectCreate(0, infolabel_names, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(infolabel_names,"", 8, "Tahoma");     
   chkenable = "Obj_CHK" + IntegerToString(lbnum);

   EventSetTimer(1);   
   return(INIT_SUCCEEDED);
}



void OnDeinit(const int reason)
{
   EventKillTimer();
   ObjectDelete(0, infolabel_names); 
   ObjectDelete(0, chkenable); 
}




//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//--- 
   double up = 0, dn = 0;
   ResetLastError();

   if (MartingaleType == NoMartingale || MartingaleType == OnNextExpiry || MartingaleType == Anti_OnNextExpiry)
      signalID = IntegerToString(GetTickCount()) + IntegerToString(MathRand());   // For NoMartingale or OnNextExpiry martingale will be candle-wide unique id generated

   if (IndicatorName != "") {
      up = iCustom(NULL, 0, IndicatorName, IndiBufferCall, SignalType);
      dn = iCustom(NULL, 0, IndicatorName, IndiBufferPut, SignalType);
   }
   else {
      ObjectSetText(infolabel_names,"MT2" + (Broker == IQOption ? "IQ" : Broker == Binary ? "Binary" : Broker == Spectre ? "Spectre" : Broker == Alpari ? "ALP" : "") + " Error: " + "Indicator name is EMPTY!", 8, "Tahoma", clrRed); 
   }

   // Check if iCustom is processed successful. If not: alert error once.
   int errornum = GetLastError();
   if (errornum == 4072) {
      ObjectSetText(infolabel_names,"MT2" + (Broker == IQOption ? "IQ" : Broker == Binary ? "Binary" : Broker == Spectre ? "Spectre" : Broker == Alpari ? "ALP" : "") + " Error: '" + IndicatorName+"' indicator is not found!", 8, "Tahoma", clrRed);  
      if (!alerted) {
         Alert("MT2" + (Broker == IQOption ? "IQ" : Broker == Binary ? "Binary" : Broker == Spectre ? "Spectre" : Broker == Alpari ? "ALP" : "") + " Connector Error: '" + IndicatorName+"' is not found in the indicators folder. Indicator name should match exactly with the indicator's file name.");
         alerted = true;
      }
   }

   // if signal UP (CALL)
   if (AutoSignal && signal(up) && Time[0] > sendOnce) {
      //Print(Time[0], sendOnce) ;
      mt2trading (asset, "CALL", TradeAmount, ExpiryMinutes, MartingaleType, MartingaleSteps, MartingaleCoef, Broker, SignalName, signalID);
      sendOnce = Time[0]; // Time stamp flag to avoid duplicated trades
      Print ("CALL - Signal sent!" + (Martingale != NoMartingale ? " [Martingale: Steps " + IntegerToString(MartingaleSteps) + ", Coefficient " + DoubleToString(MartingaleCoef,2) + "]" : ""));
   }

   // if signal DOWN (PUT)
   if (AutoSignal && signal(dn) && Time[0] > sendOnce) {
      //Print(Time[0], sendOnce) ;
      mt2trading (asset, "PUT", TradeAmount, ExpiryMinutes, MartingaleType, MartingaleSteps, MartingaleCoef, Broker, SignalName, signalID);
      Print ("PUT - Signal sent!" + (Martingale != NoMartingale ? " [Martingale: Steps " + IntegerToString(MartingaleSteps) + ", Coefficient " + DoubleToString(MartingaleCoef,2) + "]" : ""));
      sendOnce = Time[0]; // Time stamp flag to avoid duplicated trades
   }


   //--- return value of prev_calculated for next call
   return(rates_total);
}
//+------------------------------------------------------------------+


// Function: check indicators signal buffer value 
bool signal (double value) 
{
   if (value != 0 && value != EMPTY_VALUE)
      return true;
   else
      return false;
} 









// Function: create info label on the chart
void OnTimer() {
   if (!initgui) {
      ObjectsDeleteAll(0,"Obj_*");      
      initgui = true;
   }
   createGUI();
}



void createGUI() {
      if (ObjectFind(0, infolabel_names) < 0) {
         int row = 0;
         for (int i = 0; i < 100; i++)
            if (ObjectFind(0, "Obj_LB" + IntegerToString(i)) >= 0)
               row++;
         ObjectCreate(0, infolabel_names,OBJ_LABEL, 0, 0, 0); 
         ObjectSetInteger(0,infolabel_names,OBJPROP_SELECTABLE,false);
         ObjectSetInteger(0,infolabel_names,OBJPROP_READONLY,true);
         ObjectSet(infolabel_names, OBJPROP_CORNER, 2);
         ObjectSet(infolabel_names, OBJPROP_XDISTANCE, 31*DesktopScaling);
         ObjectSet(infolabel_names, OBJPROP_YDISTANCE, 6*DesktopScaling + row * 16*DesktopScaling);
         ObjectCreate(ChartID(),chkenable,OBJ_LABEL,0,0,0) ;
         if (AutoSignal)
            ObjectSetText(chkenable,CharToStr(254),14,"Wingdings",ForegroundColor);
         else 
            ObjectSetText(chkenable,CharToStr(0x6F),14,"Wingdings",clrRed);

         ObjectSetInteger(0,chkenable,OBJPROP_SELECTABLE,false);
         ObjectSetInteger(0,chkenable,OBJPROP_READONLY,true);      
         ObjectSet(chkenable, OBJPROP_CORNER, 2);


         ObjectSetInteger(ChartID(),chkenable,OBJPROP_XDISTANCE,10*DesktopScaling);
         ObjectSetInteger(ChartID(),chkenable,OBJPROP_YDISTANCE,2*DesktopScaling + row*16*DesktopScaling);
         ObjectSetInteger(ChartID(),chkenable,OBJPROP_BACK,false);
         ObjectSetInteger(ChartID(),chkenable,OBJPROP_XSIZE,7*DesktopScaling);
         ObjectSetInteger(ChartID(),chkenable,OBJPROP_YSIZE,7*DesktopScaling);   
         if (IndicatorName=="") {
            Alert ("Attention: Indicator is not defined.");      
            Print ("Attention: Indicator is not defined.");    
            ObjectSetText(infolabel_names,"MT2" +"MT2" + (Broker == IQOption ? "IQ" : Broker == Binary ? "Binary" : Broker == Spectre ? "Spectre" : Broker == Alpari ? "ALP" : "") + " Error: " + "Indicator name is EMPTY!", 8, "Tahoma", clrOrangeRed);  
         }   
         else 
            if (AutoSignal)
               ObjectSetText(infolabel_names,"MT2" + (Broker == IQOption ? "IQ" : Broker == Binary ? "Binary" : Broker == Spectre ? "Spectre" : Broker == Alpari ? "ALP" : "") + ": " + IndicatorName + " ["+ DoubleToString(TradeAmount,2) + " | Exp: " + IntegerToString(ExpiryMinutes)+ "M]", 8, "Tahoma", ForegroundColor);     
            else
               ObjectSetText(infolabel_names,"MT2" + (Broker == IQOption ? "IQ" : Broker == Binary ? "Binary" : Broker == Spectre ? "Spectre" : Broker == Alpari ? "ALP" : "") + ": " + IndicatorName + " ["+ DoubleToString(TradeAmount,2) + " | Exp: " + IntegerToString(ExpiryMinutes)+ "M]", 8, "Tahoma", clrRed);     
      }
}



void OnChartEvent(const int id,         // Event ID 
                  const long& lparam,   // Parameter of type long event 
                  const double& dparam, // Parameter of type double event 
                  const string& sparam  // Parameter of type string events 
                  ) 
{ 
   if (id == CHARTEVENT_OBJECT_CLICK) {
      if(sparam==chkenable)
      {
         if (AutoSignal) {
            AutoSignal = NO;
            ObjectSetText(chkenable,CharToStr(0x6F),14,"Wingdings",clrRed);
            ObjectSetInteger(0, infolabel_names, OBJPROP_COLOR, clrRed);
         } 
         else {
            AutoSignal = YES;
            ObjectSetText(chkenable,CharToStr(254),14,"Wingdings",ForegroundColor);         
            ObjectSetInteger(0, infolabel_names, OBJPROP_COLOR,ForegroundColor);
         }
      }

   }
}```


...