Lesson 12 - Your First Indicator (Part3) - page 2

 

I still have question with IndicatorCounted().

In the function start() which is executed everytime new tick is delieved (right?),

function counted_bars = IndicatorCounted() is executed, which means counted_bars is always Bars -1, after line counted_bars--, counted_bars will be equal to Bars - 2, so pos should be equal to 2. But it seems not. What is the problem?

 

It really confirms my doubt.

I tested the values of counted_bars and Bars. The first time the function start() runs,Bars already a big number, but counted_bars is 0, so pos is a large number. After that, I found when new bar first appears,

the Bars increases by 1, the counted_bars keeps the same, so the pos is 3,

when the new tick is delievered, the pos will be 2 (Bars keeps the same, counted_bars increases by 1 but keeps the same later).

Now my question is:

Every time the new bar first appears, pos = 3, so the

ExtMapBuffer1[3], ExtMapBuffer1[2], ExtMapBuffer1[1], ExtMapBuffer1[0] will be updated, other ExtMapBuffer1 elements will keep the same.

What's the point for that???? Anybody bother to give me a hint? I hate to see the magic buried in the MQL4.

 

How does MQL4 deal with the buffer?

My guess is when Bars changes (it always increase by 1), the indicator value

for the new bar to be shown in the windows will be always ExtMapBuffer1[0], others will be rotated from low to high one-by-one???

 

The interesting thing that I found is when I remove the line

if(counted_bars > 0) counted_bars--;[/code]

The indicator still works pretty fine! So what's the point of adding the above line??? To tell you the truth, I even modify the above line to be

[code]if(counted_bars > 0) counted_bars++;

and still get the indicator works perfectly fine. (In that case, pos is generally 0, and when new bar first appears, pos will be 1).

I think now I got the answer. All corrections are WELCOME!

 

Is it codersguru or pseudoguru?

I have to agree with you Blooms.

My take on this indicator is that on the first run through, when counted_bars==0, what it needs to do is assign ExtMapBuffer1[] with a value for each Bar so they can be displayed in the window. After the first run through, when counted_bars>0, only ExtMapBuffer1[0] needs to be updated for each tick. I rewrote the code and got the exact same indicator window display as codersguru's original indicator.

REPLACE:

int start()

{

int counted_bars=IndicatorCounted();

int pos=Bars-counted_bars;

//---- check for possible errors

if (counted_bars<0) return(-1);

//---- last counted bar will be recounted

if (counted_bars>0) counted_bars--;

double dHigh , dLow , dResult;

Comment("Hi! I'm here on the main chart windows!");

//---- main calculation loop

WITH:

int counted_bars , pos;

double dHigh , dLow , dResult;

int start()

{

counted_bars=IndicatorCounted();

if(counted_bars<0) return(-1);

if(counted_bars==0) pos=Bars-1;

if(counted_bars>0) pos=0;

//---- main calculation loop

 

answers

Hi,

Is somene gone answer all these questions ?

I have some but I don't see any answers since 2006

thanks

 

IndicatorCounted ()

Hi,

How this function is called again and again.

In function start is called outside the loop meaning that only once it gives probably 0 value.

thanks

 

Another Request...

codesguru how to add 2 indicator(same levels,different setting eg.stoch 5,3,3 and stoch 20,10,20) in a window?

 

hi

heartnet:
codesguru how to add 2 indicator(same levels,different setting eg.stoch 5,3,3 and stoch 20,10,20) in a window?

go to navigator , find stochastics then drag and drop to your chart ..do this once again for second stochastics indicator

===================

Forex Indicators Collection

 

Lesson 12 - Your First Indicator (Part3)

Hi Guru,

I would like to read from lesson 1 to 12 but found a few and missing some. Can you give me a list where I can download?

Thank you very much.

Reason: