Description
The objective for this robot is not to develop a real trading robot but to point out the technical architecture and the communication process between cAlgo and an external dll.
In order to bring the principle in the foreground, the chosen example is very simple and basic. It consist of a frame with 2 buttons representing the current Bid and Ask prices like the cTrader order button with exact the same prices. By pushing on of the buttons an entry in the cAlgo log frame will be printed (see attached video for more details).
The frame application itself will be started from within cAlgo same as a robot, but is acting in a different thread and is therefore managed independent. In addition there is a bidirectional event handling taking care of cAlgo events and events from the external dll to communicate between both threads. You can imagine to adopt this approach to your own needs. I. e. for communication to third party products or intercommunication between different currency pairs respectively time frames.
The external dll has been developed using Visual Basic .Net based on Visual Studio 2010 Express edition (free edition). If you intend to follow this example one by one you need to install at least this version of Visual Studio.
Create a new project of type class library and copy & paste the following code. Align the code to your needs
Imports System.Windows.Forms 'the communication layer between cAlgo and the frame application Public Class ThreadHandler Private sMesText As String Private iDigs As Integer 'declaring the frame application with event handling Private WithEvents myForm As externalForm Public Event ButtonBuyClicked() Public Event ButtonSellClicked() 'constructor for frame application with overloading parameters Public Sub New(ByVal sMsgTxt As String, iDigits As Integer) sMesText = sMsgTxt iDigs = iDigits End Sub 'start the frame application Public Sub Work() 'use the windows visual style Application.EnableVisualStyles() Application.DoEvents() myForm = New externalForm myForm.Text = sMesText myForm.ShowDialog() End Sub Public Sub setButtonText(ByVal cTxt As String, dPrice As Double) 'passing the price from cAlgo to the form application myForm.SetButtonText(cTxt, dPrice) End Sub Private Sub myForm_ButtonBuyClicked() Handles myForm.ButtonBuyClicked 'passing the button click event from frame application to cAlgo RaiseEvent ButtonBuyClicked() End Sub Private Sub myForm_ButtonSellClicked() Handles myForm.ButtonSellClicked 'passing the button click event from frame application to cAlgo RaiseEvent ButtonSellClicked() End Sub End Class
Then create a new frame, paste 2 buttons and copy & paste the following code. Align the code to your needs.
Imports System.Windows.Forms Public Class externalForm Public Event ButtonSellClicked() Public Event ButtonBuyClicked() Public Delegate Sub dlSetButtonText(ByVal cTxt As String, ByVal dPrice As Double) Private Sub ButtonSell_Click(sender As System.Object, e As System.EventArgs) Handles ButtonSell.Click RaiseEvent ButtonSellClicked() End Sub Private Sub ButtonBuy_Click(sender As System.Object, e As System.EventArgs) Handles ButtonBuy.Click RaiseEvent ButtonBuyClicked() End Sub Public Sub SetButtonText(ByVal cTxt As String, ByVal dPrice As Double) Dim myCont As Control() 'external application (cAlgo) tries to call the frame application. invocation is required myCont = Me.Controls.Find(cTxt, True) If myCont.Count = 0 Then Exit Sub If myCont(0).InvokeRequired Then myCont(0).Invoke(New dlSetButtonText(AddressOf SetButtonText), cTxt, dPrice) Else 'after invocation and 'recall' of the sub the button text can be set myCont(0).Text = dPrice.ToString End If End Sub End Class
Hugoman
Joined on 26.01.2013
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: 7b51f216d1cc8b0b5f0da9109e101ea8.cs
- Rating: 0
- Installs: 2875
- Modified: 13/10/2021 09:54
Comments
Hi!
Can some one add code in C#?
With thanks!
PP
Great Post
This is what I was looking for. Thank you for sharing
:)
Los servicios de redacción de ensayos se han vuelto cada vez más populares entre los estudiantes universitarios que buscan ayuda con sus tareas académicas. Consulte más https://hacemostutfg.com. Estos servicios ofrecen una variedad de beneficios, lo que los convierte en una opción atractiva para los estudiantes que enfrentan plazos ajustados y cursos desafiantes.
Una de las principales ventajas de utilizar un servicio de redacción de ensayos es la comodidad que ofrece. Los estudiantes universitarios a menudo hacen malabarismos con múltiples responsabilidades, incluidas clases, trabajos a tiempo parcial y actividades extracurriculares, lo que les deja poco tiempo para escribir ensayos. Los servicios de redacción de ensayos ofrecen una solución al permitir a los estudiantes delegar sus ensayos a escritores profesionales que puedan entregar trabajos de alta calidad dentro de plazos específicos.