MQL4 Metaquotes Problem!

 

Hello All.

I am facing issue regarding mql4 metaquotes problem anyone here please help me .

Please check the code below while i am adding this with indicator its break some of function used in indicator Besides this indicator work perfectly!


#property copyright "Copyright 2017-2019 (c) MT2 Software Ltd."
#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);
         }
      }
   
   }
}


Thanks in advance

Automated Binary Options Trading Robot for MetaTrader 4/5 - MT2Trading
Automated Binary Options Trading Robot for MetaTrader 4/5 - MT2Trading
  • 2019.09.19
  • arabmt2
  • www.mt2trading.com
Since there are infinite ways to trade automatically with MT2 platform, the robot win rate/effectiveness is totally variable to each user. Your results will depend on the technical indicators you set up on MetaTrader or the signals providers you subscribe to, your general configurations, risk-management parameters and overall strategy! Every...
 
@Pavel Zamoshnikov am i right sir?
 

Hi,

I'm working on how to get the last trade result by using the function of traderesult (string signalid); but with no luck after the trade expiry and return nothing, I notice the trade ID transaction was different which been captured, my purpose is just need to display the actual result after trade at my desktop.


Thanks

 
vincentans #:

Hi,

I'm working on how to get the last trade result by using the function of traderesult (string signalid); but with no luck after the trade expiry and return nothing, I notice the trade ID transaction was different which been captured, my purpose is just need to display the actual result after trade at my desktop.


I've never heard of this function.

Reason: