heavy processing of indicator

 

Hi Forum,

To not highjack other ppl's recent thread and more specifically: I found this Support/Resistance indicator in the Forum (props to the Author!) and I am planning to give it a try. One thing is bugging me though: the launch of the MT4 platform slows down significantly (to "Not responding" sometimes), and my resonably powerful processor's usage spikes up for a few good tens of seconds - then everything seems to be calming down and reverting to normal. I'm on build 409, Win Vista and 7.

two things :
1) does this indicator will likely affect the actual EA trading? i.e. will it generally slow down execution speed, signals and general communication with server (in which case I will only keep it on a Demo account). Or does everything actually revert to normal after this initial spike at platform boot?
2) I understand there might be quite a large amount of data & probabilities to be crunched by the source file, but still: can you think of any quick-fix suggestion for avoiding this spike in processing?

Any feedback, most wellcome. Noob here in programming - as you can tell, so bear with me! : )

Dan

 

The code is inefficient. Calculates a lot of gaussians, but only uses one. Calculates the averages window times for each bar instead of once and saving it.

Once it draws its initial run it only calculates the zero bar - should be no problem for EA. (Reduce bars on chart to lessen the initial spike)

 
WHRoeder:

The code is inefficient. Calculates a lot of gaussians, but only uses one. Calculates the averages window times for each bar instead of once and saving it.

Once it draws its initial run it only calculates the zero bar - should be no problem for EA. (Reduce bars on chart to lessen the initial spike)



thanks WHR for kindly looking into it, will consider your suggestion and report back!

 
WHRoeder:

The code is inefficient. Calculates a lot of gaussians, but only uses one. Calculates the averages window times for each bar instead of once and saving it.

Once it draws its initial run it only calculates the zero bar - should be no problem for EA. (Reduce bars on chart to lessen the initial spike)


Hello again,

OK, below is the hacked down indicator script - it will only show the last few (10) bars, that looks a bit awkward on screen but still offers a good indication so I will use this for now.

So, how would you go about improving it, eg calculating each bar once, saving it and drawing the line? I guess I am on to the broader question of how to properly write an indicator (whew), but any initial guidance // kick in the back would be most welcome ! : ))

Dan da noob!

int start()
{
   
   /*int ToCount = Bars - IndicatorCounted();*/ 
   int ToCount = 10;
   
   for (int i = ToCount - 1; i >= 0; i--)
   {
      double Max = 0;
      double Min = 1000;

      for (int j = i; j < i + WindowSize; j++)
      {
         double low = Smooth_5(PRICE_LOW, j);
         if (low < Min) Min = low;
         
         double high = Smooth_5(PRICE_HIGH, j);
         if (high > Max) Max = high;
      }
      
      Support[i] = Min;
      Resistance[i] = Max;
      /*Average[i] = (Max + Min)/2;*/
      
      Print (Support[i], "  ", Resistance[i]/*, "  ", Average[i]*/);
   }
   return(0);


}
 

On the image down (it is not much clear but) there are iMA(2,SMMA) vs SR-Rate(20,5). On the chart lines are almost identical, but only visual.

I won't kick You in the back (because you made me work -) ), here are the 3 in 1.

I've shown all screen so to be known I wrote it in linux (if it works there, I think it will work in MSWin too).


Files:
sr-gauss.mq4  5 kb
 
Dannoo007:

OK, below is the hacked down indicator script - it will only show the last few (10) bars, that looks a bit awkward on screen but still offers a good indication so I will use this for now.

So, how would you go about improving it, eg calculating each bar once, saving it and drawing the line? I guess I am on to the broader question of how to properly write an indicator

   /*int ToCount = Bars - IndicatorCounted();*/ 
   int ToCount = 10;
   
   for (int i = ToCount - 1; i >= 0; i--)

Your problem was the initial spike. Try
#define MAX_BARS 10
int counted = IndicatorCounted(),
    limit   = Bars - 1 - counted;
if (limit > MAX_BARS) limit = MAX_BARS;
for (int i = limit; i >= 0; i--)