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.