Failed to load - wrong type [Solved]

 

Hi this is my first time here sorry if this is the wrong place. I just started having this issue today, the code was working fine before. I'm using mt5 and getting "Error loading - wrong type." This is very frustrating for me because I cannot run any ea's as of today. Any guidance would be apprecated. I'll post my code down below. Thank you 


//+------------------------------------------------------------------+
//|                                                         mine.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#include<Trade\Trade.mqh>

//--- object for performing trade operations
CTrade  trade;

//--- Set Variables
double   dblChanged,dblLast; //When Candle Changes
static bool firstRun = true; //first run
string myPairs[6] = {"USDCAD","EURUSD","USDJPY","EURJPY","GBPUSD","USDCHF"}; //Set pairs
double firstCandle[4] = {}; //set up each candle
double secondCandle[4] = {}; //testing candle
double thirdCandle[4] = {}; //candle before entry
//First Run
void OnStart() {
     firstRun = false;
     printf("Hello World First Run Ok");
}
void OnTick() {
 //detect new bar
   static datetime prevTime=0;
   datetime lastTime[1];
   if (CopyTime(_Symbol,_Period,0,1,lastTime)==1 && prevTime!=lastTime[0]) {
       prevTime=lastTime[0];
       printf("new bar");
//End bar check
       
       
//Horizontal line
   long cid=ChartID();
   ObjectDelete(cid, "test");
      ResetLastError();
   double line = iClose(Symbol(),PERIOD_H1,0);
   if(!ObjectCreate(cid,"test",OBJ_HLINE,0,0,line) || GetLastError()!=0)
      Print("Error creating object: ",GetLastError());
   else
      ChartRedraw(cid);
//------------------------
      
     //Create for loop to hold array data
  for(int i=0;i<ArraySize(myPairs);i++) {
   firstCandle[0] = iHigh(myPairs[i],PERIOD_H1,0);
   firstCandle[1] = iLow(myPairs[i],PERIOD_H1,0); //Only update on candle close for performance reasons
   firstCandle[2] =  iOpen(myPairs[i],PERIOD_H1,0);
   firstCandle[3] = iClose(myPairs[i],PERIOD_H1,0);
   
   secondCandle[0] = iHigh(myPairs[i],PERIOD_H1,1);
   secondCandle[1] = iLow(myPairs[i],PERIOD_H1,1);
   secondCandle[2] = iOpen(myPairs[i],PERIOD_H1,1);
   secondCandle[3] = iClose(myPairs[i],PERIOD_H1,1);
   
   thirdCandle[0] =  iHigh(myPairs[i],PERIOD_H1,2);
   thirdCandle[1] =  iLow(myPairs[i],PERIOD_H1,2);
   thirdCandle[2] =  iOpen(myPairs[i],PERIOD_H1,2);
   thirdCandle[3] =  iClose(myPairs[i],PERIOD_H1,2);
   
 printf("Testing this candle close "+firstCandle[3]+ " vs previous candle High"+secondCandle[3] +" and "+ secondCandle[0]);


    //call price check to compare
   if (secondCandle[3] > thirdCandle[0]) {
               //printf(myPairs[i]+ " : "+"Previous High: "+DoubleToString(thirdCandle[0])+" New Close Higher Price: " +DoubleToString(secondCandle[3])); //implicit converted
               buyStop(secondCandle[0],secondCandle[1],secondCandle[2],secondCandle[3],myPairs[i],thirdCandle[0],thirdCandle[1],thirdCandle[2],thirdCandle[3]); //buy
    
    
    
       } else if (secondCandle[3] < thirdCandle[1]) {
            //  printf(myPairs[i] + " : "+"Previous low: " +DoubleToString(thirdCandle[1])+ " Close lower Price: " +  DoubleToString(secondCandle[3]));   //implicit converted
              sellStop(secondCandle[0],secondCandle[1],secondCandle[2],secondCandle[3],myPairs[i],thirdCandle[0],thirdCandle[1],thirdCandle[2],thirdCandle[3]); //sell
         
          } else {
              //no signal
          }
        }
     }
}
//Create Buy Stop Orders
void buyStop(double high,double low,double open,double close,string currentPair,double prevHigh, double prevLow,double prevOpen, double prevClose) {
   int    digits=(int)SymbolInfoInteger(currentPair,SYMBOL_DIGITS);
   string symbol=currentPair;    // specify the symbol, at which the order is placed
   double point=SymbolInfoDouble(symbol,SYMBOL_POINT);         // point
   double ask=SymbolInfoDouble(symbol,SYMBOL_ASK);             // current buy price
   datetime expiration = 0; //TimeTradeServer()+PeriodSeconds(PERIOD_H4);
   double volume=0.01;
   double price=high;       //price for when order will be placed 
   double orderprice = NormalizeDouble(price+(5*point),digits); //place order 5 pips above 3rd candle 
   double altorderprice = NormalizeDouble(price+(10*point),digits);
   int SL_pips=0;                                      
   int TP_pips=0;
        
  //Define Formula for run//----------================
  //Enter non normalized value in price
   double TPFormulaA = price + (2*(price-prevLow))-(15*point);      //Take profit 2x entry candle 
   double SLFormulaA = 0;                                          //No stop loss
   //--
   double TPFormulaB = price + (2*(price-prevLow))-(15*point);      //Take profit 2x entry candle
   double SLFormulaB = price - (SL_pips*point);                     //Static stop loss
   //--
   double TPFormulaC = price + ((2*(price-prevLow))*point)-(15*point);      //Take profit always 2x
   double SLFormulaC = price - ((price-prevLow)*point + (5*point));         //stop loss always below candle, 5 additional pips
   //--
   double TPFormulaD = price + (2*((price-prevLow))*point)-(15*point);      //Take profit variable to 2x stops
   double SLFormulaD = price - ((price-prevLow)*point + (5*point));         //stop loss always below candle, 5 additional pips
   //--
   double TPFormulaPips = price + (TP_pips*point); //Formula for take profit in pips
   double SLFormulaPips = price - (SL_pips*point); //Formula for stops in pips
   //--------------------------------==================     double SL=SLFormulaA;  
   double TP = NormalizeDouble(TPFormulaA,digits);
   double SL = NormalizeDouble(SLFormulaA,digits);                          

   string comment=StringFormat("Buy Stop %s %G lots at %s, SL=%s TP=%s",
                               symbol,volume,
                               DoubleToString(price,digits),
                               DoubleToString(SL,digits),
                               DoubleToString(TP,digits));
//--- everything is ready, sending a Buy Stop pending order to the server
   if(!trade.BuyStop(volume,orderprice,symbol,SL,TP,ORDER_TIME_GTC,expiration,comment)){
      //--- failure message
            Print("buy method failed. Return code=",trade.ResultRetcode()," (",trade.ResultRetcodeDescription(),")");  //Error message
       //--- retry=
            if (!trade.BuyStop(volume,altorderprice,symbol,SL,TP,ORDER_TIME_GTC,expiration,comment)) {
              Print("sell method retry failed. Return code=",trade.ResultRetcode()," (",trade.ResultRetcodeDescription(),")");  //Error message
            } else {
              Print("buy method executed successfully. Return code=",trade.ResultRetcode()," (",trade.ResultRetcodeDescription(),")"); //Error message
            }
     }
   else
     {
      Print("buy method executed successfully. Return code=",trade.ResultRetcode()," (",trade.ResultRetcodeDescription(),")"); //Error Message
     }
return;
}

//Create Sell Stop Orders
void sellStop(double high,double low,double open,double close, string currentPair,double prevHigh, double prevLow,double prevOpen, double prevClose) {
   double volume=0.01;
   string symbol=currentPair;    // specify the symbol, at which the order is placed
   int    digits=(int)SymbolInfoInteger(currentPair,SYMBOL_DIGITS); // number of decimal places
   double point=SymbolInfoDouble(symbol,SYMBOL_POINT);         // point
   double ask=SymbolInfoDouble(symbol,SYMBOL_ASK);    
   datetime expiration=TimeTradeServer()+PeriodSeconds(PERIOD_H4);      
 
   double price=low;                      //candle to use for entry
   double altorderprice=NormalizeDouble(price-(5*point),digits);                      //retry same trade 5 pips lower
   double orderprice = NormalizeDouble(price-(10*point),digits);
   int SL_pips=0;                                      
   int TP_pips=0;
        
  //Define Formula for run//----------================
  //Define Formula for run//----------================
   double TPFormulaA = price - ((2*(prevHigh-price))-(15*point));      //Take profit 2x entry candle 
   double SLFormulaA = 0;                                          //No stop loss
   //--
   double TPFormulaB = price - (2*(prevHigh-price))-(15*point);      //Take profit 2x entry candle
   double SLFormulaB = price + (SL_pips*point);                     //Static stop loss
   //--
   double TPFormulaC = price - ((2*(prevHigh-price))*point)-(15*point);      //Take profit always 2x
   double SLFormulaC = price + ((prevHigh-price)*point + (5*point));         //stop loss always below candle, 5 additional pips
   //--
   double TPFormulaD = price - (2*((prevHigh-price))*point)-(15*point);      //Take profit variable to 2x stops
   double SLFormulaD = price + ((prevHigh-price)*point + (5*point));         //stop loss always below candle, 5 additional pips
   //--
   double TPFormulaPips = price - (TP_pips*point); //Formula for take profit in pips
   double SLFormulaPips = price + (SL_pips*point); //Formula for stops in pips
   //--------------------------------==================     double SL=SLFormulaA;
   double TP = NormalizeDouble(TPFormulaA,digits);
   double SL = NormalizeDouble(SLFormulaA,digits);                         

   string comment=StringFormat("Buy Stop %s %G lots at %s, SL=%s TP=%s",
                               symbol,volume,
                               DoubleToString(price,digits),
                               DoubleToString(SL,digits),
                               DoubleToString(TP,digits));
//--- everything is ready, sending a Buy Stop pending order to the server
   if(!trade.SellStop(volume,orderprice,symbol,SL,TP,ORDER_TIME_GTC,expiration,comment))
     {
      //--- failure message
                 Print("sell stop method failed. Return code=",trade.ResultRetcode(),". Code description: ",trade.ResultRetcodeDescription()); //Error message
      //--- retry
            if (!trade.SellStop(volume,altorderprice,symbol,SL,TP,ORDER_TIME_GTC,expiration,comment)) {
               Print("sell method failed. Return code=",trade.ResultRetcode()," (",trade.ResultRetcodeDescription(),")"); //Error message
            } else {
               Print("sell method executed successfully. Return code=",trade.ResultRetcode()," (",trade.ResultRetcodeDescription(),")"); //Error message
            }
     }
   else
     {
           Print("sell method executed successfully. Return code=",trade.ResultRetcode()," (",trade.ResultRetcodeDescription(),")"); //Error message
     }
return;
}
 

