Arrow indicator don't work!

 

Hello, I tried to modify an indicator with my parameters. I want an up arrow when MACD < 0 and become greater than 0 and vise versa.


I juste modify iMA with my iMACD. Now there's any arrow on the chart.


Thank's

pgforex

//+------------------------------------------------------------------+
//|                                                  MACD_Signal.mq4 |
//|                      Copyright © 2009, Pascal Gignac             |
//|                                                                  |
//+------------------------------------------------------------------+

   
#property copyright "Copyright © 2009, Pascal Gignac"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 SpringGreen
#property indicator_color2 Red

double CrossUp[];
double CrossDown[];
extern int FasterEMA = 5;
extern int SlowerEMA = 10;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double macdPrev, macd;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
   
   for(i = 0; i <= limit; i++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++) {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;
      
      macdPrev = iMACD(NULL,0,5,35,5,PRICE_CLOSE,MODE_MAIN,1);
      macd = iMACD(NULL,0,5,35,5,PRICE_CLOSE,MODE_MAIN,0);
           
      if ((macdPrev < 0.0000) && (macd > 0.0000)) {
         CrossUp[i] = Low[i] - Range*0.5;
      }
      else if ((macdPrev > 0.0000) && (macd < 0.0000)) {
         CrossDown[i] = High[i] + Range*0.5;
      }
   }
   return(0);
}
 

at least in init you have to set IndicatorBuffers(2)

and are you sure that your calculation of range and the resulting drawingposition is in the visible area of the chart ?



 

Seriously I don't know. With th original code, the drawingposition are ok.


I've change:

CrossUp[i] = Low[i] - Range*0.5;

With:

CrossUp[i] = Low[i] - 5*Point;

Same bug.


I've juste change iMA of the original code with iMACD.


And 2 buffer are set.

   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp); //0 = Buffer1
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown); //1 = Buffer2

 

i have seen that the numbers of buffers is set as property.

next time use the strategytester please over a longer period in the visible mode until you see some results on the chart

the code works, if there are no arrows visible the reason is simple:

((macdPrev < 0) && (macd > 0))==false;
//or
((macdPrev > 0) && (macd < 0))==false;
 

How to test an indicator with strategytester? It's not juste for EA?


I have a print screen of my chart. I can't see anything.



 

i have already wasted my time for you with a non-existing problem.

instead of you take my advise and say thanks you think you know it better than me.

i think the problem is between chair and keyboard.

 

Ok thank's for your help. The problem is maybe me. I just show you a print screen of my result.

I don't know why but it's not work for me.


I think than a forum is create to help people with their problem.

Your last comment don't help anybody.


Thank's again!

pgforex

 

arrows
 

Ok I try again!


Thank's

pgforex

 

"How to test an indicator with strategytester? It's not juste for EA?"


how to develop an indicator WITHOUT strategy tester ?

waiting on the next tick to come and stopping developin at the weekend ?


the usage is simple, test an EA in visual mode and attach the indicator as usual by drag and drop.


sometimes i think that a lot of questions here in the forum are based on "not reading the manual"

 

Thank's to explain how to test indicator with strategytester. My indicator work now. Normaly when I add

an indicator on live chart, I can see the signal on previous bars. Not with my code. With my code I see a

signal only next time when condition are meet.


I'm not sure, I think is due to the next code. Tell me if it's right. This code calculate only the 9 previous

bars.

for (counter=i ;counter<=i+9;counter++)
Reason: