Hi,
I have a problem with the default fractal indicator in MT4. If you create an EA which prints the value of the fractal indicator on each bar, it can happen that a non zero value is printed, although on the chart there is nothing indicating that the concerned bar is a fractal.
I think the problem is that when the last bar starts at a price lower than the previous fractal up value, two bars before, it will be recognized as a fractal because the previous bar and the current one (which is not finished) are lower.
How to modify that? I tried to use a shift of 3 to avoid indicating a fractal 2 bars befor the current one. I tried to modify the fractal indicator to recompute the last three bars. And I tried many other things, but I cannot get rid of those wrong signals.
I hope some of you can help me.
Here is the code. Try to execute it on EURUSD 1h from 2007.08.01 to 2007.08.02. You'll see that there are two false fractals printed in the journal, but they don't appear on the chart.
//+------------------------------------------------------------------+
//| Chaos.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//|
Forex Trading Software: Forex Trading Platform MetaTrader 4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//----------------------- INCLUDES
#include <stdlib.mqh>
//----------------------- EA PARAMETER
extern double Lots = 0.1;
datetime prevBarTime;
datetime NO_TIME = D'01.01.1990';
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
Print("--------------------------------- Start -------------------------------------");
prevBarTime = NO_TIME;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
if (Time[1] != prevBarTime) {
//Print("Time: " + Time[1]);
double up = iCustom(Symbol(), 0, "Fractals", 0, 3);
double down = iCustom(Symbol(), 0, "Fractals", 1, 3);
if (up != 0.0)
Print(up);
if (down != 0.0)
Print(down);
prevBarTime = Time[1];
}
//----
return(0);
}
//+------------------------------------------------------------------+
Cheers,
Daniel