Histogram indicator keeps recalculating

 
Removed!

Hi guys,


Ive created a historgram indicator that basically prints a colour when price is in an uptrend/downtrend, and out of a set of bands like BB bands.


After a couple of bars if i refresh the chart, the histogram changes in colours and is recalculating or redrawing. I have gone through my code alongside the mql4 doc

making sure i understand the code to see if i have done it right, however i cant stop this problem happening. I only need the histogram to print on the close of the current bar

and stay that colour without changing its value again. So its candle index -1 im interested in. 


I beleive i the error could be around this part, //--- main loop

   for(int i = limit-1; i >= 0; i--)

      {

      if (i >= MathMin(LookBackBars-1, rates_total-1-50)) continue;


but i have attached the bulk of the code. 


Thank you 

 
  1. Buffer7[i] = Bid; //Set indicator value at Price

    Your "believe" is wrong. Bid is the price of bar zero. Shouldn't you be drawing using a price of bar i?

  2. if (i >= MathMin(LookBackBars-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation 
    
    Do your lookbacks correctly. Your lookback, per iCustom(...Shift+i) is Shift.

  3.  if(iCustom(NULL, PERIOD_CURRENT, "MiracleBand", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, true, true, false, true, true, true, false, false, 3, Shift+i)

  4. You should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum

 
whroeder1:
  1. Your "believe" is wrong. Bid is the price of bar zero. Shouldn't you be drawing using a price of bar i?

  2. Do your lookbacks correctly. Your lookback, per iCustom(...Shift+i) is Shift.

  3. You should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum

Thank you for your fast reply, 


I will get to work trying to make those changes, in regards to the bid when drawing the histogram, the prices arnt important as im aiming for this style of histogram rather then like a macd style. 


 
CtCapitalFx:

Thank you for your fast reply, 


I will get to work trying to make those changes, in regards to the bid when drawing the histogram, the prices arnt important as im aiming for this style of histogram rather then like a macd style. 



Solved, do not use a recalculating indicator! 

Reason: