Hello everyone,
When trading manually, we can easily visually identify the breakout/breakdown of a consolidation. This consolidation may last n bars, never the same period.
However, for Automated Trading, I was not able to code properly the upper and lower limits of a range, where by definition the period “n” is a variable. Intuitively, I’m suspecting Arrays would be helpful but I failed to write a code which works.
The idea is to identify the upper and low limits of the range (in the boxes in the screenshot). If anyone can please help writing this code or if you can direct me to a link where this code is available on this forum.
Many thanks
You can simply use a number of bars:
hh = highest[20](high)
ll = lowest[20](low)
consolidation = (hh - ll) <= 20 * PipSize
You can use the variable consolidation to detect a range.
Since I don’t understand it right now… what could I do with this value? Go to the market or stay away?
consolidation will be true when a range is detected.
You decide what to, if you want to trade a range, then enter at market, while you won’t enter if you are looking for a trend.
I only trade H1 breakout. So, I’m trying to avoid that my system get caught in a range and either have to have a large SL below the low of the range or have a high probability that a fairly narrow SL get hit frequently.