zwp
Pine Script Scholar
Pine Script Scholar
Posts: 17
Joined: September 18th, 2021
Contact: TradingView Profile

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

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)

Deep-Wave
Pine Script Master
Pine Script Master
Posts: 44
Joined: September 4th, 2020
Contact: TradingView Profile

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

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:

zwp
Pine Script Scholar
Pine Script Scholar
Posts: 17
Joined: September 18th, 2021
Contact: TradingView Profile

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

Big thanks. I think i understand. Let me try!

zwp
Pine Script Scholar
Pine Script Scholar
Posts: 17
Joined: September 18th, 2021
Contact: TradingView Profile

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

FYI: worked. thank you.

Return to “Share Your Scripts”