My indicator

 

Anyone help me to identify problem with my indicator.

As in the picture, the left red circle is false signal happen when begin new bar.

After I refresh the indicator back to normal as in the right red circle.



false signal

 
prothemeus:

Anyone help me to identify problem with my indicator.

As in the picture, the left red circle is false signal happen when begin new bar.

After I refresh the indicator back to normal as in the right red circle.


You have a bug in your code . . . .  take a look at line 23.
 

Below is head of start function.

-----------------------

   int counted_bars = IndicatorCounted();
   int i,limit,num,k,m;
 
   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;

         limit = MathMin(Bars-counted_bars,Bars);

-------------------

Is that ok?

 

  1. For large amounts of code, attach it
  2. You should always count down. If one buffer depends on another, you must count down to do it in one pass. Alternatively, must use multiple passes.
  3. No need to decrement counted_bars: Contradictory information on IndicatorCounted() - MQL4 forum
int counted_bars = IndicatorCounted();

// If you look back on earlier bars, e.g. Moving average
// if (counted_bars < LOOK_BACK) counted_bars = LOOK_BACK;

for (int i = Bars-1-counted_bars; i>=0; i--){
   :
 
Thank you WHRoeder for recommendation. I will try it .
 

The problem was solved. Thank you very much.

But I got the other problem occur.

The value different after I refresh it. Such as before refresh is 0.2563 and after refresh  is 0.2760 etc.

As in the picture below. The Above is before refresh and below is the after refresh.



How to fix it?