Topic: Swing Highs or Lows as an entry condition

Hi all,

First I want to thank Popov and all the people involved in the development of this great software.

I'm not an expert programmer but I'm capable of creating my own MT4 indicators and now I'm starting to create indicators for FSB.

My first indicator open positions when the most recent swing high or low is reached, at the moment it only gives FSB and opening and closing point for the position.

My logic for a swing high is a candle which high is above the closest two on both sides (inverse logic applies for a swing low). So you have to wait for at least 2 candles before getting a confirmation that you have a valid swing high/low.

I need some help to solve a problem, when a swing is confirmed, the tester goes back to the swing candle and opens a position there (so far I can avoid the problem by adding 1 pip to the vertical shift but could be better without the issue).

That's it, I'll appreciate all the suggestions/complains you have.

Thanks a lot.

Re: Swing Highs or Lows as an entry condition

Hi, I made it just thinking about the backtester, I really think it'll have problems with live market as it is; I'll test it and modify if needed.

Re: Swing Highs or Lows as an entry condition

You might try the Fractal indicator, built in with FSB. It does the same thing of looking for a high that is higher than the previous and next 2 bars. It has several more cases or types of swings, but you could customize it by removing the extra cases you don't want by commenting out Fractal Types 2-7.

For the Recent Swing High Low indicator, I think the problem is at line 91-92 and 101-102:

``````                    if (High[iBar] >= High[iBar - 1] && High[iBar] > High[iBar - 2] &&  // Check 2 candles to the left
High[iBar] >= High[iBar + 1] && High[iBar] > High[iBar + 2])    // Check 2 candles to the right
{``````

iBar+1 and iBar+2 is like saying "look at the current bar and compare against the 2 bars in the future", which the indicator cannot know in real trading. Instead, the swing high (or swing low) should be 3 bars in the past, so we can be sure the next 2 bars are also in the past and can be known.
This might work, try replacing the above with:

``````                    if (High[iBar-3] >= High[iBar - 4] && High[iBar-3] > High[iBar - 5] &&  // Check 2 candles to the left
High[iBar-3] >= High[iBar - 2] && High[iBar -3] > High[iBar -1])    // Check 2 candles to the right
{``````

Then, when the high price is set, the entry signal will start on the bar after the formation, not sent back to the bar with the swing high or low. If the entry signal lags too much, try [-0, -1, .. -4] instead of [-1, -2, .. -5], then be careful in testing that it is not giving and entering signals before info can be known.

Also, line 75, change iFirstBar = 3 to something higher (eg 10), and line 81, from "for (int iBar = 1" to "for (int iBar = iFirstBar". If not, you may get an "Out of Range error", where you get a dialog box asking "quit or continue".

Hope that helps.

Re: Swing Highs or Lows as an entry condition

Thanks a lot for all the feedback, I've tested too and I'll modify the code this sunday to make it work as it should be.

Again, thank you very much for the posts and the suggestions.

Re: Swing Highs or Lows as an entry condition

Ok, finally I made it work, one thing I wasn't aware of was that FSB first draws the indicator and then runs the test.

In the last version I was drawing the line on the candle with the swing (when it's not valid yet), now the line is being drawn only for the candles where the recent swing is valid (from the third candle after the swing has occurred).

I made a couple of tests with FST and works as intented, some orders are not opened at the exact price but that issue comes from slippage or not-fixed spread from my test broker.

Thank you very much to krog for his suggestions and to footon for his feedback, you made the indicator work.

I'm going to start testing some old strategies I had using this indicator, if I find more issues I'll update the indicator, and if I find a good strategy I'll let you know.

Thanks again

Re: Swing Highs or Lows as an entry condition

Hyoru,
Excellent job with that indicator.

I made two very small changes to it:
1. Increased the max value of the shift to +- 200 pips due to 5 digit brokers;
2. Added ToString() function in order to print the name of the indicator properly on the indicator chart.

Re: Swing Highs or Lows as an entry condition

Hyoru wrote:

Thank you very much to krog for his suggestions and to footon for his feedback, you made the indicator work.

That's great !! Happy to help out, and glad to hear it is working as expected.