Newbie needs a bit of help with Indicator

Back to topics list To post a new topic, please log in or register
avatar
5
finitemonk1 2016.08.27 13: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.

Attached files:
  zbpv.3.mq4  (6.03 KB)
avatar
2017
gooly 2016.08.27 14: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...

avatar
5
finitemonk1 2016.08.27 16: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?


avatar
5
finitemonk1 2016.08.27 16: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

avatar
2017
gooly 2016.08.27 18:55 #
 

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

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

avatar
5
finitemonk1 2016.08.27 20: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 ...

avatar
5
finitemonk1 2016.08.27 21: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.




Back to topics list  

To add comments, please log in or register