Button event
Button event
11 Jan 2024, 18:54
Hi forum, I'm creating a button that should open a position, but I'm stuck in its implementation. How should I continue this function? Thank you
private void Button_Click_Buy(??ButtonClickEventArgs??)
{
var volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "pos");
Replies
AndreaPereira
12 Jan 2024, 12:27
Button event
Hi Panagiotis,
I'm creating an indicator that has two chart buttons, one opens a long position and the other short. Graphically I managed to implement them as you can see from the photo, but now I should implement the action or behavior. I helped myself with the examples and the guide provided by the site but I haven't succeeded yet. Thanks for the support.
PanagiotisCharalampous said:
Hi Andrea,
You would need to provide a better explanation regarding how exactly you want to proceed. What exact information are you looking for?
Best regards,
Panagiotis
@AndreaPereira
PanagiotisCharalampous
12 Jan 2024, 12:44
Hi Andrea,
Can you share your complete cBot code?
Best regards,
Panagiotis
@PanagiotisCharalampous
AndreaPereira
12 Jan 2024, 13:45
( Updated at: 12 Jan 2024, 14:12 )
RE: Button event
here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC,AccessRights = AccessRights.None)]
public class NewIndicator2 : Indicator
{
protected override void Initialize()
{
var stackPanel = new StackPanel
{
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Bottom,
BackgroundColor = Color.Gold,
Opacity = 0.7,
};
for (int i = 0; i < 2; i++)
{
var button = new Button();
if (i == 0)
{
button.Text = "Buy";
button.Button_Click_Buy();
}else{
button.Text = "Sell";
button.Button_Click_Sell();
}
button.Margin = 10;
stackPanel.AddChild(button);
}
Chart.AddControl(stackPanel);
}
private void Button_Click_Buy(ButtonClickEventArgs ????)
{
?????????
}
private void Button_Click_Sell(ButtonClickEventArgs ????)
{
?????????
}
public override void Calculate(int index)
{
// Calculate value at specified index
// Result[index] =
}
}
}
@AndreaPereira
AndreaPereira
12 Jan 2024, 17:31
( Updated at: 12 Jan 2024, 17:39 )
RE: Button event
I solved it with cbot and not with the indicator. However, I'm curious to see your solution. If you want I'll attach the code and tell me what you think.
@AndreaPereira
PanagiotisCharalampous
13 Jan 2024, 07:56
RE: RE: Button event
AndreaPereira said:
I solved it with cbot and not with the indicator. However, I'm curious to see your solution. If you want I'll attach the code and tell me what you think.
Hi Andrea,
You cannot execute orders through indicators. It needs to be a cBot.
Best regards,
Panagiotis
@PanagiotisCharalampous
AlgoCreators
30 Mar 2024, 09:44
( Updated at: 30 Mar 2024, 10:06 )
Hi andrea
you can see this robot
https://ctrader.com/algos/show/3835
@AlgoCreators
PanagiotisCharalampous
12 Jan 2024, 07:04
Hi Andrea,
You would need to provide a better explanation regarding how exactly you want to proceed. What exact information are you looking for?
Best regards,
Panagiotis
@PanagiotisCharalampous