Please help with MT4 . . . . bad signals from System

 

Hi All,

I am not able to understand the functioning of indicators and fulfillment of a signal in MT4. Actually I am a beginner in mql, just got good experience in C# through Ninja Trader and I want to test profitability af an idea. Generated inputs and outputs do not match with my conditions I entered (see Bug.gif).

My guess why it happens so:

A/ indicators is being drawn and changes with candle (but I need them to be calculated from PRICE_CLOSE)

After the close of a candle the indicator shows the value for close price of the candle. (that is why a cross cannot be seen in results)

or

B/ these inputs and outputs are caused by the fact, that SB and BB indicators are being calculated for 20 bars back.

So it is possible that a cross happened, but as the indicators are being redrawn back for 20 bars, they might get redrawn even couple of bars back (I do not think this is highly probable)

Does MT show inputs and outputs correctly?

System (everything is in attachment):

Simple system: LPS.mq4 that uses Bollinger bands (BB) and starc bands indicator (SB)

System has:

entry to long when SBlower crosses upwards BBlower, this is also the exit for short position.

exit from long/entry to short: SBhigher crosses BBhigher downwards

I implemented the Cross with the known method Crossed:

int Crossed (double line1 , double line2)

{

static int last_direction = 0;

static int current_direction = 0;

if(line1>line2)current_direction = 1; //up

if(line1<line2)current_direction = 2; //down

if(current_direction != last_direction) //changed

{

last_direction = current_direction;

return (last_direction);

}

else

{

return (0);

}

}

If you check picture bug.gif, you can see the system generated signals that have nothing in common with my rules. Please advice me how the MT works. I want only the signals that can be seen on the chart to be taken into account .

Thank you very much

Lukas Kellerstein

Files:
LPS.mq4  8 kb
LPSBdown.mq4  3 kb
LPSBup.mq4  3 kb
 

My guess is that your ea is taking readings from the current bar which is not yet closed... Hence, the line might have crossed and went back before the candle closes. Use the previous close candle for your calculation. Use Bar 1 and not Bar 0. I am not an expert and this is just a wild guess

Reason: