Quicktrade button

yomm0401's avatar

yomm0401 since: 11 Apr 2020;

  28 Nov 2021, 11:21
Quicktrade button

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);
        }

    }
}
amusleh's avatar

amusleh since: 01 Mar 2021;

  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.

Spotware | Telegram: @algodeveloper
yomm0401's avatar

yomm0401 since: 11 Apr 2020;

  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.

xiao-linlong since: 03 Aug 2020;

  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.

China CFD Traders
amusleh's avatar

amusleh since: 01 Mar 2021;

  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.

Spotware | Telegram: @algodeveloper

xiao-linlong since: 03 Aug 2020;

  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.

China CFD Traders

xiao-linlong since: 03 Aug 2020;

  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.

China CFD Traders

xiao-linlong since: 03 Aug 2020;

  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.

China CFD Traders
amusleh's avatar

amusleh since: 01 Mar 2021;

  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?

Spotware | Telegram: @algodeveloper

xiao-linlong since: 03 Aug 2020;

  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?

China CFD Traders