public MFI(Bars bars, int period, string description) public static MFI Series(Bars bars, int period)
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 ); } } } }