Forex
Google
New signals service!

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions


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
  #31 (permalink)  
Old 01-24-2008, 08:07 AM
Senior Member
 
Join Date: Feb 2006
Posts: 559
Michel is on a distinguished road
Quote:
Originally Posted by bdht View Post
Hello there,
Question:
I have started coding my EA. I am by no means a decent coder for MQL b/c I've never seen C++/C. Fine.

My settings are as follows: There are two indicators: IND1 [indicator] and IND2. IND1 has 1 line, IND2 has 2 lines. Lines = lines on a chart. For instance, Bollinger bands indicator has 3 lines, but isn't used in this example. Both INDs have their 0.0 level shown on the chart.

My logic is as follows: when IND1 crosses its 0 level the first time and goes into negative, send the SELL order. Wait for the IND2 to have its line1 cross line2 and send the BUY order, automatically closing the SELL submitted by IND1. If there's a 2nd/3rd/etc 0 level crossing by IND1 into either positive or negative before the BUY, disregard that crossing, do nothing and proceed w/ that first SELL order[otherwise there will be a 2nd/3rd/etc SELL order w/ no corresponding BUY order]. When the BUY order is executed by the IND2 [IND2's line1 has crossed line2], wait for the following crossing of 0 [into the negative] by IND1 and send the SELL order, automatically closing the BUY order submitted by IND2.
I'm going to include my coding. Please take a look at it, b/c it isn't graphing anything and isn't working.

Here's the code itself:

Code:
#property copyright "Copyright © 2008 BDHT"
#define MAGIC 689

//do not take into consideration
//the names of the indicators
//they're fabricated

extern double lots = 0.1; // Lots
extern double TP = 140; // Take Profit
extern double SL = 30; // Stop Loss
static int prevtime = 0;
static int res = 0;
double IND2_line1, IND2_line2, IND1, IND1_prev, IND2_line1_prev;

int init() {  
   IND2_line1 = iIND2_line1(NULL,0,0,MODE_MAIN,0);
   IND2_line2 = iIND2_line2(NULL,0,0,MODE_SIGNAL,0);
   IND1= iCustom(NULL, 0, "IND1", 0, 0, 0);
   IND1_prev= iCustom(NULL,0, "IND1", 0, 0, 1);
   IND2_line1_prev = iCustom(NULL, 0, "IND2", 0, 0, 1);
   return(0);
}
int deinit() {
   return(0);
}

