Plugin link to chart query **SOLVED**

Created at 07 Oct 2024, 20:17
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!
M4

m4j4p4v4

Joined 07.10.2024

Plugin link to chart query **SOLVED**
07 Oct 2024, 20:17


Hi

I'm currently developing a simple cTrader plugin that acts as a small macro dashboard to execute trades with multiple options for SL / trade close rules etc. I've built bots and indicators with good success but wish to aggregate this into ‘presets’. Overall I understand the integration of c# relatively well at this stage.

As a test when trying to execute simple XAUUSD trade on a demo account (local) I get the following scenario.

First : I open the plugin test

 

Second : I select the buy button and receive this popup

Thirdly : I select allow and nothing happens.

This is the code within the plugin. I've changed the access code to reflect full and not full but that just changes if the popup appears or not. 

I assume it's not actually attaching to a chart or something similar as when you typically run a but you go through the symbol/time frame selection before running. Any insight grateful!

using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Internals;
using cAlgo.API.Indicators; // Needed for colors

namespace cAlgo.Plugins
{
    [Plugin(AccessRights = AccessRights.FullAccess)]
    public class CustomWindowPlugin : Plugin
    {
        private Button _buttonBuy;
        private Button _buttonSell;
        private Window _window;

        protected override void OnStart()
        {
            // Initialize the Buy button
            _buttonBuy = new Button
            {
                BackgroundColor = Color.SeaGreen,
                Height = 40,
                Width = 80,
                Text = "Buy"
            };

            _buttonBuy.Click += ButtonBuy_Click;

            // Initialize the Sell button
            _buttonSell = new Button
            {
                BackgroundColor = Color.Crimson,
                Height = 40,
                Width = 80,
                Text = "Sell"
            };

            _buttonSell.Click += ButtonSell_Click;

            // Create the window and add buttons
            _window = new Window
            {
                Height = 600,
                Width = 800,
                Padding = new Thickness(10)
            };

            // Use StackPanel for vertical stacking
            var stackPanel = new StackPanel
            {
                Orientation = Orientation.Vertical
            };
            stackPanel.AddChild(_buttonBuy);
            stackPanel.AddChild(_buttonSell);

            _window.Child = stackPanel;
            _window.Show();
        }

        private void ButtonBuy_Click(ButtonClickEventArgs args)
        {
            // Open buy trade in XAUUSD 0.05 lots
            double volume = 0.05;
            var result = ExecuteMarketOrder(TradeType.Buy, "XAUUSD", volume);

            if (result.IsSuccessful)
            {
                Print($"Opened XAUUSD Buy trade with {volume} lots.");
                _buttonBuy.BackgroundColor = Color.Gray; // Change color on click
            }
            else
            {
                Print($"Failed to open trade: {result.Error}");
            }
        }

        private void ButtonSell_Click(ButtonClickEventArgs args)
        {
            // Open a sell trade for XAUUSD with 0.05 lots
            double volume = 0.05; 
            var result = ExecuteMarketOrder(TradeType.Sell, "XAUUSD", volume);

            if (result.IsSuccessful)
            {
                Print($"Opened XAUUSD Sell trade with {volume} lots.");
                _buttonSell.BackgroundColor = Color.Gray; // Change color on click
            }
            else
            {
                Print($"Failed to open trade: {result.Error}");
            }
        }

        protected override void OnStop()
        {
            // Handle Plugin stop here
        }
    }
}


Many thanks


@m4j4p4v4
Replies

PanagiotisCharalampous
08 Oct 2024, 05:36

Hi there,

I select allow and nothing happens.
 

What do you expect to happen? Did you try clicking on the buttons after you pressed “Allow”?

Best regards,

Panagiotis


@PanagiotisCharalampous

m4j4p4v4
08 Oct 2024, 07:58 ( Updated at: 08 Oct 2024, 10:44 )

RE: Plugin link to chart query

PanagiotisCharalampous said: 

I select allow and nothing happens.
 

What do you expect to happen? Did you try clicking on the buttons after you pressed “Allow”?

Yea exactly that, pressed both a number of times. Also if I close the plugin and re-run it it doesn't prompt for access again unless I disabled it in the main plugin on/off area. I've tested this quite a few times. Something tells me the syntax isn't pointing to XAUUSD correctly. 

Many thanks :)

 


@m4j4p4v4

PanagiotisCharalampous
08 Oct 2024, 10:48

RE: RE: Plugin link to chart query

m4j4p4v4 said: 

PanagiotisCharalampous said: 

I select allow and nothing happens.
 

What do you expect to happen? Did you try clicking on the buttons after you pressed “Allow”?

Yea exactly that, pressed both a number of times. Also if I close the plugin and re-run it it doesn't prompt for access again unless I disabled it in the main plugin on/off area. I've tested this quite a few times. Something tells me the syntax isn't pointing to XAUUSD correctly. 

Many thanks :)

 

Hi there,

Check the Algo logs as well. There might be some useful information there as well.

Best regards,

Panagiotis


@PanagiotisCharalampous

m4j4p4v4
08 Oct 2024, 16:58 ( Updated at: 08 Oct 2024, 17:07 )

RE: RE: RE: Plugin link to chart query

PanagiotisCharalampous said: 

 

Check the Algo logs as well. There might be some useful information there as well.


Yea it seems BadVolume is the issue. I've tried a variety of volumes. Noting I can manually open with 0.1 - I thought it might be trying to use a real broker account without capital - as opposed to using the Demo account I'm trying to test it with but I ran a debug check and it confirms it's a demo account. I run bots with the same '0.1' float all the time without issue…


08/10/2024 16:55:19.359 | Info | Plugin [Trade Window Debug] started.
08/10/2024 16:55:20.344 | Info | Plugin OnStart method called.
08/10/2024 16:55:20.344 | Info | Account Type: Demo
08/10/2024 16:55:20.375 | Info | Window displayed successfully.
08/10/2024 16:55:23.516 | Info | Buy button clicked.
08/10/2024 16:55:23.516 | Info | Attempting to execute Buy order for XAUUSD with volume 0.1
08/10/2024 16:55:23.531 | Trade | Executing Market Order to Buy 0.1 XAUUSD
08/10/2024 16:55:23.594 | Trade | → Executing Market Order to Buy 0.1 XAUUSD FAILED with error "BadVolume"
08/10/2024 16:55:23.594 | Info | Failed to open trade: BadVolume. Error Code: 0
 


@m4j4p4v4

m4j4p4v4
08 Oct 2024, 17:16 ( Updated at: 08 Oct 2024, 22:24 )

RE: RE: RE: RE: Plugin link to chart query

**UPDATE** **SOLVED**

I've found the reason for anybody in the future who may find this useful. Hope this helps with calibrating like it has for me.

It appears 1.0 Lot in the syntax = 0.01 lots in reality for XAUUSD so it needs scaling up. BadVolume was because I was attempting 0.001 Lots

with 1 Lots written in c# I can confirm this equated to 0.10 lots in reality. As below -

08/10/2024 17:10:42.438 | Info | Buy button clicked.
08/10/2024 17:10:42.438 | Info | Attempting to execute Buy order for XAUUSD with volume 1
08/10/2024 17:10:42.438 | Trade | Executing Market Order to Buy 1 XAUUSD
08/10/2024 17:10:42.719 | Trade | → Executing Market Order to Buy 1 XAUUSD SUCCEEDED, Position PID99659352
08/10/2024 17:10:42.719 | Info | Opened XAUUSD Buy trade with 1 lots at 2612.79



So 100 is really 1.00 Lots and so on.


@m4j4p4v4