Information

Username: PureForm
Member since: 10 Jun 2019
Last login: 10 Jun 2019
Status: Active

Activity

Where Created Comments
Algorithms 0 1
Forum Topics 2 8
Jobs 0 0

Last Algorithm Comments

PU
PureForm · 4 years ago

Hey, I color coded your output. No more need for the arrows and easier to read.

 

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Text;
using System.Collections.Generic;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MTFTrend : Indicator
    {
        [Parameter("Vertical Alignment", Group = "Position", DefaultValue = VerticalAlignment.Top)]
        public VerticalAlignment vAlignment { get; set; }

        [Parameter("Horizontal Alignment", Group = "Position", DefaultValue = HorizontalAlignment.Right)]
        public HorizontalAlignment hAlignment { get; set; }

        private List<Box> list;
        private string lastResult;

        protected override void Initialize()
        {
            this.list = new List<Box>();

            Bars barsM1 = MarketData.GetBars(TimeFrame.Minute);
            Bars barsM5 = MarketData.GetBars(TimeFrame.Minute5);
            Bars barsM15 = MarketData.GetBars(TimeFrame.Minute15);
            Bars barsM30 = MarketData.GetBars(TimeFrame.Minute30);
            Bars barsH1 = MarketData.GetBars(TimeFrame.Hour);
            Bars barsH4 = MarketData.GetBars(TimeFrame.Hour4);
            Bars barsD1 = MarketData.GetBars(TimeFrame.Daily);
            Bars barsW1 = MarketData.GetBars(TimeFrame.Weekly);
            Bars barsMN = MarketData.GetBars(TimeFrame.Monthly);

            list.Add(new Box("MN", "      ", Indicators.DirectionalMovementSystem(barsMN, 14), Indicators.ParabolicSAR(barsMN, 0.02, 0.2)));
            list.Add(new Box("W1", "     ", Indicators.DirectionalMovementSystem(barsW1, 14), Indicators.ParabolicSAR(barsW1, 0.02, 0.2)));

            list.Add(new Box("D1", "     ", Indicators.DirectionalMovementSystem(barsD1, 14), Indicators.ParabolicSAR(barsD1, 0.02, 0.2)));

            list.Add(new Box("H4", "    ", Indicators.DirectionalMovementSystem(barsH4, 14), Indicators.ParabolicSAR(barsH4, 0.02, 0.2)));
            list.Add(new Box("H1", "     ", Indicators.DirectionalMovementSystem(barsH1, 14), Indicators.ParabolicSAR(barsH1, 0.02, 0.2)));

            list.Add(new Box("M30", "       ", Indicators.DirectionalMovementSystem(barsM30, 14), Indicators.ParabolicSAR(barsM30, 0.02, 0.2)));

            list.Add(new Box("M15", "       ", Indicators.DirectionalMovementSystem(barsM15, 14), Indicators.ParabolicSAR(barsM15, 0.02, 0.2)));

            list.Add(new Box("M5", "     ", Indicators.DirectionalMovementSystem(barsM5, 14), Indicators.ParabolicSAR(barsM5, 0.02, 0.2)));
            list.Add(new Box("M1", "     ", Indicators.DirectionalMovementSystem(barsM1, 14), Indicators.ParabolicSAR(barsM1, 0.02, 0.2)));

            this.lastResult = "";
        }

        public override void Calculate(int index)
        {
            string sb_green = "", sb_white = "", sb_red = "";
            double price = (Symbol.Ask + Symbol.Bid) * 0.5;
            
            foreach (Box box in this.list)
            {
                bool adxBullish = true;
                bool psarBullish = true;

                if (box.adx.DIPlus.LastValue < box.adx.DIMinus.LastValue)
                {
                    adxBullish = false;
                }

                if (price < box.psar.Result.LastValue)
                {
                    psarBullish = false;
                }

                if (adxBullish && psarBullish)
                {
                    sb_green += "  " + box.label;
                    sb_red += "  " + box.empty;
                    sb_white += "  " + box.empty;
                }
                else if (!adxBullish && !psarBullish)
                {
                    sb_green += "  " + box.empty;
                    sb_red += "  " + box.label;
                    sb_white += "  " + box.empty;
                }
                else
                {
                    sb_green += "  " + box.empty;
                    sb_red += "  " + box.empty;
                    sb_white += "  " + box.label;
                }
            }

            string result = sb_green + sb_white + sb_red;
            if (!result.Equals(this.lastResult))
            {
                Chart.DrawStaticText("idtext_green", "\n"+sb_green+".", this.vAlignment, this.hAlignment, Color.Green);
                Chart.DrawStaticText("idtext_red", "\n"+sb_red+".", this.vAlignment, this.hAlignment, Color.Chocolate);
                Chart.DrawStaticText("idtext_white", "\n"+sb_white+".", this.vAlignment, this.hAlignment, Color.Gray);
                this.lastResult = result;
            }
        }
    }

    public class Box
    {
        public Box(string l, string e, DirectionalMovementSystem a, ParabolicSAR p)
        {
            this.label = l;
            this.empty = e;
            this.adx = a;
            this.psar = p;
        }
        public string label { get; set; }
        public string empty { get; set; }
        public DirectionalMovementSystem adx { get; set; }
        public ParabolicSAR psar { get; set; }
    }
}