horizontal line y

Created at 21 Dec 2021, 15:16
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
IR

IRCtrader

Joined 17.06.2021

horizontal line y
21 Dec 2021, 15:16


i have cbot manager bot. i want this bot add a horizontal line to my chart and user could change that line.

i want my robot show me volume based my stop lost. and this horizontal line is stop lost that user could modify and move it.

i make that but code doesn't move. and i dont know how could i set y index while robot running in center of chart..

i tried with chart.drawhorionalline but i couldn't access y inedes in my code. and user could'nt move line?

other question: could we have access volume in one click trading in code?

using System;
using System.Linq;
using cAlgo.API;


namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AWCPDaily : Robot
    {

        TextBlock tb = new TextBlock();
        Chart.DrawHorizontalLine sll;

        [Parameter("Take Profit", DefaultValue = 100)]
        public double tp { get; set; }
        [Parameter("Stop Profit", DefaultValue = 90)]
        public double sl { get; set; }
        [Parameter("FontSize", DefaultValue = 16, Group = "Text")]
        public int FontSize { get; set; }
        [Parameter("Space to Corner", DefaultValue = 10, Group = "Text")]
        public int Margin { get; set; }
        [Parameter("Horizental Alignment", DefaultValue = HorizontalAlignment.Left, Group = "Text")]
        public HorizontalAlignment HAlignment { get; set; }
        [Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Top, Group = "Text")]
        public VerticalAlignment VAlignment { get; set; }
        [Parameter("Color", DefaultValue = "Red", Group = "Text")]
        public string Color1 { get; set; }
        [Parameter("Opacity", DefaultValue = 0.7, MinValue = 0.1, MaxValue = 1, Group = "Text")]
        public double Opacity { get; set; }
        [Parameter("Text Alignment", DefaultValue = TextAlignment.Center, Group = "Text")]
        public TextAlignment Alignment { get; set; }
        protected override void OnStart()
        {
            Chart.AddControl(sll);


            Chart.AddControl(tb);
            tb.Text = "sl : " + sl.ToString() + ", " + "tp : " + tp.ToString() + "\n EQ: " + Account.Equity + ", ML%: " + Account.MarginLevel + "\nVP: " + Account.Margin / Account.Balance + "V: " + sll.y;
            tb.FontSize = FontSize;
            tb.ForegroundColor = Color1.TrimEnd();
            tb.HorizontalAlignment = HAlignment;
            tb.VerticalAlignment = VAlignment;
            tb.TextAlignment = Alignment;
            tb.Margin = Margin;
            tb.Opacity = Opacity;
        }

        protected override void OnTick()
        {


            foreach (var position in Positions)
            {
                if (Account.Equity > tp || Account.Equity < sl)
                {
                    ClosePositionAsync(position);
                }

            }

            foreach (var order in PendingOrders)
            {
                if (Account.Equity > tp || Account.Equity < sl)
                {
                    CancelPendingOrder(order);
                }
            }

        }

    }


}

 


@IRCtrader
Replies

amusleh
22 Dec 2021, 09:28

Hi,

Please read API references and check the examples there before asking a question: cAlgo API Reference - ChartHorizontalLine Interface (ctrader.com)

Try this:

