Quicktrade button

Created at 28 Nov 2021, 11:21
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!
yomm0401's avatar

yomm0401

Joined 11.04.2020

Quicktrade button
28 Nov 2021, 11:21


Is it possible to reproduce the Stop/Limit function of the Quicktrade button in Automate?
Can I drag and drop Stop/Limit orders to Place

I tried to set the entry price in "obj.Yvalue" using "MouseMoveEventArgs".
However, when there are other objects, such as a pending order, its Stop Loss, Takeprofit, or other horizontal line, I cannot get the Yvalue when the price is the same.
The selection is shifted to other objects.
Is there any way to solve this?

bestregards


using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class QuickTradingpanelStopLimittest : Robot
    {
        [Parameter("LineStyle", Group = "Horizontal Line", DefaultValue = LineStyle.Solid)]
        public LineStyle hLS { get; set; }

        [Parameter("Thickness", Group = "Horizontal Line", DefaultValue = 1)]
        public int hThc { get; set; }

        [Parameter("Color", Group = "Horizontal Line", DefaultValue = "DarkGoldenrod")]
        public string hCol { get; set; }

        [Parameter("Transparency", Group = "Horizontal Line", DefaultValue = 60, MinValue = 1, MaxValue = 100)]
        public int hOpc { get; set; }

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

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

        private StackPanel contentPanel;
        private ToggleButton sellstoplimitbutton;
        private bool sellSLbool;
        private Color hColour;
        private ChartHorizontalLine HorizontalLine;
        private string _symbol;
        private double defaultlots, testvolume;

        protected override void OnStart()
        {
            defaultlots = 0.01;
            testvolume = Chart.Symbol.QuantityToVolumeInUnits(defaultlots);
            _symbol = Chart.SymbolName;
            hOpc = (int)(255 * 0.01 * hOpc);
            hColour = Color.FromArgb(hOpc, Color.FromName(hCol).R, Color.FromName(hCol).G, Color.FromName(hCol).B);
            panel();
            Chart.MouseMove += OnChartMouseMove;
            Chart.MouseLeave += OnChartMouseLeave;
            Chart.MouseDown += OnChartMouseDown;
        }

        private void OnChartMouseDown(ChartMouseEventArgs obj)
        {
            if (sellSLbool == true)
            {
                sellstoplimitorder(Math.Round(obj.YValue, Symbol.Digits));
                sellstoplimitbutton.IsChecked = false;
                sellSLbool = false;
            }

            Chart.RemoveObject("HorizontalLine");
            Chart.RemoveObject("price");
        }
        private void sellstoplimitorder(double openprice)
        {
            if (openprice >= Symbol.Bid)
            {
                PlaceLimitOrderAsync(TradeType.Sell, _symbol, testvolume, openprice);
            }
            else if (openprice < Symbol.Bid)
            {
                PlaceStopOrderAsync(TradeType.Sell, _symbol, testvolume, openprice);
            }
        }


        private void OnChartMouseMove(ChartMouseEventArgs obj)
        {
            if (sellSLbool == true)
            {
                if (sellSLbool == true)
                {
                    HorizontalLine = Chart.DrawHorizontalLine("stoplimitHorizontalLine", obj.YValue, Color.FromHex("#F05824"), hThc, hLS);
                    if (Math.Round(obj.YValue, Symbol.Digits) >= Symbol.Bid)
                    {
                        var sprice = Chart.DrawText("stoplimitprice", "Sell Limit " + Math.Round(obj.YValue, Symbol.Digits).ToString(), Chart.FirstVisibleBarIndex, obj.YValue, Color.FromHex("#F05824"));
                    }
                    else if (Math.Round(obj.YValue, Symbol.Digits) < Symbol.Bid)
                    {
                        var sprice = Chart.DrawText("stoplimitprice", "Sell Stop " + Math.Round(obj.YValue, Symbol.Digits).ToString(), Chart.FirstVisibleBarIndex, obj.YValue, Color.FromHex("#F05824"));
                    }
                }
            }
        }
        void OnChartMouseLeave(ChartMouseEventArgs obj)
        {
            Chart.RemoveObject("stoplimitHorizontalLine");
            Chart.RemoveObject("stoplimitprice");
        }

        private void panel()
        {
            var contetstyle = new Style();
            contetstyle.Set(ControlProperty.CornerRadius, 3);
            contetstyle.Set(ControlProperty.BackgroundColor, GetColorWithOpacity(Color.FromHex("#292929"), 0.85m), ControlState.DarkTheme);
            contetstyle.Set(ControlProperty.BackgroundColor, GetColorWithOpacity(Color.FromHex("#FFFFFF"), 0.85m), ControlState.LightTheme);
            contetstyle.Set(ControlProperty.Margin, "20 20 20 20");

            var sellstoplimitstyle = new Style();
            sellstoplimitstyle.Set(ControlProperty.BackgroundColor, Color.FromHex("#F05824"), ControlState.DarkTheme);
            sellstoplimitstyle.Set(ControlProperty.BackgroundColor, Color.FromHex("#F05824"), ControlState.LightTheme);
            sellstoplimitstyle.Set(ControlProperty.BackgroundColor, Color.FromHex("#8B0000"), ControlState.DarkTheme | ControlState.Checked);
            sellstoplimitstyle.Set(ControlProperty.BackgroundColor, Color.FromHex("#8B0000"), ControlState.LightTheme | ControlState.Checked);
            sellstoplimitstyle.Set(ControlProperty.ForegroundColor, Color.FromHex("#FFFFFF"), ControlState.DarkTheme);
            sellstoplimitstyle.Set(ControlProperty.ForegroundColor, Color.FromHex("#FFFFFF"), ControlState.LightTheme);
            sellstoplimitstyle.Set(ControlProperty.Margin, 3);

            contentPanel = new StackPanel 
            {

                HorizontalAlignment = OrderHorizontalAlignment,
                VerticalAlignment = OrderVerticalAlignment,
                Width = 225,
                Style = contetstyle
            };

            var grid = new Grid(33, 3);
            grid.Columns[1].SetWidthInPixels(5);
            sellstoplimitbutton = new ToggleButton 
            {
                Text = "Stop/Limit",
                Style = sellstoplimitstyle
            };

            grid.AddChild(sellstoplimitbutton, 0, 0);
            sellstoplimitbutton.Click += SellSLbutton;
            contentPanel.AddChild(grid);
            Chart.AddControl(contentPanel);
        }
        private void SellSLbutton(ToggleButtonEventArgs e)
        {

            if (sellstoplimitbutton.IsChecked == true)
            {
                sellSLbool = true;
            }
            else
            {
                sellSLbool = false;
            }

        }

        private static Color GetColorWithOpacity(Color baseColor, decimal opacity)
        {
            var alpha = (int)Math.Round(byte.MaxValue * opacity, MidpointRounding.AwayFromZero);
            return Color.FromArgb(alpha, baseColor);
        }

    }
}

 

 

 

 


