Page 1 of 1

MFI - I don't know what I am doing wrong

Posted: Mon Oct 18, 2021 12:12 pm
by zwp
Hi Guys,
completely new to coding, so have a patience with me :wink:
I have written super simple scrip to indicate overbought levels of MFI.
The problem is that:
  • It doesn't indicate all OB levels - only some
  • it indicates some levels which are actually not OB
any idea?

Download link for pic
https://we.tl/t-e84aMeViLJ

Script:

//@version=4
study(title="[zwp]=03", overlay=true)

//get input
mfi = mfi(close,14)
ob = mfi >= 80

//to the graph
plotshape(ob, text="OB", color=color.new(color.red, 0))
bgcolor(ob ? color.new(color.aqua,70) : na)

Re: MFI - I don't know what I am doing wrong

Posted: Tue Oct 19, 2021 11:21 pm
by Deep-Wave
Hi zwp,

from your picture i guess you plotted to built in MFI indicator at the bottom of your chart right?
If you check the source code of that indicator you will see that in that script the hlc3 ((high + low + close)/3) is used for the calculation and you used the close price in your script. That its why you see a visual discrepancy between the two scripts on the charts. If you adjust either of the sources it will be in sync.

Hope this helps you out, best of luck with your coding!

Cheers :cool:

Re: MFI - I don't know what I am doing wrong

Posted: Wed Oct 20, 2021 8:36 am
by zwp
Big thanks. I think i understand. Let me try!

Re: MFI - I don't know what I am doing wrong

Posted: Tue Oct 26, 2021 6:35 pm
by zwp
FYI: worked. thank you.