using System;
using System.Linq;
using cAlgo.API;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AWCPDaily : Robot
    {
        private TextBlock tb = new TextBlock();
        private ChartHorizontalLine sll;

        [Parameter("Take Profit", DefaultValue = 100)]
        public double tp { get; set; }

        [Parameter("Stop Profit", DefaultValue = 90)]
        public double sl { get; set; }

        [Parameter("FontSize", DefaultValue = 16, Group = "Text")]
        public int FontSize { get; set; }

        [Parameter("Space to Corner", DefaultValue = 10, Group = "Text")]
        public int Margin { get; set; }

        [Parameter("Horizental Alignment", DefaultValue = HorizontalAlignment.Left, Group = "Text")]
        public HorizontalAlignment HAlignment { get; set; }

        [Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Top, Group = "Text")]
        public VerticalAlignment VAlignment { get; set; }

        [Parameter("Color", DefaultValue = "Red", Group = "Text")]
        public string Color1 { get; set; }

        [Parameter("Opacity", DefaultValue = 0.7, MinValue = 0.1, MaxValue = 1, Group = "Text")]
        public double Opacity { get; set; }

        [Parameter("Text Alignment", DefaultValue = TextAlignment.Center, Group = "Text")]
        public TextAlignment Alignment { get; set; }

        protected override void OnStart()
        {
            var y = Chart.BottomY + ((Chart.TopY - Chart.BottomY) / 2);

            sll = Chart.DrawHorizontalLine("horizontal", y, Color.Red);

            sll.IsInteractive = true;

            Chart.AddControl(tb);
            tb.Text = "sl : " + sl.ToString() + ", " + "tp : " + tp.ToString() + "\n EQ: " + Account.Equity + ", ML%: " + Account.MarginLevel + "\nVP: " + Account.Margin / Account.Balance + "V: " + sll.Y;
            tb.FontSize = FontSize;
            tb.ForegroundColor = Color1.TrimEnd();
            tb.HorizontalAlignment = HAlignment;
            tb.VerticalAlignment = VAlignment;
            tb.TextAlignment = Alignment;
            tb.Margin = Margin;
            tb.Opacity = Opacity;
        }

        protected override void OnTick()
        {
            foreach (var position in Positions)
            {
                if (Account.Equity > tp || Account.Equity < sl)
                {
                    ClosePositionAsync(position);
                }
            }

            foreach (var order in PendingOrders)
            {
                if (Account.Equity > tp || Account.Equity < sl)
                {
                    CancelPendingOrder(order);
                }
            }
        }
    }
}

You have to set a chart object IsInteractive property to true, then you will be able to change it on the chart.


@amusleh

IRCtrader
22 Dec 2021, 14:24 ( Updated at: 22 Dec 2021, 14:27 )

RE:

thanks

 

amusleh said:

Hi,

Please read API references and check the examples there before asking a question: cAlgo API Reference - ChartHorizontalLine Interface (ctrader.com)

Try this:

using System;
using System.Linq;
using cAlgo.API;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AWCPDaily : Robot
    {
        private TextBlock tb = new TextBlock();
        private ChartHorizontalLine sll;

        [Parameter("Take Profit", DefaultValue = 100)]
        public double tp { get; set; }

        [Parameter("Stop Profit", DefaultValue = 90)]
        public double sl { get; set; }

        [Parameter("FontSize", DefaultValue = 16, Group = "Text")]
        public int FontSize { get; set; }

        [Parameter("Space to Corner", DefaultValue = 10, Group = "Text")]
        public int Margin { get; set; }

        [Parameter("Horizental Alignment", DefaultValue = HorizontalAlignment.Left, Group = "Text")]
        public HorizontalAlignment HAlignment { get; set; }

        [Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Top, Group = "Text")]
        public VerticalAlignment VAlignment { get; set; }

        [Parameter("Color", DefaultValue = "Red", Group = "Text")]
        public string Color1 { get; set; }

        [Parameter("Opacity", DefaultValue = 0.7, MinValue = 0.1, MaxValue = 1, Group = "Text")]
        public double Opacity { get; set; }

        [Parameter("Text Alignment", DefaultValue = TextAlignment.Center, Group = "Text")]
        public TextAlignment Alignment { get; set; }

        protected override void OnStart()
        {
            var y = Chart.BottomY + ((Chart.TopY - Chart.BottomY) / 2);

            sll = Chart.DrawHorizontalLine("horizontal", y, Color.Red);

            sll.IsInteractive = true;

            Chart.AddControl(tb);
            tb.Text = "sl : " + sl.ToString() + ", " + "tp : " + tp.ToString() + "\n EQ: " + Account.Equity + ", ML%: " + Account.MarginLevel + "\nVP: " + Account.Margin / Account.Balance + "V: " + sll.Y;
            tb.FontSize = FontSize;
            tb.ForegroundColor = Color1.TrimEnd();
            tb.HorizontalAlignment = HAlignment;
            tb.VerticalAlignment = VAlignment;
            tb.TextAlignment = Alignment;
            tb.Margin = Margin;
            tb.Opacity = Opacity;
        }

        protected override void OnTick()
        {
            foreach (var position in Positions)
            {
                if (Account.Equity > tp || Account.Equity < sl)
                {
                    ClosePositionAsync(position);
                }
            }

            foreach (var order in PendingOrders)
            {
                if (Account.Equity > tp || Account.Equity < sl)
                {
                    CancelPendingOrder(order);
                }
            }
        }
    }
}

You have to set a chart object IsInteractive property to true, then you will be able to change it on the chart.

 


@IRCtrader