Forex
Google

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions
Forex Forum Register FAQ Members List Calendar Today's Posts


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-09-2006, 12:53 PM
demag demag is offline
Junior Member
 
Join Date: Jan 2006
Location: Middle Earth, UK.
Posts: 25
demag is on a distinguished road
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 |
//| http://www.forex-tsd.com |
//+------------------------------------------------------------------+


#property copyright "Coders Guru"
#property link "http://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+Poi nt*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
//+------------------------------------------------------------------+
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-09-2006, 01:19 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Unhappy Semi-colon

Quote:
Originally Posted by 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!

__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-09-2006, 10:08 PM
demag demag is offline
Junior Member
 
Join Date: Jan 2006
Location: Middle Earth, UK.
Posts: 25
demag is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-10-2006, 06:59 AM
mcintyd1 mcintyd1 is offline
Junior Member
 
Join Date: Dec 2005
Location: Portland, Oregon, USA
Posts: 7
mcintyd1 is on a distinguished road
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!)
__________________
Regards,

Dean
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-10-2006, 08:18 AM
demag demag is offline
Junior Member
 
Join Date: Jan 2006
Location: Middle Earth, UK.
Posts: 25
demag is on a distinguished road
Great,

Thanks Dean.

demag.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with .ex4................. EFX General Discussion 4 10-21-2006 07:23 AM
problem with EVERY #MTF indicators iGoR Indicators - Metatrader 4 10 08-16-2006 06:07 AM
Problem with BGcross EA Andrewsurfer Expert Advisors - Metatrader 4 2 05-26-2006 06:13 AM
Backtesting Problem juanchoc Expert Advisors - Metatrader 4 3 05-23-2006 03:26 PM
I've a Problem here hellkas Metatrader 4 6 11-04-2005 12:30 AM


All times are GMT. The time now is 08:10 PM.