@yomm0401
Replies

... Deleted by UFO ...

amusleh
29 Nov 2021, 15:38

Hi,

The order and price alert lines are under chart and the mouse events will not work while cursor is over them.

You can use Chart mouse leave and enter events to get the latest cursor position, if you move mouse over these lines the chart mouse leave event will be triggered and when you move back to other areas of chart the mouse enter event will be triggered.


@amusleh

yomm0401
29 Nov 2021, 16:39

RE:

amusleh said:

Hi,

The order and price alert lines are under chart and the mouse events will not work while cursor is over them.

You can use Chart mouse leave and enter events to get the latest cursor position, if you move mouse over these lines the chart mouse leave event will be triggered and when you move back to other areas of chart the mouse enter event will be triggered.

Thank you amusleh.
It would be nice to have an event to ignore the order and price alert lines.


@yomm0401

artcfd
03 Dec 2021, 05:43

RE:

amusleh said:

Hi,

The order and price alert lines are under chart and the mouse events will not work while cursor is over them.

You can use Chart mouse leave and enter events to get the latest cursor position, if you move mouse over these lines the chart mouse leave event will be triggered and when you move back to other areas of chart the mouse enter event will be triggered.

Mr. amusleh, is there any event to ignore the order and price alert line? Or is it possible to open the drag and drop so that it solves the problem perfectly, looking forward to the reply, thanks.


@artcfd

amusleh
03 Dec 2021, 08:27

RE: RE:

xiao-linlong said:

amusleh said:

Hi,

The order and price alert lines are under chart and the mouse events will not work while cursor is over them.

You can use Chart mouse leave and enter events to get the latest cursor position, if you move mouse over these lines the chart mouse leave event will be triggered and when you move back to other areas of chart the mouse enter event will be triggered.

Mr. amusleh, is there any event to ignore the order and price alert line? Or is it possible to open the drag and drop so that it solves the problem perfectly, looking forward to the reply, thanks.

Hi,

As I said on my previous post, you can use Chart mouse enter/leave events, when cursor goes over those lines the mouse leave event will be trigged and when it goes back to other parts of chart the mouse enter event will be triggered.


@amusleh

artcfd
03 Dec 2021, 08:51

RE: RE: RE:

amusleh said:Hello, sir, is it possible to reproduce the drag-and-drop function of the Quicktrade button in Automate?

xiao-linlong said:

amusleh said:

Hi,

The order and price alert lines are under chart and the mouse events will not work while cursor is over them.

You can use Chart mouse leave and enter events to get the latest cursor position, if you move mouse over these lines the chart mouse leave event will be triggered and when you move back to other areas of chart the mouse enter event will be triggered.

Mr. amusleh, is there any event to ignore the order and price alert line? Or is it possible to open the drag and drop so that it solves the problem perfectly, looking forward to the reply, thanks.

Hi,

As I said on my previous post, you can use Chart mouse enter/leave events, when cursor goes over those lines the mouse leave event will be trigged and when it goes back to other parts of chart the mouse enter event will be triggered.

 


@artcfd

artcfd
03 Dec 2021, 09:10

RE: RE: RE:

amusleh said:Dear Sir, you may have misunderstood, what I want is to be able to press the &quot;Ready button&quot; and then click on the next &quot;Stop/Limit&quot; order on the chart.

xiao-linlong said:

amusleh said:

Hi,

The order and price alert lines are under chart and the mouse events will not work while cursor is over them.

You can use Chart mouse leave and enter events to get the latest cursor position, if you move mouse over these lines the chart mouse leave event will be triggered and when you move back to other areas of chart the mouse enter event will be triggered.

Mr. amusleh, is there any event to ignore the order and price alert line? Or is it possible to open the drag and drop so that it solves the problem perfectly, looking forward to the reply, thanks.

Hi,

As I said on my previous post, you can use Chart mouse enter/leave events, when cursor goes over those lines the mouse leave event will be trigged and when it goes back to other parts of chart the mouse enter event will be triggered.

 


@artcfd

artcfd
03 Dec 2021, 09:33

RE: RE: RE:

amusleh said:What you mean is that if the mouse moves over the alert, order or pending order price or its stop loss and take profit lines, the mouse event will be cancelled.
What I want is to be able to press the "Prepare button" and then click on the chart to place a "Stop Loss/Limit" order.
Can you tell me if there is a solution? grateful.

xiao-linlong said:

amusleh said:

Hi,

The order and price alert lines are under chart and the mouse events will not work while cursor is over them.

You can use Chart mouse leave and enter events to get the latest cursor position, if you move mouse over these lines the chart mouse leave event will be triggered and when you move back to other areas of chart the mouse enter event will be triggered.

Mr. amusleh, is there any event to ignore the order and price alert line? Or is it possible to open the drag and drop so that it solves the problem perfectly, looking forward to the reply, thanks.

Hi,

As I said on my previous post, you can use Chart mouse enter/leave events, when cursor goes over those lines the mouse leave event will be trigged and when it goes back to other parts of chart the mouse enter event will be triggered.

 


@artcfd

amusleh
04 Dec 2021, 18:02

RE: RE: RE: RE:

xiao-linlong said:

amusleh said:What you mean is that if the mouse moves over the alert, order or pending order price or its stop loss and take profit lines, the mouse event will be cancelled.
What I want is to be able to press the "Prepare button" and then click on the chart to place a "Stop Loss/Limit" order.
Can you tell me if there is a solution? grateful.

xiao-linlong said:

amusleh said:

Hi,

The order and price alert lines are under chart and the mouse events will not work while cursor is over them.

