ctid4633759
ctid4633759's avatar

Info

Username:ctid4633759
Name:ctid4633759
Member since: 25 Aug 2021

About

None

Signature

None

Last Forum Posts

@Custom indicator advice:  17 Sep 2021, 14:54


Hi, I have an indicator that I want to create, but not sure how to do it.

In short, I want to create rectangles based on the open and close of a higher timeframe as sort of a "big picture candle".

Any advice?

Thanks 

@Moving average fill colour:  15 Sep 2021, 10:42


Hi, I'm looking for a method to color spaces between multiple moving averages.

For example, if a 50 is trending below the 200, the space between the 50 and 200 can be filled with a red colour. Is this possible?

Thanks.

@Last three bars indicator:  09 Sep 2021, 13:22


amusleh said:

Hi,

Not sure what exactly you want to do with all those extra code, but if you want to show a text based on type of last three bar you can do it like this:

using cAlgo.API;
using System.Linq;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ThreeStrike : 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 ChartStaticText _text;

        protected override void Initialize()
        {
            _text = Chart.DrawStaticText("idtext_red", string.Empty, this.vAlignment, this.hAlignment, Color.Chocolate);
        }

        public override void Calculate(int index)
        {
            if (index < 2) return;

            var lastThreeBars = new Bar[] { Bars.Last(0), Bars.Last(1), Bars.Last(2) };

            if (lastThreeBars.All(bar => bar.Close > bar.Open))
            {
                _text.Text = "Three Bull";
                _text.Color = Color.Green;
            }
            else if (lastThreeBars.All(bar => bar.Close < bar.Open))
            {
                _text.Text = "Three Bear";
                _text.Color = Color.Red;
            }
            else
            {
                _text.Text = "Neutral";
                _text.Color = Color.Gray;
            }
        }
    }
}

Hi amusleh, thanks for the help.

I have added another step where the next bar should be an engulfing bar, which works, but I'm having a bit of trouble creating a vertical line as an entry signal where the conditions are met.

using cAlgo.API;
using System.Linq;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ThreeStrike : 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 ChartStaticText _text;

        protected override void Initialize()
        {
            _text = Chart.DrawStaticText("idtext_red", string.Empty, this.vAlignment, this.hAlignment, Color.Chocolate);
        }

        public override void Calculate(int index)
        {
            if (index < 2)
                return;

            var lastThreeBars = new Bar[] 
            {
                Bars.Last(1),
                Bars.Last(2),
                Bars.Last(3)
            };

            if (lastThreeBars.All(bar => bar.Close > bar.Open))
            {
                _text.Text = "Wait For Red Engulfing";
                _text.Color = Color.Red;
                if (Bars.ClosePrices.Last(0) < Bars.OpenPrices.Last(1))
                {
                    _text.Text = "Sell";
                    _text.Color = Color.Red;
                    Chart.DrawVerticalLine("Sell", System.DateTime.Now, Color.OrangeRed);
                }
            }
            else if (lastThreeBars.All(bar => bar.Close < bar.Open))
            {
                _text.Text = "Wait For Green Engulfing";
                _text.Color = Color.Green;

                if (Bars.ClosePrices.Last(0) > Bars.OpenPrices.Last(1))
                {
                    _text.Text = "Buy";
                    _text.Color = Color.Green;
                    Chart.DrawVerticalLine("Buy", System.DateTime.Now, Color.LimeGreen);
                }
            }
            else
            {
                _text.Text = "Do Not Trade";
                _text.Color = Color.Gray;
            }
        }

    }
}

@Last three bars indicator:  08 Sep 2021, 11:12


Hi, I am attempting to create an indicator that will tell me if the last three bars are in the same direction. I want to display this as a chart object, but the logic regarding color changes confuses me.

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 ThreeStrike : 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;
        private bool threestrike;

        protected override void Initialize()
        {
            this.list = new List<Box>();
            list.Add(new Box("Three Strike", "     "));

            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)
            {
                if (Bars.ClosePrices.Last(1) > Bars.ClosePrices.Last(2) && Bars.ClosePrices.Last(2) > Bars.ClosePrices.Last(3) && Bars.ClosePrices.Last(3) > Bars.ClosePrices.Last(4))
                {
                    threestrike = true;
                }

                if (Bars.ClosePrices.Last(1) < Bars.ClosePrices.Last(2) && Bars.ClosePrices.Last(2) < Bars.ClosePrices.Last(3) && Bars.ClosePrices.Last(3) < Bars.ClosePrices.Last(4))
                {
                    threestrike = false;
                }

                if (threestrike)
                {
                    sb_green += "  " + box.label;
                    sb_red += "  " + box.empty;
                    sb_white += "  " + box.empty;
                }
                else if (!threestrike)
                {
                    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)
        {
            this.label = l;
            this.empty = e;
        }
        public string label { get; set; }
        public string empty { get; set; }
    }
}

Any help would be appreciated, thanks.

@Only one trade per MA cross:  25 Aug 2021, 15:08


Hi, I want to create a condition where a bot is only allowed one trade per moving average cross.

So far I have:

_MA_Cross = _FastMA.Result.Last(1) > _SlowMA.Result.Last(1) ? true : false;

            if (posBuy == null && _MA_Cross && !_dir)
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, 10000, _label, _SL_Para, _TP_Para);
                    _dir = true;
            }

            if (posSell == null && !_MA_Cross && _dir)
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, 10000, _label, _SL_Para, _TP_Para);
                    _dir = false;
            }

What I have implemented does not work the way I want, any tips?

Thanks.

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.

No uploaded.

Warning! Executing cBots downloaded from this section may result in loss of funds. Use them at your own risk.

No uploaded.