KF_Mtf_MA free

by gmkenneyy in category Trend at 10/11/2022
Description

Gives you the ability to supper-impose a moving average line of a higher timeframe onto the current chart.

The screen shot below shows the moving average line of the H4 chart on a H1 chart - enjoy!!!

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 cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
    public enum DSTypeE
    {
        OpenPrices,
        ClosePrices,
        HighPrices,
        LowPrices,
        MedianPrices,
        TypicalPrices,
        WeightedPrices
    }

    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class KF_Mtf_MA : Indicator
    {
        #region Settings

        [Parameter("MaType", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }

        [Parameter("Period", DefaultValue = 200)]
        public int Period { get; set; }

        [Parameter("DsType", DefaultValue = DSTypeE.ClosePrices)]
        public DSTypeE DsType { get; set; }

        [Parameter("Timeframe", DefaultValue = "Hour4")]
        public TimeFrame Timeframe { get; set; }

        #endregion


        [Output("Result", LineColor = "Chartreuse", Thickness = 4, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries Result { get; set; }


        private MovingAverage _c2M;

        private Bars _c2;
        private bool extraBarsFetched = false;


        protected override void Initialize()
        {
            _c2 = Timeframe == Chart.TimeFrame ? Bars : MarketData.GetBars(Timeframe);

            if(_c2.TimeFrame != Chart.TimeFrame) while (_c2.LoadMoreHistory() > 0) { };

            switch (DsType)
            {
                case DSTypeE.OpenPrices:
                    _c2M = Indicators.MovingAverage(_c2.OpenPrices, Period, MaType);
                    break;
                case DSTypeE.HighPrices:
                    _c2M = Indicators.MovingAverage(_c2.HighPrices, Period, MaType);
                    break;
                case DSTypeE.LowPrices:
                    _c2M = Indicators.MovingAverage(_c2.LowPrices, Period, MaType);
                    break;
                case DSTypeE.TypicalPrices:
                    _c2M = Indicators.MovingAverage(_c2.TypicalPrices, Period, MaType);
                    break;
                case DSTypeE.WeightedPrices:
                    _c2M = Indicators.MovingAverage(_c2.WeightedPrices, Period, MaType);
                    break;
                default:
                    _c2M = Indicators.MovingAverage(_c2.ClosePrices, Period, MaType);
                    break;
            }
        }

        public override void Calculate(int index)
        {
            var index2 = _c2.TimeFrame == Chart.TimeFrame ? index : _c2.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
            if (index2 < 0)
            {
                return;
            }

            _c2M.Calculate(0);

            Result[index] = _c2M.Result[index2];

            var tmp2 = _c2.TimeFrame == Chart.TimeFrame ? index - 1 : _c2.OpenTimes.GetIndexByTime(Bars.OpenTimes[index - 1]);

            int lastIdx1 = Bars.OpenTimes.GetIndexByTime(_c2.OpenTimes[index2]);
            int lastIdx2 = Bars.OpenTimes.GetIndexByTime(_c2.OpenTimes[tmp2]);
            if (lastIdx1 == lastIdx2 && _c2.TimeFrame != Chart.TimeFrame)
            {
                Result[index - 1] = double.NaN;
            }
        }
    }
}
Comments

wardrose4472902 - November 10, 2022 @ 19:17

Very great and useful post. I appreciate you creating this blog because it has been really beneficial to  cookie clicker

gosoc37766 - November 15, 2022 @ 19:56

I can do my homework on time, I can. I'm grateful that this website called https://uk.eliteassignmenthelp.com/assignment-writers has my back. I now find it impossible to fathom functioning without this!

vasquezspears5355093 - November 17, 2022 @ 09:41

Continue to create stuff that is helpful and interesting; I like reading what you've written and am impressed with the quality of your website rolling ball 3d

asshancuc - November 19, 2022 @ 04:42

I'm writing on this topic these days, baccarat online but I have stopped writing because there is no reference material. Then I accidentally found your article. I can refer to a variety of materials, so I think the work I was preparing will work! Thank you for your efforts. 

0