Custom indicator from a chosen timeframe

 

Hi,

This is my first post, so welcome everyone!

 I'm trying to develop a set of custom indicators based on another custom indicator. The custom indicator I want to use is similar to RSI.

What I want to do is to check if RSI is below 30 on H1 timeframe. And if it is I want to draw a blue line/ blue symbol above chart on every timeframe. So when I'm looking at M15 I know right away what is the status of RSI on the H1 interval.

This code looks super easy, but I encounter some strange behavior. For example sometimes two different symbols drawn at the same place. But what is worst sometimes I have to switch between intervals to fix my indicator. What I mean, I am on M15 interval I attach my indicator and it shows incorrect values. I switch to H1 and back to M15 and suddenly all looks ok. The third weird behavior is that when i scroll back to the history at some point weird things start to happen - My shapes are drawn all over the place, indicator shows totally incorrect values etc.

Maybe I should remember about something when creating indicator like this one? I want also to have  other ones that read the data from certain indicators on specific intervals D1, H4 etc.

Am I using iBarShift correctly? Or maybe I should add something here? Please have a look and I would really appreciate any suggestion. 

int counted_bars=IndicatorCounted();

// Check for errors

   if(counted_bars<0)
      return(-1);

   if(counted_bars>0)
      counted_bars--;

// how many we have to draw

   int limit=Bars-counted_bars;

//just to display slightly above the candle
   double shift=110.0*Point();

   for(int barNumber=0; barNumber<limit; barNumber++)
     {
      int h1BarIndex=iBarShift(NULL,PERIOD_H1,Time[barNumber]);

      int h1Direction=getH1Direction(h1BarIndex);
// what happens inside of the function above is a call to iCustom with h1BarIndex and 

      if(h1Direction==GOING_DOWN)

        {
         arrowDown[barNumber]=High[barNumber]+shift;
        }

      else if(h1Direction==GOING_UP)
        {
         arrowUp[barNumber]=Low[barNumber]-shift;
        }

      else if(h1Direction==NOTHING)
        {
         arrowNothing[barNumber]=Low[barNumber]-shift;
        }
     }

   return(rates_total); 

 
Are arrowUP etc buffers?
 
Keith Watford:
Are arrowUP etc buffers?

Yes + the code in my first post is in onCalculate method

 

double arrowUp[];
double arrowDown[];
double arrowNothing[];

int OnInit()
  {
   SetIndexStyle(0,DRAW_ARROW,NULL,1);
   SetIndexArrow(0,233);
   SetIndexBuffer(0,arrowUp);

   SetIndexStyle(1,DRAW_ARROW,NULL,1);
   SetIndexArrow(1,234);
   SetIndexBuffer(1,arrowDown);

   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,191);
   SetIndexBuffer(2,arrowNothing);

   return(INIT_SUCCEEDED);
  }
 
dmdamiyo:

Hi,

This is my first post, so welcome everyone!

 I'm trying to develop a set of custom indicators based on another custom indicator. The custom indicator I want to use is similar to RSI.

What I want to do is to check if RSI is below 30 on H1 timeframe. And if it is I want to draw a blue line/ blue symbol above chart on every timeframe. So when I'm looking at M15 I know right away what is the status of RSI on the H1 interval.

This code looks super easy, but I encounter some strange behavior. For example sometimes two different symbols drawn at the same place. But what is worst sometimes I have to switch between intervals to fix my indicator. What I mean, I am on M15 interval I attach my indicator and it shows incorrect values. I switch to H1 and back to M15 and suddenly all looks ok. The third weird behavior is that when i scroll back to the history at some point weird things start to happen - My shapes are drawn all over the place, indicator shows totally incorrect values etc.

Maybe I should remember about something when creating indicator like this one? I want also to have  other ones that read the data from certain indicators on specific intervals D1, H4 etc.

Am I using iBarShift correctly? Or maybe I should add something here? Please have a look and I would really appreciate any suggestion. 

You have to reset your buffers when counted_bars is 0.

 
Alain Verleyen:

You have to reset your buffers when counted_bars is 0.

Thanks, but what do you mean by that? I don't see it in the examples from book.mql4.com. Also the custom indicators I use don't reset the arrays. 

What I now see in the examples is the usage of "History". I am yet to understand what "too many bars" means. 

if (i<History-1)                 // If too many bars ..

 
dmdamiyo:

Thanks, but what do you mean by that? I don't see it in the examples from book.mql4.com. Also the custom indicators I use don't reset the arrays. 

 

They should ;-)

Try it :

  if(counted_bars==0)
    {
     ArrayInitialize(arrowUp,EMPTY_VALUE);
     ArrayInitialize(arrowDown,EMPTY_VALUE);
     ArrayInitialize(arrowNothing,EMPTY_VALUE);
    }
 

Hi Alain,

looks like it helped with some of the issues - when I scroll back I no longer see my symbols all over the place!

Thank you very much:)

Reason: