PO Indicator

by Tatsuya in category Trend at 08/04/2019
Description

Using 4 MAs to indentify the direction of the trend.

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class POIndicator : Indicator
    {
        [Parameter(DefaultValue = 10)]
        public int MAPeriod1 { get; set; }
        [Parameter(DefaultValue = 20)]
        public int MAPeriod2 { get; set; }
        [Parameter(DefaultValue = 40)]
        public int MAPeriod3 { get; set; }
        [Parameter(DefaultValue = 80)]
        public int MAPeriod4 { get; set; }

        [Output("MA1", LineColor = "White")]
        public IndicatorDataSeries MA1 { get; set; }
        [Parameter("MA1 Type", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAType1 { get; set; }
        [Output("MA2", LineColor = "Yellow")]
        public IndicatorDataSeries MA2 { get; set; }
        [Parameter("MA2 Type", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAType2 { get; set; }
        [Output("MA3", LineColor = "LimeGreen")]
        public IndicatorDataSeries MA3 { get; set; }
        [Parameter("MA3 Type", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAType3 { get; set; }
        [Output("MA4", LineColor = "Magenta")]
        public IndicatorDataSeries MA4 { get; set; }
        [Parameter("MA4 Type", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAType4 { get; set; }

        [Parameter("Up Color", DefaultValue = "White")]
        public string UpColorStr { get; set; }

        [Parameter("Down Color", DefaultValue = "Black")]
        public string DownColorStr { get; set; }

        [Parameter("PO Up Color", DefaultValue = "Red")]
        public string PoUpColorStr { get; set; }

        [Parameter("PO Down Color", DefaultValue = "Blue")]
        public string PoDownColorStr { get; set; }

        private MovingAverage ma1;
        private MovingAverage ma2;
        private MovingAverage ma3;
        private MovingAverage ma4;

        private Color UpColor;
        private Color DownColor;
        private Color PoUpColor;
        private Color PoDownColor;

        protected override void Initialize()
        {
            ma1 = Indicators.MovingAverage(MarketSeries.Close, MAPeriod1, MAType1);
            ma2 = Indicators.MovingAverage(MarketSeries.Close, MAPeriod2, MAType2);
            ma3 = Indicators.MovingAverage(MarketSeries.Close, MAPeriod3, MAType3);
            ma4 = Indicators.MovingAverage(MarketSeries.Close, MAPeriod4, MAType4);

            UpColor = Color.FromName(UpColorStr);
            DownColor = Color.FromName(DownColorStr);
            PoUpColor = Color.FromName(PoUpColorStr);
            PoDownColor = Color.FromName(PoDownColorStr);
        }

        public override void Calculate(int index)
        {
            MA1[index] = ma1.Result[index];
            MA2[index] = ma2.Result[index];
            MA3[index] = ma3.Result[index];
            MA4[index] = ma4.Result[index];

            if ((ma1.Result[index] > ma2.Result[index]) && (ma2.Result[index] > ma3.Result[index]) && (ma3.Result[index] > ma4.Result[index]))
            {
                Chart.DrawTrendLine("PO" + index, index, MarketSeries.Open[index], index, MarketSeries.Close[index], PoUpColor, 5, LineStyle.Solid);

                if (MarketSeries.Close[index] > MarketSeries.Open[index])
                {
                    Chart.DrawTrendLine("POHighUp" + index, index, MarketSeries.High[index], index, MarketSeries.Open[index], PoUpColor, 1, LineStyle.Solid);
                    Chart.DrawTrendLine("POHighDown" + index, index, MarketSeries.Low[index], index, MarketSeries.Close[index], PoUpColor, 1, LineStyle.Solid);
                }
                else
                {
                    Chart.DrawTrendLine("POHighUp" + index, index, MarketSeries.High[index], index, MarketSeries.Open[index], PoDownColor, 1, LineStyle.Solid);
                    Chart.DrawTrendLine("POHighDown" + index, index, MarketSeries.Low[index], index, MarketSeries.Close[index], PoDownColor, 1, LineStyle.Solid);
                }

                return;
            }
            else if ((ma1.Result[index] < ma2.Result[index]) && (ma2.Result[index] < ma3.Result[index]) && (ma3.Result[index] < ma4.Result[index]))
            {
                Chart.DrawTrendLine("PO" + index, index, MarketSeries.Open[index], index, MarketSeries.Close[index], PoDownColor, 5, LineStyle.Solid);

                if (MarketSeries.Close[index] < MarketSeries.Open[index])
                {
                    Chart.DrawTrendLine("POHighUp" + index, index, MarketSeries.High[index], index, MarketSeries.Close[index], PoDownColor, 1, LineStyle.Solid);
                    Chart.DrawTrendLine("POHighDown" + index, index, MarketSeries.Low[index], index, MarketSeries.Open[index], PoDownColor, 1, LineStyle.Solid);
                }
                else
                {
                    Chart.DrawTrendLine("POHighUp" + index, index, MarketSeries.High[index], index, MarketSeries.Close[index], PoUpColor, 1, LineStyle.Solid);
                    Chart.DrawTrendLine("POHighDown" + index, index, MarketSeries.Low[index], index, MarketSeries.Open[index], PoUpColor, 1, LineStyle.Solid);
                }

                return;
            }

            if (MarketSeries.Close[index] < MarketSeries.Open[index])
            {
                Chart.DrawTrendLine("PO" + index, index, MarketSeries.Open[index], index, MarketSeries.Close[index], DownColor, 5, LineStyle.Solid);
                Chart.DrawTrendLine("POHighUp" + index, index, MarketSeries.High[index], index, MarketSeries.Open[index], DownColor, 1, LineStyle.Solid);
                Chart.DrawTrendLine("POHighDown" + index, index, MarketSeries.Low[index], index, MarketSeries.Close[index], DownColor, 1, LineStyle.Solid);
            }
            else
            {
                Chart.DrawTrendLine("PO" + index, index, MarketSeries.Open[index], index, MarketSeries.Close[index], UpColor, 5, LineStyle.Solid);
                Chart.DrawTrendLine("POHighUp" + index, index, MarketSeries.High[index], index, MarketSeries.Open[index], UpColor, 1, LineStyle.Solid);
                Chart.DrawTrendLine("POHighDown" + index, index, MarketSeries.Low[index], index, MarketSeries.Close[index], UpColor, 1, LineStyle.Solid);
            }
        }
    }
}
Comments

fuchslochulli - April 16, 2019 @ 20:27

wow, really good indicator. Easy to understand and to the point. Ty

fuchslochulli - April 16, 2019 @ 20:35

I use Better Volume Paint Bar, and together with this one is giving me more inside when should i trade.

0