I am also getting the error "-.ex5 not found" When both the .ex5 and .mq5 files are in the /experts directory.

Also got the error "Metaeditor not found" When the editor is clearly installed. Many bugs with the mt client unfortunately. Have reinstalled multiple times using both mt4/and mt5 seperately

1) uninstalled mt5 and restarted

2) installed mt5, pressed f4 to open meta editor

3) Created new expert, pasted in the  code. Press compile, save. 

4) Start/resume debugging on history data. 

This is when I get the wrong type error and I cannot run the EA

 
truthfx :

This should not be in the expert:

void OnStart()
 

Help:

Event Handling

Function

Description

OnStart

The function is called when the  Start event occurs to perform actions set in the script

OnInit

The function is called in indicators and EAs when the  Init event occurs to initialize a launched MQL5 program

OnDeinit

The function is called in indicators and EAs when the  Deinit event occurs to de-initialize a launched MQL5 program

OnTick

The function is called in EAs when the  NewTick event occurs to handle a new quote

OnCalculate

The function is called in indicators when the  Calculate event occurs to handle price data changes

OnTimer

The function is called in indicators and EAs during the  Timer periodic event generated by the terminal at fixed time intervals

OnTrade

The function is called in EAs during the  Trade event generated at the end of a trading operation on a trade server

OnTradeTransaction

The function is called in EAs when the  TradeTransaction event occurs to process a trade request execution results

OnBookEvent

The function is called in EAs when the  BookEvent event occurs to process changes in the market depth

OnChartEvent

The function is called in indicators and EAs when the  ChartEvent event occurs to process chart changes made by a user or an MQL5 program

OnTester

The function is called in EAs when the  Tester event occurs to perform necessary actions after testing an EA on history data

OnTesterInit

The function is called in EAs when the  TesterInit event occurs to perform necessary actions before optimization in the strategy tester

OnTesterDeinit

The function is called in EAs when the  TesterDeinit event occurs after EA optimization in the strategy tester

OnTesterPass

The function is called in EAs when the  TesterPass even occurs to handle an arrival of a new data frame during EA optimization in the strategy tester

Documentation on MQL5: Event Handling
Documentation on MQL5: Event Handling
  • www.mql5.com
The MQL5 language provides handling of certain predefined events. The functions for handling these events should be defined in an MQL5 program: function name, return type, a set of parameters (if any) and their types should strictly correspond to the description of an event handling function. The client terminal event handler uses the return...
 
Vladimir Karputov:

This should not be in the expert

Wow thank you so much for your help, I appreciate it. After reading the documentation I understand my error.

Reason: