stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Algorithm to detect support and resistance
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=661
Page 1 of 1
Author:  zen4x [ Sun Jul 01, 2012 1:34 pm ]
Post subject:  Algorithm to detect support and resistance

Hello guys. I recently joined the community and I hope to become quickly productive to help others and share good trading tools with you.
I am trying to work on the process to identify support and resistance with a decent accuracy using mql4 language. I started to do some research about a criteria to adopt in order to find a level of support/resistance and I went through this article on mql4.com that seems a well made piece of code.
The article is at this url http://articles.mql4.com/360
where the creator explains the basic idea even if two more important points do not sound clear to me.
Basically following his description he talks about local minimum, radius and max-crossed level.
Can somebody be a so kind to have a look at the code if does not require too much time.
I would like to wrap that indicator in other tools to build an EA.
I am also looking at the other indicators, so if anybody has a good piece of code I am very interested to have a look at it.
Thanks a lot, Francesco.
Author:  NeoTrader [ Sun Jul 01, 2012 1:49 pm ]
Post subject:  Re: Algorithm to detect support and resistance

hi zen4x and welcome to our beloved community...

check this Thread from slipshod where he develops a indicator for support & resistance...maybe you can get something out of his source or contact him for further informations.

happy Sunday,

NeoTrader

-
Author:  zen4x [ Sun Jul 01, 2012 5:03 pm ]
Post subject:  Re: Algorithm to detect support and resistance

Hello Neo, thank you for the welcome. I will try to ask to Andrew if he can help, but I think that indicator he has written is similar to the supply and demand zones Sam Seiden teaches. Basically those levels are the areas where market made a "V" or "A". Those patterns are defined by Seiden as Rally-base-drop and Drop-base-Rally.
What I am trying to do is instead to look back to a number of bars, define the minimum and the maximum value reached from price and after that try to find common points where price struggled to go through.
It sounds easy to say a little bit more difficult to achieve. I saw the article but the code seems a bit nasty for me and the fellow enjoys to adopt a scientific language, LOL
Author:  NeoTrader [ Sun Jul 01, 2012 5:21 pm ]
Post subject:  Re: Algorithm to detect support and resistance

hi zen4x,

I think you're right with your assumption that this indicator is more on the sight of seiden's s/d zones...at least it looks close to the other indicators like supdem and so on...
but maybe he could help you to achieve your goals since he is more into this topic...

happy Sunday,

NeoTrader
Author:  garyfritz [ Sun Jul 01, 2012 5:26 pm ]
Post subject:  Re: Algorithm to detect support and resistance

Francesco, take a look at squalou's S&R indicator. I think it works more like what you want.

It's posted in various places but the only one I could find was in this thread: http://www.stevehopwoodforex.com/phpBB3 ... f=24&t=128 Look for 10.1 Daily S&R Daily.mq4.
Author:  zen4x [ Sun Jul 01, 2012 10:10 pm ]
Post subject:  Re: Algorithm to detect support and resistance

Thank you Gary....I believe is not the same. I will try to keep studying the code. The problem is that I do know what is the criteria used so it makes a little bit the thing more complicated.
I attache the indicator to give you an idea, I think it's a good piece of software to use in any EA.


P.S: I am very happy to be part of this community, very cool personalities in here ;)
Author:  zen4x [ Tue Jul 03, 2012 4:56 pm ]
Post subject:  Re: Algorithm to detect support and resistance

I made the following considerations

1 - S/R is a price level that struggled to break a pre-existing range

2 - Has been retouched a number of times (to set as paramenter) but at least 2 or more times

3 - Scan the chart for X bars and to find min and max value within X bars

4 - Loop from the minimum price to the maximum price using step increase parameter

5 - I used the high of the candles to check if they were within a range +/- range (another parameter to set)

Code: Select all

int commonPoint;
   int minLevel, maxLevel;
   double highest, lowest, stepIncrement, tolerance, high;
   double storeLevel[];
   ///ArrayResize(storeLevel, loopback);
   
   minLevel = iLowest(Symbol(), Period(), MODE_LOW, loopback, 0);
   maxLevel = iHighest(Symbol(), Period(), MODE_HIGH, loopback, 0);
   highest = iHigh(Symbol(), Period(), maxLevel);
   lowest = iLow(Symbol(), Period(), minLevel);
  
   //Print("max: " + highest + " min: " + lowest);
   stepIncrement = 0.0005;
   tolerance = 0.0002;
   static double tmp;
   tmp = 0.0;
   
   
   for (double actPrice = lowest; actPrice <= highest; actPrice += stepIncrement) {
   
      
      for (int i = 1; i <= loopback; i++) {
         //do some stuff here...
         high = iHigh(Symbol(), Period(), i);
         double topRange, bottomRange;
         /**  if is the first value tmp stores the first high encountered until that moment **/
         if (tmp == 0) {
            tmp = high;
         } else {
            //define a buffer adding a subtracting from tmp to check if the new high is within that value
            topRange = tmp + tolerance;
            bottomRange = tmp - tolerance;
            
            if (high <= topRange && high >= bottomRange) {
               commonPoint++;
            }
         }
         //if has been touched at least three times reset common point
         //tmp goes to the new high value to keep looping
         if (commonPoint == 3) {
            commonPoint = 0;
            tmp = high;
            ///Print("valore tmp: " + tmp);
            storeLevel[i] = tmp;
         }
      }
   }
At the moment the big problem is that I should filter the values that too close to each other.
Any suggestion ?
All times are UTC Page 1 of 1