int start() {
//Make sure there are no open orders; if yes - stop
if (OrdersTotal() > 0) 
      return (0);
      
if (IND1< 0 && IND1 < IND1_prev && IND1_prev > 70 && IND2_line1 < 0 && IND2_line2 < 0) { 
// 70 may be 10; simply means that the IND1_prev was greater than 0
      res=OrderSend(Symbol(),OP_SELL,lots,Bid,3,Bid+SL*Point,Ask+TP*Point,"My EA",MAGIC,0,Blue);
      return(0);
}
if (IND2_line1 > IND2_line2 && IND2_line1_prev < IND2_line1) {
      res=OrderSend(Symbol(),OP_BUY,lots,Ask,3,Ask+SL*Point,Bid+TP*Point,"My EA",MAGIC,0,Blue);
      return(0);
}
I know I'm missing something... But what is it?

UPDATE: Okay, I got a little help from phy in MQL forums: he says that "code within start() executes every tick" and "code within init() is only executed one time or once per intitialization/start/restart of the EA". Am I getting this correctly: a tick is any change of price. A bar has many ticks. A M1 bar may have 60 seconds [or so] worth of ticks and a M5 bar may have 60 seconds * 5 instances/minutes worth of ticks. I do not want the code to pay attention to each and every tick there is; I just want the bar to make the difference.
This seems wrong :
PHP Code:
   IND2_line1 iIND2_line1(NULL,0,0,MODE_MAIN,0);
   
IND2_line2 iIND2_line2(NULL,0,0,MODE_SIGNAL,0); 
Where are such functions ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #32 (permalink)  
Old 01-24-2008, 05:15 PM
Junior Member
 
Join Date: Jan 2008
Location: Brooklyn
Posts: 22
bdht is on a distinguished road
Quote:
Originally Posted by Michel View Post
This seems wrong:
Code:
IND2_line1 = iIND2_line1(NULL,0,0,MODE_MAIN,0);
IND2_line2 = iIND2_line2(NULL,0,0,MODE_SIGNAL,0);
Where are such functions ?
Ok, my IND2 has 2 lines crossing one another at some time. As per MQL4 documentation for that particular indicator,
Code:
double iIND2( string symbol, int timeframe, int period, int mode, int shift)
This way,
string symbol is NULL for the current symbol;
int timeframe is 0 for current timeframe;
int period is 0 b/c I don't need anything to be calculated, they simply have to be crossing one another;
int mode is MODE_MAIN b/c that indicator has both MAIN and SIGNAL modes;
int shift is 0 for the phase shift b/c I don't need to be looking at any previous value of that indicator.

What seems wrong?

Last edited by bdht; 01-26-2008 at 12:28 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #33 (permalink)  
Old 01-26-2008, 12:40 AM
Junior Member
 
Join Date: Jan 2008
Location: Brooklyn
Posts: 22
bdht is on a distinguished road
When I backtest my EA, it gives out error message
Code:
2008.01.25 19:39:02	TestGenerator: unmatched data error (high value 1.4674 at 2008.01.24 11:23 and price 1.4675 mismatched)
and
Code:
2008.01.25 19:49:30	TestGenerator: unmatched data error (volume limit 85 at 2008.01.17 22:45 exceeded)
Also, how to I specify closure of the order when the TP is reached? Logically, TP = close and take profit, but I'm not sure.

Last edited by bdht; 01-26-2008 at 01:23 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #34 (permalink)  
Old 01-30-2008, 03:53 AM
Junior Member
 
Join Date: Mar 2007
Posts: 4
boum999 is on a distinguished road
Time Function -- HELP

I use a EA on 5M time frame, i would like to change the time to make the OPEN ORDER... i have to much trade in the same time( on multiple curency, on the same account)..... like .....add 30 or 60 seconde after the 5 Minute bar

Here is the part of the EA.... i think.... need to be change

PHP Code:
datetime LastMinute;
int      LongTrades=0;
int      ShortTrades=0;
double   LastBuyPrice=0;
double   LastSellPrice=0
and this part

PHP Code:
  if(LastMinute!=Time[0]) { 
THAnKS for your HELP
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #35 (permalink)  
Old 02-07-2008, 04:44 PM
SIDDESH's Avatar
Member
 
Join Date: Nov 2006
Location: mumbai
Posts: 64
SIDDESH is on a distinguished road
Can I vary the lot size for consecutive sell or buy orders ?

Hi,

Can I vary the lot size for consecutive sell or buy orders ?

Let us say first short order with 0.3 , second short 0.2 and third cosecutive short order with 0.1lot size. Same for long orders.

Regards,

SIDDESH

Last edited by SIDDESH; 02-07-2008 at 05:23 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #36 (permalink)  
Old 02-08-2008, 05:31 PM
Junior Member
 
Join Date: Dec 2007
Posts: 6
thomasblaesi is on a distinguished road
my First EA, the start() Function will not be called....

i build in the function Alert() in init("init") + deinit("deinit") + start("start")
init + deinit its ok but start() will not called.
not called in Backtesting to
in Parameters i selected "Allow Life trading"
i dont understand what is wrong

thanks for your helb

Thomas
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #37 (permalink)  
Old 02-13-2008, 03:53 AM
Junior Member
 
Join Date: Jan 2008
Location: Brooklyn
Posts: 22
bdht is on a distinguished road
Unbelievable

So much for a 50000+ community...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #38 (permalink)  
Old 02-13-2008, 11:19 AM
Senior Member
 
Join Date: Jan 2006
Posts: 1,119
omelette is on a distinguished road
Quote:
Originally Posted by bdht View Post
So much for a 50000+ community...
Maybe you should read over your question(?) again - you could actually look at it as a rhetorical post!

Anyway, the error are caused by price mis-matches between different timeframes - not really a problem unless you get loads of these. To get rid of them you would need to delete and re-generate the pairs that give problems, via the History center. Your TP question makes no sense.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #39 (permalink)  
Old 02-13-2008, 12:54 PM
fxgrm's Avatar
Member
 
Join Date: Mar 2007
Posts: 91
fxgrm is on a distinguished road
Question Code for trading only specific pairs only?

Newdigital or anyone else:

I have an EA that says: "Trades Authorized On EURUSD Only!" on chart comment.

How can I get it to trade on other pairs? How do I change the code in EA to trade on other paris?

Thanks in advance!

Last edited by fxgrm; 02-13-2008 at 01:31 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #40 (permalink)  
Old 02-13-2008, 03:48 PM
Administrator
 
Join Date: Sep 2005
Posts: 16,816
Blog Entries: 145
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
I moved your post to this thread where this subject was discussed. Check from the beginning of this thread.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
forex, trendenvelopes_v3

Thread Tools
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
MT4 (Basic) Questions stepwise Metatrader 4 6 09-22-2008 03:22 AM
Basic Indicator Question waaustin Metatrader Programming 8 04-02-2008 03:54 PM
Need Help Understanding Basic MQL logic Emerald King Expert Advisors - Metatrader 4 7 02-27-2007 10:59 AM
Very basic coding help needed camisa Questions 1 05-08-2006 06:36 PM


All times are GMT. The time now is 06:21 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.