EA shows no error in compiler but Journal says "Not expert..."

 

Hello experts...!

I'm new to MT4 platform and I've been trying to create an EA, I managed to come up with an indicator which is fine but when I try to make it as an EA I receive the following error:

MT4 Journal:

2019.04.03 11:05:47.286 'testEA' is not expert and cannot be executed

Meta Editor:

0 error(s), 0 warning(s), compile time: 410 msec 1 1

I believe the header property declarations have something to do with it, plz advise 

Code:

#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Gold
#property indicator_width1 2

 

Do not double post.

Your other post has been deleted.

 
make sure you do not have the function start() defined. 
 
Stephen Cattaneo:
make sure you do not have the function start() defined. 

Thank you Stephen

Here are the list of functions I used...

int OnInit()
int OnCalculate()
double EA()
void OnTick()
int over()

//Init in detail
int OnInit()
  {
   int shift_begin=int(.....);
   IndicatorShortName("Name");
   SetIndexBuffer(0,B0);
   SetIndexBuffer(1,B1);
   SetIndexBuffer(2,B2);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexDrawBegin(0,shift_begin);
   SetIndexDrawBegin(1,shift_begin);
   SetIndexDrawBegin(2,shift_begin);
   return(INIT_SUCCEEDED);
  }

Please let me know

 
Arunkumar Kalyanasundaram:

Thank you Stephen

Here are the list of functions I used...

Please let me know

remove the function from the code  OnCalculate() , as well as #property  indicator_chart_window #property  indicator_buffers 1 #property  indicator_color1 Gold #property  indicator_width1 2 .

This applies to indicators, not an expert Advisor.

 
Vitalii Ananev: This applies to indicators, not an expert Advisor.

And all the SetIndex*

 
whroeder1:

And all the SetIndex*

Yeah, right, I forgot about the indicator buffers.

 

Tk u @Vitalii & @Whroeder1, I have removed the set index, and I've removed the onCalculate function to onTick now I'm able to load the EA but its still trading on change of signal, is it bcz the variables used to calculate is an array to store the data or what is happening, I'm sorry I'm good with the EAs.

I'm passing the crossover to the user defined function crossed, so is it because crossed isin't getting the value 1 or 2 as required? How do I check it, Please let me know; Thanks in advance

//This is OnTick()
 int limit=rates_total-prev_calculated;
   if(prev_calculated==0)limit--;
   else  limit++;

   for(i=0; i<limit && !IsStopped(); i++)
   {
      B0[i]=2*EA(...)-EA(i,period);
......
......
......
......

      }

   for(i=0; i<limit && !IsStopped(); i++)
      B1[i]=iMAOnArray(B0,0,(int)MathRound(........);

   for(i=0; i<limit && !IsStopped(); i++)
     {
      if(B1[i]>B1[i+1])B2[i]=B1[i];
    //  int isCrossed = Crossed(B0[i], B1[i]);
      else B2[i]=EMPTY_VALUE;
     }

int isCrossed = Crossed(B1[limit], B2[limit]);
total = OrdersTotal();
if(total < 1)
{
if(isCrossed == 1)
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, 0, (Ask + TakeProfit * Point), "Double SMA Crossover H1", 12345, 0, Blue);
Print("Test BUY trigger: ", OrderOpenPrice());
if(ticket > 0)
{
if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
Print("BUY order opened : ", OrderOpenPrice());
}
else
Print("Error opening BUY order : ", GetLastError());

}

if(isCrossed == 2)
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, 0, (Bid - TakeProfit * Point), "Double SMA Crossover H1", 12345, 0, Red);
if(ticket > 0)
{
if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
Print("SELL order opened : ", OrderOpenPrice());
}
else
Print("Error opening SELL order : ", GetLastError());
return;
}

}

for(cnt = 0; cnt < total; cnt++)
{
double os = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if(isCrossed == 2)
{
os = OrderClose(OrderTicket(), OrderLots(), Bid, 3, Violet); // close position
 // exit
}
// check for trailing stop
if(TrailingStop > 0)
{
if((Bid - OrderOpenPrice()) > (Point * TrailingStop))
{
if(OrderStopLoss() < (Bid - Point * TrailingStop))
{
double om = OrderModify(OrderTicket(), OrderOpenPrice(), (Bid - Point * TrailingStop), OrderTakeProfit(), 0, Green);

}
}
}
}
else // go to short position
{
// should it be closed?
if(isCrossed == 1)
{
double oc = OrderClose(OrderTicket(), OrderLots(), Ask, 3, Violet); // close position
 // exit
}
// check for trailing stop
if(TrailingStop > 0)
{
if((OrderOpenPrice() - Ask) > (Point * TrailingStop))
{
if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0))
{
double om1 = OrderModify(OrderTicket(), OrderOpenPrice(), (Ask + Point * TrailingStop), OrderTakeProfit(), 0, Red);

}
}
}
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //  return(rates_total);
  }
  
////////////////////////////////////////////////////////////////////////////////////////////////// 
int Crossed(double line1, double line2)
{
static int last_direction = 0;
static int current_dirction = 0;

if(line1 > line2)
{
current_dirction = 1; //up
}
if(line1 < line2)
{
current_dirction = 2; //down
}

if(current_dirction != last_direction) //changed
{
last_direction = current_dirction;
return (last_direction);
}
else
{
return (0);
}
} 
 

What is B0, B1, B2? Use speaking names for your variables.

The whole indenting is a mess, use Tools->Styler to indent your code. Move larger code blocks to functions.

In OnTick there is no prev_calculated or rates_total. You'll have to figure this out on your own.

 
lippmaje: In OnTick there is no prev_calculated or rates_total.
Exactly. Don't try do that. There are no buffers, no IndicatorCounted() or prev_calculated. No way to know if older bars have changed or been added (history update.)
Just get the value(s) of the indicator(s) into the EA (using iCustom) and do what you want with it.
You should encapsulate your iCustom calls to make your code self-documenting.
          Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum
 

Mixing EA with indicators is not a good idea, we all agree on that, but iCustom calls may be inefficient in some cases bc of unnecessary calculations overload. In case we have access to source code of indicator - and we have it here - I would suggest 2 more options to pass signals to EA:

  1. via custom chart events - more efficient https://docs.mql4.com/eventfunctions/eventchartcustom
  2. using global variables - less efficient bc it involves disk I/O https://book.mql4.com/variables/globals

EventChartCustom - Working with Events - MQL4 Reference
EventChartCustom - Working with Events - MQL4 Reference
  • docs.mql4.com
Returns true if a custom event has been successfully placed in the events queue of the chart that receives the events. In case of failure, it returns false. Use GetLastError() to get an error code. An Expert Advisor or indicator attached to the specified chart handles the event using the function OnChartEvent(int event_id, long& lparam, double...
Reason: