MFI

by afhacker in category Oscilator at 18/09/2016
Description

This indicator shows the MFI bot signals in dots style on your chart, If you are a manual discretionary trader and want to use your chart reading skills for filtering some signals then it's for you.

Download
264 downloads
How to install
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Threading.Tasks;
using AlertWindow;



/*

Version 1.0
Developed by afhacker (Ahmad Noman Musleh)
Email : afhackermubasher@gmail.com

*/


namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class MFI : Indicator
    {
        [Parameter("Alert", DefaultValue = true)]
        public bool alert { get; set; }

        [Parameter("Alert Sound File", DefaultValue = "C:\\Windows\\Media\\notify.wav")]
        public string alertSoundFile { get; set; }

        [Parameter("MFI Periods", DefaultValue = 20)]
        public int moneyFlowIndexPeriods { get; set; }

        [Parameter("Buy Above", DefaultValue = 40)]
        public int moneyFlowIndexBuy { get; set; }

        [Parameter("Sell Below", DefaultValue = 70)]
        public int moneyFlowIndexSell { get; set; }

        [Parameter("Dots Space(pip)", DefaultValue = 1)]
        public int dotsSpace { get; set; }

        [Parameter("Time Filter?", DefaultValue = false)]
        public bool timeFilter { get; set; }

        [Parameter("Start Hour", DefaultValue = 7, MinValue = 0, MaxValue = 23)]
        public int startHour { get; set; }

        [Parameter("End Hour", DefaultValue = 15, MinValue = 0, MaxValue = 23)]
        public int endHour { get; set; }

        [Output("Buy Dot", Color = Colors.Magenta, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries BuyDot { get; set; }

        [Output("Sell Dot", Color = Colors.Magenta, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries SellDot { get; set; }



        private int signalIndex;

        private Alert _alarm;

        private HeikenAshi ha;

        private MoneyFlowIndex moneyFlowIndex;

        protected override void Initialize()
        {
            _alarm = new Alert("MFI", Symbol.Code);
            signalIndex = 0;

            ha = Indicators.GetIndicator<HeikenAshi>(1);
            moneyFlowIndex = Indicators.MoneyFlowIndex(moneyFlowIndexPeriods);
        }

        public override void Calculate(int index)
        {
            bool heikenAshiOk = false;
            bool bullishSignal = false;
            bool bearishSignal = false;
            if (ha.Close.Last(1) > ha.Open.Last(1) && ha.Close.Last(2) < ha.Open.Last(2))
            {
                heikenAshiOk = true;
                bullishSignal = true;
            }
            else if (ha.Close.Last(1) < ha.Open.Last(1) && ha.Close.Last(2) > ha.Open.Last(2))
            {
                heikenAshiOk = true;
                bearishSignal = true;

            }


            // Money Flow Index Filter
            bool moneyFlowIndexOk = false;
            if (bullishSignal && moneyFlowIndex.Result.Last(1) > moneyFlowIndexBuy && moneyFlowIndex.Result.Last(2) < moneyFlowIndexBuy)
            {
                moneyFlowIndexOk = true;
            }
            else if (bearishSignal && moneyFlowIndex.Result.Last(1) < moneyFlowIndexSell && moneyFlowIndex.Result.Last(2) > moneyFlowIndexSell)
            {
                moneyFlowIndexOk = true;
            }



            // Time Filter
            bool isTimeCorrect = false;
            if (timeFilter)
                isTimeCorrect = timeFilterCheck();
            else
                isTimeCorrect = true;



            if (heikenAshiOk && moneyFlowIndexOk && isTimeCorrect)
            {
                if (bullishSignal)
                    BuyDot[index - 1] = MarketSeries.Low[index - 1] - (Symbol.PipSize * dotsSpace);
                else if (bearishSignal)
                    SellDot[index - 1] = MarketSeries.High[index - 1] + (Symbol.PipSize * dotsSpace);


                if (alert && IsLastBar && IsRealTime && signalIndex != index)
                {
                    string SignalType = "";
                    if (bullishSignal)
                    {
                        SignalType = "Buy";
                    }
                    else if (bearishSignal)
                    {
                        SignalType = "Sell";
                    }

                    Notifications.PlaySound(alertSoundFile);
                    Task showForm = Task.Factory.StartNew(() => { _alarm.Trigger(SignalType, Server.Time); });
                }

                signalIndex = index;
            }
        }


        // Checking the opening time of candle
        private bool timeFilterCheck()
        {
            bool timeOk = false;
            if (timeFilter && MarketSeries.OpenTime.Last(1).Hour >= startHour && MarketSeries.OpenTime.Last(1).Hour <= endHour)
                timeOk = true;
            else if (!timeFilter)
                timeOk = true;


            if (timeOk)
                return true;
            else
                return false;
        }

    }
}
Comments
0