LO
Topics
20 May 2024, 07:14
258
2
18 May 2024, 05:12
204
1
11 Dec 2023, 14:14
481
1
louisangkq
22 May 2024, 05:44 ( Updated at: 22 May 2024, 07:24 )
RE: Using indicators to trade
PanagiotisCharalampous said:
Hi Panagiotis, thank you for responding.
Below is my code:
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class OrderEntry : Indicator
{
//Panel Parameters
private TextBox _textBox;
private StackPanel _mainPanel;
private TextBlock _errorMessageTextBlock;
[Parameter("Horizontal Alignment", DefaultValue = HorizontalAlignment.Right, Group = "Panel")]
public HorizontalAlignment HorizontalAlignment { get; set; }
[Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Top, Group = "Panel")]
public VerticalAlignment VerticalAlignment { get; set; }
[Parameter("Opacity", DefaultValue = 1, MinValue = 0, MaxValue = 1, Group = "Panel")]
public double Opacity { get; set; }
protected override void Initialize()
{
_textBox = new TextBox
{
Margin = 2,
MinWidth = 100,
BackgroundColor = Color.LightGray
};
var BuyButton = new Button
{
Text = "Buy",
Margin = 2,
ForegroundColor = Color.White,
BackgroundColor = Color.Green
};
BuyButton.Click += BuyButton_Click;
var SellButton = new Button
{
Text = "Sell",
Margin = 2,
ForegroundColor = Color.White,
BackgroundColor = Color.Red
};
SellButton.Click += SellButton_Click;
var panel = new StackPanel
{
Orientation = Orientation.Horizontal
};
panel.AddChild(_textBox);
panel.AddChild(BuyButton);
panel.AddChild(SellButton);
_mainPanel = new StackPanel
{
Orientation = Orientation.Vertical,
HorizontalAlignment = HorizontalAlignment,
VerticalAlignment = VerticalAlignment,
Margin = 2,
Opacity = Opacity
};
_errorMessageTextBlock = new TextBlock
{
FontWeight = FontWeight.Bold
};
_mainPanel.AddChild(panel);
_mainPanel.AddChild(_errorMessageTextBlock);
Chart.AddControl(_mainPanel);
_mainPanel.IsVisible = true;
}
public override void Calculate(int index)
{
}
private void BuyButton_Click(ButtonClickEventArgs obj)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, Convert.ToDouble(_textBox.Text), "buy order", 10, 10);
}
private void SellButton_Click(ButtonClickEventArgs obj)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, Convert.ToDouble(_textBox.Text), "sell order", 10, 10);
}
}
}
Am I missing out something?
How can I include execute Market Order & Limit Order commands inside Indicator coding?
Thank you in advance.
@louisangkq