My First EA problem

 

I am just playing with the ea from CoderGuru's course and have tried to add another MA.

But Meta-editor is returning an error. Error = 'if'-variable expected C:\Program files\ etc.\My_First_EA.mq4 (66, 4)

//+------------------------------------------------------------------+

//| My_First_EA.mq4 |

//| Coders Guru |

//| https://www.mql5.com/en/forum |

//+------------------------------------------------------------------+

#property copyright "Coders Guru"

#property link "https://www.forex-tsd.com"

//---- input parameters

extern double TakeProfit=15.0;

extern double Lots=0.1;

extern double TrailingStop=8.0;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

int Crossed (double line1 , double line2 , double line3)

{

static int last_direction = 0;

static int current_direction = 0;

if(line1>line2>line3)current_direction = 1; //up

if(line1<line2<line3)current_direction = 2; //down

if(current_direction != last_direction) //changed

{

last_direction = current_direction;

return (last_direction);

}

else

{

return (0);

}

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//----

int cnt, ticket, total;

double shortEma, longEma, longSma,

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<10)

{

Print("TakeProfit less than 10");

return(0); // check TakeProfit

}

shortEma = iMA(NULL,0,3,0,MODE_EMA,PRICE_CLOSE,0);

longEma = iMA(NULL,0,7,0,MODE_EMA,PRICE_CLOSE,0);

longSma = iMA(NULL,0,25,0,MODE_SMA,PRICE_CLOSE,0);

int isCrossed = Crossed (shortEma,longEma,longSma);

total = OrdersTotal();

if(total < 1)

{

if(isCrossed == 1)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"My EA",12345,0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}

if(isCrossed == 2)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"My EA",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(0);

}

return(0);

}

for(cnt=0;cnt<total;cnt++)

{

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)

{

OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position

return(0); // exit

}

// check for trailing stop

if(TrailingStop>0)

{

if(Bid-OrderOpenPrice()>Point*TrailingStop)

{

if(OrderStopLoss()<Bid-Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);

return(0);

}

}

}

}

else // go to short position

{

// should it be closed?

if(isCrossed == 1)

{

OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position

return(0); // exit

}

// check for trailing stop

if(TrailingStop>0)

{

if((OrderOpenPrice()-Ask)>(Point*TrailingStop))

{

if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);

return(0);

}

}

}

}

}

}

return(0);

}

//+------------------------------------------------------------------+

 

Semi-colon

demag:
I am just playing with the ea from CoderGuru's course and have tried to add another MA.

But Meta-editor is returning an error. Error = 'if'-variable expected C:\Program files\ etc.\My_First_EA.mq4 (66, 4)

Semi-colon , it's the hell of forgetting a semi-colon which all the programmer (including me) always suffering it.

This line:

double shortEma, longEma, longSma,

Sould be:

double shortEma, longEma, longSma;

KEEP GOING MAN!

 

CodersGuru Thanks for your quick reply. Much appreciated.

One other question if I can.

In the error report, what do the numbers (66, 4) stand for?

I thought 66 was maybe the line number in the program but now I'm not so sure. Or is it Mq4 code to tell me I've missed a semi colon?

If I get an error report when compiling, does it tell me where to look for the error, or do I just search until I find it?

Many Thanks,

demag.

 

I think the (66, 4) means line 66, space 4.

If you double click the error message, Metaeditor will take you right to the line in which it finds a problem (if you're lucky that is where the REAL problem is!)

 

Great,

Thanks Dean.

demag.

 

my first ea doesnt work

I passed my question to header

 

I passed this