Modified on 2008/04/18 09:16 by Administrator — Categorized as: Standard Indicators


public MFI(Bars bars, int period, string description)
public static MFI Series(Bars bars, int period)

Parameter Description

bars The Bars object
period Indicator calculation period


Money Flow Index measures the flow of money into and out of a security over the specified Period. Its calculation is similar to that of the Relative Strength Index (RSI), but takes volume into account in its calculation. The indicator is calculated by accumulating positive and negative Money Flow values (see Money Flow indicator), then creating a Money Ratio. The Money Ratio is then normalized into the MFI oscillator form.



The follow steps are used to calculate Money Flow Index. See MoneyFlow for an excellent example script showing the construction of the MFI.

Money Flow = Volume x AveragePriceC

Money Flow direction: if today's average price is greater than yesterday's, then it is considered positive money flow, otherwise it is negative money flow.

Positive Money Flow = Sum all the Positive Money Flows day over specified periods. Negative Money Flow = Sum all the Negative Money Flows day over specified periods. Money Ratio = Sum of Positive Money Flow / Sum of Negative Money Flow

Money Flow Index (MFI) = 100 - ( 100 / ( 1 + Money Ratio ) )


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { /* The trading system below buys a position whenever MFI crosses below 20. It sells all open positions as soon as MFI crosses above 80. The Strategy also colors MFI bars red and green to show oversold/overbought levels. */ DataSeries mfi = MFI.Series( Bars, 14 ); ChartPane mfiPane = CreatePane( 50, true, true ); PlotSeries( mfiPane, mfi, Color.Black, WealthLab.LineStyle.Solid, 2 ); SetBarColors( Color.Silver, Color.Silver );

for(int bar = 50; bar < Bars.Count; bar++) { if( CrossUnder( bar, mfi, 20 ) ) BuyAtMarket( bar+1 ); // Let's work directly with the list of active positions if( CrossOver( bar, mfi, 80 ) ) { for( int p = ActivePositions.Count - 1; p > -1 ; p-- ) SellAtMarket( bar+1, ActivePositions[p], "MFI" ); } if( mfi[bar] < 20 ) SetSeriesBarColor( bar, mfi, Color.Red ); if( mfi[bar] > 80 ) SetSeriesBarColor( bar, mfi, Color.Green ); } } } }