|
|||||||
| 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 |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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); } //+------------------------------------------------------------------+ |
|
|||
|
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!)
__________________
Regards, Dean |
![]() |
|
|
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 |