Indicator update per tick

 

I know this has to have been answered before, but I can't find it in the forums... So on with it.


How do I make my indicator update every tick? I have an indicator that draws an arrow above and below a candle that is an inside bar. The problem is that when a new candle forms, it is an inside bar, so it gets these arrows, but as the bar ticks along the candle may not be an inside bar when it closes, but the candle will still have my arrows drawn. I do not believe it is an error in the indicator logic because when I first load the indicator, it correctly marks all of the inside bars and does not mark incorrect bars. Here is the code I use that I think is the problem.


int start() // Special function start()
{
int i, // Bar index
Counted_bars; // Number of counted bars
//--------------------------------------------------------------------
Counted_bars=IndicatorCounted(); // Number of counted bars
i=Bars-Counted_bars-1; // Index of the first uncounted
while(i>=0) // Loop for uncounted bars


Now when I look at it now, it is only looping for the bars that have not been counted. But I don't really know how to change this. Anyway, thats where I think the problem is. Here is the rest of the code.


int start() // Special function start()
{
int i, // Bar index
Counted_bars; // Number of counted bars
//--------------------------------------------------------------------
Counted_bars=IndicatorCounted(); // Number of counted bars
i=Bars-Counted_bars-1; // Index of the first uncounted
while(i>=0) // Loop for uncounted bars
{
if (High[i]<High[i+1] && Low[i]>Low[i+1]) // check if the high's and low's are within each other
{
if (MathAbs(Open[i]-Close[i])<MathAbs(Open[i+1]-Close[i+1])) // check if the recent bar is smaller than the previous
{
if (Open[i+1]>Close[i+1]) // check if the open of the previous bar is above the close
{
if (Close[i]<=Open[i+1]) // check if the recent bar is within the previous
{
Buf_0[i]=High[i]+5*Point; // Value of 0 buffer on i bar
Buf_1[i]=Low[i]-5*Point; // Value of 1st buffer on i bar
}
}
else if (Open[i+1]<Close[i+1]) // check if the open of the previous bar is below the close
{
if (Close[i]>=Open[i+1]) // chekc if the recent bar is within the previous
{
Buf_0[i]=High[i]+5*Point; // Value of 0 buffer on i bar
Buf_1[i]=Low[i]-5*Point; // Value of 1st buffer on i bar
}
}
}
}
i--; // Calculating index of the next bar
}
//--------------------------------------------------------------------
return; // Exit the special funct. start()
}


(yes I know this code does not check if the open of the inside bar is within the previous candle. I am allowing fro price gaps.)


Any help you guys can offer will be greatly appreciated.


Thank you

 

How do I make my indicator update every tick?

use Close[0] price in the calculation.

 
phy:

How do I make my indicator update every tick?

use Close[0] price in the calculation.

while(i>=0) // Loop for uncounted bars

i will be equal to 0 last. At that point, the while loop will complete at a value of 0(unless I am wrong about a while loop works, I am new to programming...) then terminate.


Maybe I do not know what calculation you are referring to???

 

Your indicator runs on every tick already if i >= 0

Check value of i if there is no update.

 
phy:

Your indicator runs on every tick already if i >= 0

Check value of i if there is no update.

Thank you phy. The problem was how I initialised i.

 

Hi guys,


ikone & phy: according to your problem... could you please write the proper code now - to resolve this problem? I think that I have the very common subject like your...


Regards,

Puncher

 

The problem is very easy to solve. You just check on the MT4 menu "Scroll the chart to the end on tick incoming" at the top of the window. If this button is not clicked, the indicator will not paint the new arrow on the new market tick.


Reason: