Grayed Out EA - Does not work

 

I recently programmed a very basic EA to test the relationship between risk/reward ratio and winning percentage (see below). The EA successfully compiles, but when I go to my MT4 terminal, the icon for the EA is greyed out and when I try to add it to a chart, I get the message "Cannot open file 'C:\Program Files\GFT_MT4 Powered by BT\experts\90% Wins.ex4' on the EURUSD,H4" in my journal.


I've already looked into this issue and the consensus is that a greyed out EA should work, but means there is no .mq4 file to go with the .ex4 file. Obviously in my case, this makes no sense, as I personally programmed the EA...and it doesn't load on the chart.


Can someone help me?


//+------------------------------------------------------------------+
//|                                            RRR vs. Winning %.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

int MagicNumber                  =     23894;
extern double Stop_Distance      =     100;
extern double TP_Distance        =     100;
int
   Time_0,                                               // New bar beginning time
   Total,                                                // Amount of orders in window
   points;                                               // 5 digit adjustment for points
double pips;                                             // 5 digit adjustment for pips
string Symb;                                             // Symbol abbreviation
extern bool Bought_Last          =      false,
Sold_Last                        =      false;
  

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
  
if (Digits==5 || Digits==3)                              // For 5 digit brokers
   {
   points=10;                                            // Make points = 10 units
   pips=Point*10;                                        // Pips are actually 10 units...
   }
   else                                                  // else...
   {
   points=1;                                             // Points = 1 unit
   pips=Point;                                           // Pips are just 1 unit
   }
   return(0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   Symb = Symbol();
   Total = 0;
   //----Order Processing
   
       for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) 
       {
         if (
         OrderSelect(pos, SELECT_BY_POS)                          // Only my orders w/
         &&  OrderMagicNumber()  == MagicNumber                   // my magic number
         &&  OrderSymbol()       == Symbol() )                    // and my pair.
         {                                                        // Analyzing orders:
         if (OrderType()>1)                                       // Pending order found
            {
            Print("Pending order detected. EA does not work.");
            return(0);                                            // Exit start()
            }
         Total++;                                                 // Counter of market orders
         }
       }
      if(Total>0)                                                  // Only one order at once
      {
      return(0);
      }

//----
if (Bought_Last == false && Total==0)
      {
      Bought_Last = true;
      Sold_Last = false;
      int ticket=OrderSend(Symb,OP_BUY,1,Ask,3*points,Ask-Stop_Distance*pips,Ask+TP_Distance*pips," ",MagicNumber);
         if(ticket>0)
            {
            OrderSelect(ticket,SELECT_BY_TICKET);
            Print("Order Send Successful " + ticket + " Long from " + OrderOpenPrice());
            }
            else
            {
            Print("Order Send Failed, Error " + GetLastError());
            }
      return(0);
      }
else
if (Sold_Last == false && Total==0)
      {
      Sold_Last = true;
      Bought_Last = false;
      ticket=OrderSend(Symb,OP_SELL,1,Bid,3*points,Bid+Stop_Distance*pips,Bid-TP_Distance*pips," ",MagicNumber);
         if(ticket>0)
            {
            OrderSelect(ticket,SELECT_BY_TICKET);
            Print("Order Send Successful " + ticket + " Long from " + OrderOpenPrice());
            }
            else
            {
            Print("Order Send Failed, Error " + GetLastError());
            }
      }
   return(0);
  }
//+------------------------------------------------------------------+
 
Works for me . . .
 

You compiled the EA succesfully, but is that file saved to your metatrader==> experts directory

Check it with your metaeditor where your program is click on file and save as Look if it is in the right directory

If you had made earlier a save to another directory outside the directory of your MT4 platform and you compile then Then this compiled ex4 will be also in that directory

 
Another method would be to create a new EA in the MetaEditor using File | New then using the Expert Advisor Wizard. This will get an EA in the right location. Just paste you code over the template code.
 
dabbler:

This name, "C:\Program Files\GFT_MT4 Powered by BT\experts\90% Wins.ex4"

may be problematic on some operating systems (?). You might try removing the percent sign just in case.

The % is legal under Windows . . . I checked ;-)
 
I created a blank mq4 file in MetaEditor, copied and pasted the OP's code in, saved as . . . the same file name as the OP had used, and then compiled. I then copied the mq4 and ex4 files to my MetaTrader installation directory/experts folder . . . I restarted MT4 and attached the expert to my chart . . . no issues.
 
RaptorUK:
I created a blank mq4 file in MetaEditor, copied and pasted the OP's code in, saved as . . . the same file name as the OP had used, and then compiled. I then copied the mq4 and ex4 files to my MetaTrader installation directory/experts folder . . . I restarted MT4 and attached the expert to my chart . . . no issues.

Wow, that's above and beyond ...

well done :-)

 
//----
if (Bought_Last == false && Total==0)
      {
//      Bought_Last = true;      if buy fails bought last is true   think it has only be true if buy succeed
//      Sold_Last = false;
      int ticket=OrderSend(Symb,OP_BUY,1,Ask,3*points,Ask-Stop_Distance*pips,Ask+TP_Distance*pips," ",MagicNumber);
         if(ticket>0)
            {
            OrderSelect(ticket,SELECT_BY_TICKET);
            Print("Order Send Successful " + ticket + " Long from " + OrderOpenPrice());
            Bought_Last = true;     //place here
            Sold_Last = false;      //
            Total++;                //Also Total is changed
            }
            else
            {
            Print("Order Send Failed, Error " + GetLastError());
            }
      return(0);
      }

Symb & Time_0 has no function

Suggestion bought last/ sold last/ total/

This can also be done for sell trades

 
wnkender:

I get the message "Cannot open file 'C:\Program Files\GFT_MT4 Powered by BT\experts\90% Wins.ex4' on the EURUSD,H4" in my journal.

Do not install in \program files* on Vista/Win7
 
wnkender:

I recently programmed a very basic EA to test the relationship between risk/reward ratio and winning percentage (see below).

When you do get it to work you should find that there is no fixed relationship between risk/reward ratio and winning percentage. I think you will find you need to know the spread, the risk and the reward or using only two ratios the spread/risk and the spread/reward to get the winning percentage for a random trade. If you ignore the spread the winning percentage is easily calculated from the risk/reward ratio based on the random walk model.