Replies

wolters
14 Jun 2024, 06:31

RE: Button.Click does not provide Shift, Ctrl & Alt-Key status

tinaturner335 said: 

Hello, 

Instead of relying on the modifier key status directly, you can track the state of the modifier keys manually using event handlers.

Here's a general approach you can follow:

  1. Create variables to track the state of the modifier keys. For example, you can use boolean variables like isShiftPressed, isCtrlPressed, and isAltPressed.
  2. Register event handlers for the key events you want to track. In this case, you can register handlers for the KeyDown and KeyUp events.
  3. Inside the KeyDown event handler, check which modifier key was pressed and update the corresponding boolean variable accordingly.
  4. Inside the KeyUp event handler, reset the corresponding boolean variable for the released modifier key.
  5. Now, in your Button.Click event handler, you can check the values of the boolean variables to determine which modifier keys are pressed and trigger the appropriate actions accordingly.

 

Hi Tina,

thank you for trying to help ;-)

I've already checked that, but the calgo-API does not support a native key-up event. As a result, I have to depend on machine-specific key-up event listeners, which creates significant compatibility issues with MacOS. If you have working code for this issue, let me know.

The easiest would be to have a simple Property for the status of the modifier keys -available inside the robot/indicator. Or as I said, the modifier status should be submitted in the events that a user can create. Like pressing a button, similar to the mouse click event.

 

Best,
Carsten


@wolters

wolters
22 May 2024, 08:54

RE: cTrader Desktop 5.0.21: Panel does not resize if inner elements get hidden

PanagiotisCharalampous said: 

Hi there,

Can you share the indicator code so that we can reproduce this behavior?

Best regards,

Panagiotis

Good morning Panagiotis,

here is an example code:

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

namespace cAlgo
{
    [Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
    public class Test : Indicator
    {
        protected override void Initialize()
        {
            Panel innerPanel1 = new StackPanel();            
            var innerGrid = new Grid(3, 2);

            TextBlock textBlock1 = new();
            textBlock1.Text = "Cell 1";
            textBlock1.BackgroundColor = Color.Gold;

            TextBlock textBlock1b = new();
            textBlock1b.Text = "Cell 2";
            textBlock1b.BackgroundColor = Color.Aqua;

            Button button1 = new();
            button1.Text = "Click me - it shoud collapse the invisible row but it does not anymore with 5.0.21.";
            button1.Click += args =>
            {
                textBlock1.IsVisible = !textBlock1.IsVisible;
                textBlock1b.IsVisible = textBlock1.IsVisible;
            };

            innerGrid.AddChild(button1, 0, 0, 1, 2);
            innerGrid.AddChild(textBlock1, 1, 0);
            innerGrid.AddChild(textBlock1b, 1, 1);
            innerPanel1.AddChild(innerGrid);


            var innerGrid2 = new Grid(2, 1);
            Panel innerPanel2 = new StackPanel();            
            TextBlock textBlock2 = new();
            textBlock2.Text = "Col-Span-Cell";

            Button button2 = new();
            button2.Text = "Click me - it shoud collapse the invisible row but it does not anymore with 5.0.21.";
            button2.Click += args =>
            {
                textBlock2.IsVisible = !textBlock2.IsVisible;
            };

            innerGrid2.AddChild(button2, 0, 0, 1, 2);
            innerGrid2.AddChild(textBlock2, 1, 0, 1, 2);
            innerPanel2.AddChild(innerGrid2);


            Panel innerPanel3 = new StackPanel();            
            TextBlock textBlock3 = new();
            textBlock3.Text = "No grid";

            Button button3 = new();
            button3.Text = "Click me - even without a grid, it will not collapse the invisible textblock anymore.";
            button3.Click += args =>
            {
                textBlock3.IsVisible = !textBlock3.IsVisible;
            };

            innerPanel3.AddChild(button3);
            innerPanel3.AddChild(textBlock3);


            Panel mainPanel = new StackPanel();
            mainPanel.AddChild(innerPanel1);    // with grid selecting only one cell
            mainPanel.AddChild(innerPanel2);    // with grid selecting only one cell
            mainPanel.AddChild(innerPanel3);
            
            mainPanel.AddChild(new TextBlock
                 {
                     Text = "Does not move even if elements are completely hidden.",
                     TextAlignment = TextAlignment.Center,
                     Margin = 5,
                     ForegroundColor = Color.Black,
                     FontWeight = FontWeight.ExtraBold
                 });
            
            mainPanel.IsVisible = true;

            StackPanel tradePanelFrame = new StackPanel
            {
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                BackgroundColor = Color.LightBlue,
                Margin = 50,                
            };
            tradePanelFrame.AddChild(mainPanel);
            Chart.AddControl(tradePanelFrame);
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = 
        }
    }
}


@wolters

wolters
06 Apr 2024, 12:14 ( Updated at: 07 Apr 2024, 05:30 )

RE: LocalStorage / Scope Type is not in sync over multiple instances

Hi Panagiotis,

I know all of this, but it still would be nice to have the mutex/thread-safe access to the LocalStorage on Type & Instance level done by cTrader and not by an error prone user implementation.

As a user I would assume, that I do no need to care about syncing stuff (I should not even think about flushing/reloading) and just use the LocalStorage on Type&Instance level. The implementation in the background should take care that it is an atomic access to the “global” storage. And this is not the case right now, so it lacks these features whichs makes things uneccessary complex.

So if possible, please extend your implementation to guarantee a thread safe behavior across multiple instances when using LocalStorage.

 

Best,
Carsten

 

 

PanagiotisCharalampous said: 

Hi Carsten,

Well this is not a cTrader issue but a general programming concept. When two threads try to access the same resource at the same time, then such issues happen. You need to implement some kind of control, like using a mutex 

Regarding

If there is already a storage on the “type”-level, there is no reason to not be in sync over different instances. Please re-think about this. It would be nice to have a consistent access to values without flush/reload.

As you mentioned before this is resource consuming, therefore it happens automatically by design every minute.

Best regards,

Panagiotis

 


@wolters

wolters
05 Apr 2024, 09:22 ( Updated at: 05 Apr 2024, 09:26 )

RE: LocalStorage / Scope Type is not in sync over multiple instances

PanagiotisCharalampous said: 

Hi there,

It is by design that you need to flush and load your changes in order to see them in another instance instantly.

Best regards,

Panagiotis

Hi Panagiotis,

even flush+load does not guarantee that the values in the other process do get refreshed.
I tried it, but is does not work consitently. Workflow:

Indicator-Instance 2:

LocalStorage.SetObject("test", “doesNotGetOverwritten”, LocalStorageScope.Type);

 

Indicator-Instance 1: 

LocalStorage.SetObject("test", “shallOverwrite”, LocalStorageScope.Type);
LocalStorage.Flush();


Indicator-Instance 2:

LocalStorage.Reload();
LocalStorage.GetObject("test", LocalStorageScope.Type) ≠ “shallOverwrite”;
 

In the last step, I cannot be sure that the LocalStorage of instance 2 does get the correct value of instance 1. Possibly, it gets overwritten by the content of instance 2, because the initial changes in instance 2 were not flushed initially and will be written at a later time - after instance 1 changed the values.

Flushing/Reloading all the time is very nasty and reduces the performance a lot.

 

If there is already a storage on the “type”-level, there is no reason to not be in sync over different instances. Please re-think about this. It would be nice to have a consistent access to values without flush/reload.

 

Best
Carsten

 


@wolters

wolters
06 Jun 2023, 14:05

RE: RE:

lookitsben said:

PanagiotisChar said:

Hi lookitsben,

m1 data should only be used for strategies that are executed on each bar. For strategies that do stuff in OnTick or use pending orders, stop losses and take profits, m1 bars will be from slightly to completely inaccurate.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

Makes sense! Very helpful, thank you!!

 

No, this does not make 100% sense ;-)

I have the same problem and created this topic:

 

The backtest simulator can do easily much better than it currently does. Checkout my example - imho this is clearly a sign of a bug. 

 

 

 


@wolters

wolters
25 Jul 2022, 12:20 ( Updated at: 25 Jul 2022, 12:21 )

The problem is solved.

In this case, it was a class defined as "internal" instead of "public" that seems to hide the information in the assembly.

Best,
Carsten


@wolters

wolters
21 Jul 2022, 19:16 ( Updated at: 23 Jul 2022, 14:41 )

RE:

The problem is solved.

In this case, it was class defined as "internal" instead of "public" that seems to trigger hide the information in the assembly.

Best

Carsten

 


@wolters