Download MetaTrader 5
To add comments, please log in or register
You can test an application before buying it. Find out how to do that!
finitemonk1
14
finitemonk1 2016.08.27 11:45 

Hi, this is my first post and my first MQL4 project - writing code for the %B indicator.

I've used a combination of copy/paste and reading both the online book, articles & a Metatrader book to write my first code.

I hope I've understood buffers and most things correctly. The compiler says there's nothing wrong.

EXCEPT it doesn't actually draw the indicator line.

I've attached the mq4 file.

_

If anyone could help that would be much appreciated. Thanks.

Files:
zbpv.3.mq4 7 kb
Carl Schreiber
5965
Carl Schreiber 2016.08.27 12:55  

(Without testing!)

I assume there is zero divide error in line 129

UpperBuffer[i]-LowerBuffer[i]

could be zero at the beginning of the chart...

finitemonk1
14
finitemonk1 2016.08.27 14:07  

OK. (Thanks for looking btw) .. Yes, my inclination was / is it's something around the area "how it starts"

I have to say that was the area I understood the least. Hmm ...

How would I get around that? Like - How could I make it "wait" until it wasn't?

finitemonk1
14
finitemonk1 2016.08.27 14:16  

' Cuz I thought this:

if(prev_calculated<1)
   {
      for(i=0; i<pBperiod; i++)
        {
         pBBuffer[i]=EMPTY_VALUE;
         BasisBuffer[i]=EMPTY_VALUE;
         UpperBuffer[i]=EMPTY_VALUE;
         LowerBuffer[i]=EMPTY_VALUE;

        }

... was the "making it wait" bit

Carl Schreiber
5965
Carl Schreiber 2016.08.27 16:55  

1) Look into the expert tab for the log entries!!

2) check not to risk zero divide like: if ( ...== 0.0) continue; // skip

finitemonk1
14
finitemonk1 2016.08.27 18:01  

Ahh, OK. Great - thank you! I didn't know that was there ... Yes, the messages I get are, e.g.: %B v.3 EURUSD, M5: zero divide in '%B v.3.mq4' (129,60)

The formula needs that, as its: %b = (price-lower)/(upper-lower)

where price = last price, lower = lower bollinger band value, upper = upper bollinger band value.


Hmm. OK. Hehe.

It can be done somehow because I see at least one other person has the %b indicator as a free download.

Do you mean by "not to risk zero divide like: if ( ...== 0.0) continue;" ... that is how to get around it? By inserting a 'continue' operator ...

finitemonk1
14
finitemonk1 2016.08.27 19:04  

So I inserted this:

//--- %b
      double UminusL;
      UminusL = (UpperBuffer[i]-LowerBuffer[i]);
      if (UminusL == 0.00) continue;
     
      pBBuffer[i]=(close[i]-LowerBuffer[i])/UminusL;

     

And it now produces a line on the indicator. it's still obviously not quite right, but thank you very much for your help.

/
To add comments, please log in or register