Indicator Ok but Ea wrong ! How to catch the good indicator value ?

 

Hello 

I would like to build my first ea based on one of my indicators. It have only one buffer.

The indicator work good. It shows 1 to open a Buy trade and -1 to open a sale trade. The rest of time it shows 0.

In my ea i want to convert 1/-1 in trade so I do that :

 

My problem it's that  wrong. When i see 'Un' It s never the good value.

Where is my error.  How to catch the good value ?

 

Thanks for your help 

if(isNewBar()) // work good

   {

   double Un = iCustom(NULL,0,"001",0,0); 

   Print(TimeToStr(Time[0],TIME_DATE|TIME_SECONDS),"      ",Un);

      if( Un == 1)

      {

         CloseTrade();

         OpenBuy();

      }

      if( Un == -1)

      {

        CloseTrade();

         OpenSell();

      }

   }
 

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Detailed explanation of iCustom - MQL4 forum
  3. It s never the good value.
    Is meaning less - no mind readers here. Post the values. Attach the indicator. What is GetLastError()

  4. Try Symbol(), Period.
    iCustom(NULL,0,"001",0,0); 
 
Nememoris:

Hello 

I would like to build my first ea based on one of my indicators. It have only one buffer.

The indicator work good. It shows 1 to open a Buy trade and -1 to open a sale trade. The rest of time it shows 0.

In my ea i want to convert 1/-1 in trade so I do that :

If your indicator doesn't repaint then there is no point checking for it's value for buffer 0 for a shift value of zero . . 

If you Indicator only sets the buffer value for bar 1 then you should use a shift of 1 with your iCustom() call . . .  you said  "one of my indicators."  so if it's your Indicator you should know how it works.  

 

Thanks

Yes its one of my indicator, a simple indicator who show when signal cross the zero line on a new candle

 if(counted_bars>0) counted_bars--;
      limit=Bars-counted_bars;
   for(int i=0; i<limit; i++)
   {
   ExtMapBuffer1[i]=0;
   
   Un = iCustom(NULL,0,"Indicator",5,9,45,0,0,3,2,i+1);
   Deux = iCustom(NULL,0,"Indicator",5,9,45,0,0,3,2,i+2);
   
   if( Un>Deux && Deux < 0 && Un > 0)
      ExtMapBuffer1[i]=1;
    if( Un<Deux && Deux > 0 && Un < 0)
    ExtMapBuffer1[i]=-1;
    
   }

 So i know i must use a shift of 0.

There s no error : 0 retourned

So if my indicator is based on a repainting indicator it may be the problem ? But when the market is off and the indicator on the chart, the indicator's value dont mouve so it doesen't repaint no ? The values are calculated and dont change no ?

 
Nememoris:

Thanks

Yes its one of my indicator, a simple indicator who show when signal cross the zero line on a new candle

 So i know i must use a shift of 0.

There s no error : 0 retourned

So if my indicator is based on a repainting indicator it may be the problem ? But when the market is off and the indicator on the chart, the indicator's value dont mouve so it doesen't repaint no ? The values are calculated and dont change no ?

Correct,  but your EA does run either as there is no tick to call start() . . .  unless you are running in the Strategy Tester,  in which case your Indicator is also running in the Strategy Tester.
Reason: