| New signals service! | |
|
|||||||
| 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 (3) | Thread Tools | Display Modes |
|
|||
|
Dear Sir
you have decleared the two static variables inside the block of the function. then every time start function recieves a quote it will call the crossed function,and every time when start calls crossed, crossed will first initilize the two varibles to zero,so how could you compare current_direction with last_direction? 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); } } |
|
||||
|
Quote:
Thanks for the question! There are two kinds of variables in MQL4, normal variables and static variables; The static variables are very like the normal variables with only one extra feature: The initialization of the static variables occurs only one time. Which means if you write a line of code like that: static int last_direction = 0; You mean: If this is the first call of the program, initialize the variable to 0, else (if it's the second, third, fourth etc call) don't initialize the variable again. But if you used a normal variable instead of static variable, every time you call your program the initialization of the variable will be occurred. |
|
|||
|
Hi, at start i want say thank you for your great job you're doing to help us to learn programming MQL4.
I've got problem. My First EA is not working correct. When MA lines getting crossed, MT try to open order but such error occurs every time: 2006.04.19 13:14:12 My_First_EA EURUSD,M1: Error opening SELL order : 4109 It is the same with Long position. #define ERR_TRADE_NOT_ALLOWED 4109 I know it is connect with these lines of code: 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); } But i can't get it why this error occurs. I would be pleased if you could help me. Best Wishes. |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/lessons/671-lesson-16-your-first-expert-advisor-part-4-a.html
|
||||
| Posted By | For | Type | Date | |
| Vegas Wealth Builder - Part I - Page 5 | This thread | Refback | 02-16-2008 07:26 PM | |
| Forex Factory - View Single Post - Vegas Wealth Builder - Part I | This thread | Refback | 08-30-2007 02:17 PM | |
| Vegas Wealth Builder - Part I - Page 5 @ Forex Factory | This thread | Refback | 06-28-2007 11:37 AM | |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Lesson 14 - Your First Expert Advisor (Part 2) | codersguru | Lessons | 12 | 07-04-2008 09:35 AM |
| CCI Expert Advisor | rodrigokaus | Expert Advisors - Metatrader 4 | 10 | 09-29-2006 06:31 PM |
| Lesson 15 - Your First Expert Advisor (Part 3) | codersguru | Lessons | 5 | 12-27-2005 10:00 PM |
| Lesson 13 - Your First Expert Advisor (Part 1) | codersguru | Lessons | 19 | 12-27-2005 09:04 PM |