You can use Chart mouse leave and enter events to get the latest cursor position, if you move mouse over these lines the chart mouse leave event will be triggered and when you move back to other areas of chart the mouse enter event will be triggered.

Mr. amusleh, is there any event to ignore the order and price alert line? Or is it possible to open the drag and drop so that it solves the problem perfectly, looking forward to the reply, thanks.

Hi,

As I said on my previous post, you can use Chart mouse enter/leave events, when cursor goes over those lines the mouse leave event will be trigged and when it goes back to other parts of chart the mouse enter event will be triggered.

 

Hi,

Can't you use the latest location of mouse before mouse enter/leave event?


@amusleh

artcfd
05 Dec 2021, 08:49

RE: RE: RE: RE: RE:

amusleh said:

xiao-linlong said:

amusleh said:What you mean is that if the mouse moves over the alert, order or pending order price or its stop loss and take profit lines, the mouse event will be cancelled.
What I want is to be able to press the "Prepare button" and then click on the chart to place a "Stop Loss/Limit" order.
Can you tell me if there is a solution? grateful.

xiao-linlong said:

amusleh said:

Hi,

The order and price alert lines are under chart and the mouse events will not work while cursor is over them.

You can use Chart mouse leave and enter events to get the latest cursor position, if you move mouse over these lines the chart mouse leave event will be triggered and when you move back to other areas of chart the mouse enter event will be triggered.

Mr. amusleh, is there any event to ignore the order and price alert line? Or is it possible to open the drag and drop so that it solves the problem perfectly, looking forward to the reply, thanks.

Hi,

As I said on my previous post, you can use Chart mouse enter/leave events, when cursor goes over those lines the mouse leave event will be trigged and when it goes back to other parts of chart the mouse enter event will be triggered.

 

Hi,

Can't you use the latest location of mouse before mouse enter/leave event?

Hello sir.

I try but but it can't.

Can you tell me how to do it?


@artcfd

artcfd
05 Dec 2021, 09:24

RE: RE: RE: RE: RE:

amusleh said:

xiao-linlong said:

amusleh said:What you mean is that if the mouse moves over the alert, order or pending order price or its stop loss and take profit lines, the mouse event will be cancelled.
What I want is to be able to press the "Prepare button" and then click on the chart to place a "Stop Loss/Limit" order.
Can you tell me if there is a solution? grateful.

xiao-linlong said:

amusleh said:

Hi,

The order and price alert lines are under chart and the mouse events will not work while cursor is over them.

You can use Chart mouse leave and enter events to get the latest cursor position, if you move mouse over these lines the chart mouse leave event will be triggered and when you move back to other areas of chart the mouse enter event will be triggered.

Mr. amusleh, is there any event to ignore the order and price alert line? Or is it possible to open the drag and drop so that it solves the problem perfectly, looking forward to the reply, thanks.

Hi,

As I said on my previous post, you can use Chart mouse enter/leave events, when cursor goes over those lines the mouse leave event will be trigged and when it goes back to other parts of chart the mouse enter event will be triggered.

 

Hi,

Can't you use the latest location of mouse before mouse enter/leave event?

I had the same problem as the original blogger, I tried his code and we had the same problem.


@artcfd

amusleh
06 Dec 2021, 09:01

Hi,

If mouse cursor is over order/alert lines then none of the mouse events will work, and the chart mouse leave event will be triggered.

To solve this issue you can hide the cTrader order/alert lines and instead manage your orders only with your own quick order tool.

Here is an example on how you can capture the last mouse cursor location:

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Test : Robot
    {
        private double _lastMouseX, _lastMouseY;

        protected override void OnStart()
        {
            Chart.MouseMove += Chart_MouseMove;
            Chart.MouseEnter += Chart_MouseEnter;
            Chart.MouseLeave += Chart_MouseLeave;
        }

        // This event will be triggered if mouse cursor goes over chart order/alert lines
        // When this event got triggered all other mouse events will stop working as the cursor is not over chart
        private void Chart_MouseLeave(ChartMouseEventArgs obj)
        {
        }

        // This event will be triggered if mouse cursor cameback to chart from order/alert lines
        // When this event got triggered all mouse events will start working back
        private void Chart_MouseEnter(ChartMouseEventArgs obj)
        {
        }

        private void Chart_MouseMove(ChartMouseEventArgs obj)
        {
            _lastMouseX = obj.MouseX;
            _lastMouseY = obj.MouseY;
        }
    }
}

 


@amusleh

artcfd
06 Dec 2021, 13:17

RE:

amusleh said:

Hi,

If mouse cursor is over order/alert lines then none of the mouse events will work, and the chart mouse leave event will be triggered.

To solve this issue you can hide the cTrader order/alert lines and instead manage your orders only with your own quick order tool.

Here is an example on how you can capture the last mouse cursor location:

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Test : Robot
    {
        private double _lastMouseX, _lastMouseY;

        protected override void OnStart()
        {
            Chart.MouseMove += Chart_MouseMove;
            Chart.MouseEnter += Chart_MouseEnter;
            Chart.MouseLeave += Chart_MouseLeave;
        }

        // This event will be triggered if mouse cursor goes over chart order/alert lines
        // When this event got triggered all other mouse events will stop working as the cursor is not over chart
        private void Chart_MouseLeave(ChartMouseEventArgs obj)
        {
        }

        // This event will be triggered if mouse cursor cameback to chart from order/alert lines
        // When this event got triggered all mouse events will start working back
        private void Chart_MouseEnter(ChartMouseEventArgs obj)
        {
        }

        private void Chart_MouseMove(ChartMouseEventArgs obj)
        {
            _lastMouseX = obj.MouseX;
            _lastMouseY = obj.MouseY;
        }
    }
}

 

Dear Sir:

"Quicktrade" is not affected by the order/alarm line. It would be great if our button could be dragged and dropped to any place like the "Quicktrade" button. After hiding the cTrader order/alarm line, there is no even the button to close the order. In addition, the order line and the alarm line themselves only have the function of prompting, and there is no operation meaning, because the move/double/close all need to click the leftmost button , I don’t know why the line affects the mouse event. I hope the team will consider solving the problem of cTrader order/alarm line affecting the order in the next version. You have also seen that more than I have encountered this trouble, many friends have encountered this Troubled. thanks.


@artcfd

amusleh
07 Dec 2021, 09:24

RE: RE:

xiao-linlong said:

amusleh said:

Hi,

If mouse cursor is over order/alert lines then none of the mouse events will work, and the chart mouse leave event will be triggered.

To solve this issue you can hide the cTrader order/alert lines and instead manage your orders only with your own quick order tool.

Here is an example on how you can capture the last mouse cursor location:

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Test : Robot
    {
        private double _lastMouseX, _lastMouseY;

        protected override void OnStart()
        {
            Chart.MouseMove += Chart_MouseMove;
            Chart.MouseEnter += Chart_MouseEnter;
            Chart.MouseLeave += Chart_MouseLeave;
        }

        // This event will be triggered if mouse cursor goes over chart order/alert lines
        // When this event got triggered all other mouse events will stop working as the cursor is not over chart
        private void Chart_MouseLeave(ChartMouseEventArgs obj)
        {
        }

        // This event will be triggered if mouse cursor cameback to chart from order/alert lines
        // When this event got triggered all mouse events will start working back
        private void Chart_MouseEnter(ChartMouseEventArgs obj)
        {
        }

        private void Chart_MouseMove(ChartMouseEventArgs obj)
        {
            _lastMouseX = obj.MouseX;
            _lastMouseY = obj.MouseY;
        }
    }
}

 

Dear Sir:

"Quicktrade" is not affected by the order/alarm line. It would be great if our button could be dragged and dropped to any place like the "Quicktrade" button. After hiding the cTrader order/alarm line, there is no even the button to close the order. In addition, the order line and the alarm line themselves only have the function of prompting, and there is no operation meaning, because the move/double/close all need to click the leftmost button , I don’t know why the line affects the mouse event. I hope the team will consider solving the problem of cTrader order/alarm line affecting the order in the next version. You have also seen that more than I have encountered this trouble, many friends have encountered this Troubled. thanks.

Hi,

Please open a thread for this on suggestions section and if it got enough voter by community we will change this behavior if already haven't opened one yet.


@amusleh