Help with Fractal EA

 

Hi,

How can i validate an entry with fractal?

Entry: Open buy when the fractal  show an down arrow, and sell when the fractal show an up arrow.

Exit: Close the buy when an up arrow shows, and close sell when an down arrow shows.


I'd tried to code with iFractal but I could not do the condition.

 
Erick Contieri: How can i validate an entry with fractal?

Entry: Open buy when the fractal  show an down arrow, and sell when the fractal show an up arrow.

Exit: Close the buy when an up arrow shows, and close sell when an down arrow shows.

I'd tried to code with iFractal but I could not do the condition.

You have to remember that the fractal is a lagging indicator. The fractal is only identified after the fact, a few bars later at least.

So, if you use iFractal(), it will not signal it at position/bar-shift [0] or [1], but only from [2] onward, where position [2] is tentative and would still be incomplete as it depends on the current prices which have not closed the bar yet. Only from position [3] onward, can it be considered a confirmed fractal with a confirmed right-hand shoulder or 2 bars.

That being said, by the time a fractal is confirmed, it might be too late to place the order and can easily turn on you. So, many traders prefer to trade on the breakout of earlier fractals instead of trading the most recent forming fractal itself.

It is also common practice to use the most recently confirmed fractal, as a Trailing-Stop for open Orders.

 
Fernando Carreiro:

You have to remember that the fractal is a lagging indicator. The fractal is only identified after the fact, a few bars later at least.

So, if you use iFractal(), it will not signal it at position/bar-shift [0] or [1], but only from [2] onward, where position [2] is tentative and would still be incomplete as it depends on the current prices which have not closed the bar yet. Only from position [3] onward, can it be considered a confirmed fractal with a confirmed right-hand shoulder or 2 bars.

That being said, by the time a fractal is confirmed, it might be too late to place the order and can easily turn on you. So, many traders prefer to trade on the breakout of earlier fractals instead of trading the most recent forming fractal itself.

It is also common practice to use the most recently confirmed fractal, as a Trailing-Stop for open Orders.


So, I intend to use it with renko graph, where the delay of 1 or 2 bars is not so relevant.
 
Erick Contieri: So, I intend to use it with renko graph, where the delay of 1 or 2 bars is not so relevant.

Renko bars or not, the definition of a Fractal is still the same. It is only considered a fractal when there is a shoulder of at least 2 bars on either side. So, you still have to look at bar-shift 3 onward when using the iFractal() function.

If you are only looking for a Renko reversal, then don't use the iFractal() function, but instead detect the confirmed bar reversal directly (ie. direction of Bar[2] is opposite to Bar[1], where Bar[0] is the current bar which is still open and can go either way).

 
Fernando Carreiro:

Renko bars or not, the definition of a Fractal is still the same. It is only considered a fractal when there is a shoulder of at least 2 bars on either side. So, you still have to look at bar-shift 3 onward when using the iFractal() function.

If you are only looking for a Renko reversal, then don't use the iFractal() function, but instead detect the confirmed bar reversal directly (ie. direction of Bar[2] is opposite to Bar[1], where Bar[0] is the current bar still which is still open and can go either way).

Oh thats true, but how can I detect the diretion of the bar?
 
Erick Contieri: Oh thats true, but how can I detect the diretion of the bar?

( Close[i] - Open[i] ) ... if > 0 it is up, if < 0 it is down, otherwise it has no direction (I used MQL4 notation for simplicity, but if it is MQL5 then it will be different).

Then compare that to the next bar to see if it is the same or opposite.

This is basic coding, so I recommend some extra research -- maybe read a book on it?

Forum on trading, automated trading systems and testing trading strategies

Something Interesting to Read

Sergey Golubev, 2017.09.16 05:40

Expert Advisor Programming for MetaTrader 4


This book will teach you the following concepts:

  • The basic of the MLQ4 language, including variables and data types, operations, conditional and loop operators, functions, classes and objects, event handlers and more.
  • Place, modify and close market and pending orders.
  • Add a stop loss and/or take profit price to an individual order, or to multiple orders.
  • Close orders individually or by order type.
  • Get a total of all currently opened orders.
  • Work with OHLC bar data and locate basic candlestick patterns.
  • Find the highest high and lowest low of recent bars.
  • Work with MetaTrader’s built-in indicators, as well as custom indicators.
  • Add a trailing stop or break even stop feature to an expert advisor.
  • Use money management and lot size verification techniques.
  • Add a flexible trading timer to an expert advisor.
  • Construct several types of trading systems, including trend, counter-trend and breakout systems.
  • Add alert, emails, sounds and other notifications.
  • Add and manipulate chart objects.
  • Read and write to CSV files.
  • Construct basic indicators, scripts and libraries.
  • Learn how to effective debug your programs, and use the Strategy Tester to test your strategies.

All of the source code in this book is available for download, including an expert advisor framework that allows you to build robust and fully-featured expert advisors with minimal effort.

Forum on trading, automated trading systems and testing trading strategies

Something Interesting to Read

Sergey Golubev, 2017.09.16 05:48

Expert Advisor Programming for MetaTrader 5


This book will teach you the following concepts:

  • Learn the basics of MQL5, including variables and data types, operators, functions, event handlers, and object-oriented programming.
  • Place, modify and close market and pending orders.
  • Calculate, verify and add stop loss and take profit prices to an open position.
  • Add a flexible trailing stop and/or break even stop to your strategy.
  • Manage your trade risk with money management.
  • Use pending orders to scale in and out of positions.
  • Use price, time and indicator data in your expert advisors.
  • Control program execution by trading on new bar open, and add flexible trade timers to your strategies.
  • Walk through the creation of several basic trading strategies from start to finish.
  • Inform the user with dialog boxes, email alerts, mobile notifications and sounds.
  • Draw trend lines, arrows and text labels on the chart.
  • Read and write data to CSV files.
  • Learn the basics of creating indicators, scripts and libraries in MetaEditor.
  • Debug, test and optimize your trading strategy.
  • And much more!

Whether you’re an experienced programmer moving from MQL4, or a novice just starting with MQL5, this book will give you the foundation to quickly program fully-featured and robust trading systems.

Reason: