FREE CODE: Finding Resistance Prices

 
I cooked up some new code because
  1. It would be cool to develop a function that returns the price of resistance
  2. I'm lame and I have nothing better to do on a Saturday than think about forex 

Plus, I think you guys will be able to improve on it. This attempts to find prices that have exhibited resistance to a particular currency over the past X periods. I'm basically doing it by creating an array of all the prices and then scrolling back through the same array and finding prices within a total band of 4 pips. The price with the greatest number of "commons" is determined to be the resistance point. It's not the greatest, but I do consider it to be a clever piece of code 

But of course, I'm sure someone here will be able to improve on it or we can improve it collectively.
Code:
//+------------------------------------------------------------------+
//| Attempts to identify points of resistance for a pair             |
//+------------------------------------------------------------------+     
double ResistanceCheck(string symbol, int charttime, int timescope)
   {
   int barscroll;
   int allhighcount;
   int allhighscroll;
   int allhighscrollsub;
   int commoncount;
   int commonhighest;
   int highcommons[];
   double allHighs[];
   double result;
   double bandtop;
   double bandbottom;
   
   //limit the number of historical bars we will look at
   allhighcount=timescope;
   //Resize the arrays to this number
   ArrayResize(allHighs,allhighcount);
   ArrayResize(highcommons,allhighcount);
   
   //Populate the first array with the highs from the previous X bars defined by timescope
   for(barscroll=0;barscroll<allhighcount;barscroll++)
      {
      allHighs[barscroll]=iHigh(symbol,charttime,barscroll);
      }
   
   //Loop through all the high prices
   for(allhighscroll=0;allhighscroll<allhighcount;allhighscroll++)
      {
      commoncount=0;
      //Create a "band" of prices two pips ABOVE and two pips BELOW the determined price
      bandtop=allHighs[allhighscroll]+(2*Point);
      bandbottom=allHighs[allhighscroll]-(2*Point);

      //Scroll through the array again and find prices that are within the band
      for(allhighscrollsub=0;allhighscrollsub<allhighcount;allhighscrollsub++)
         {
         if((allHighs[allhighscrollsub]<=bandtop) && (allHighs[allhighscrollsub]>=bandbottom))
            {
            //This variable tracks how many prices were within the band for a particular price
            commoncount++;
            }
         }
      //This array tracks all the "common" prices   
      highcommons[allhighscroll]=commoncount;
      }
   //This basically finds the POSITION within the array that contained the most common high prices i.e. resistance   
   commonhighest=ArrayMaximum(highcommons,WHOLE_ARRAY,0);
   //This actually pulls the price from the original array and returns in
   result=allHighs[commonhighest];
   return(result);
   }
__________________
 

Good code! I tested it and it works find as it is. I'll see if I get some time to tinker with the algorithm to make it run a little faster.


Keep the good work.

 
robotalfa:

Good code! I tested it and it works find as it is. I'll see if I get some time to tinker with the algorithm to make it run a little faster.


Keep the good work.

Thanx!


It's not perfect. In some backtesting, I noticed that in rare cases it can give you a support line that's ABOVE the resistance line. It mostly happens during volatile periods and fairly rare, but just thought that I'd point it out.

 
LongToBeFree:

Thanx!


It's not perfect. In some backtesting, I noticed that in rare cases it can give you a support line that's ABOVE the resistance line. It mostly happens during volatile periods and fairly rare, but just thought that I'd point it out.

Noted. Thanx for pointing that out.