Creating and Running a cBot (2024)

Action Map

The following diagram showcases the action flow of creating and running a new cBot.

graph TB B([Add a New cBot]) ==> C([Edit the Sample Code]); C ==> D([Save and Build Your cBot]); D ==> E([Create and Customize a cBot Instance]); E ==> F([Run a cBot Instance]);

Add a New cBot

Click on the 'New' button to the right of the search bar. The following window should open.

Creating and Running a cBot (1)

Type the cBot name and select between two options.

  • 'Blank'. If this option is chosen, the new cBot will contain only a basic template.
  • 'From the list'. If this option is chosen and a cBot is selected from the list below, the new cBot will contain the entire code of the chosen algo. The pre-made cBots in the list cover a wide range of cBot types and automated actions.

Samples Repository

The code samples for the 'From the list' option are taken from the [email protected]:spotware/ctrader-automate-samples.git repository. To access it, click here.

Click on 'Create' to finish setting up the bot.

Edit the Sample Code

Click on your new bot to open the code editor window. If you have chosen 'Blank' during the previous step, it will contain the following code.

 1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334353637
 using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } /* This method performs an action of your choosing  when a cBot is launched. */ protected override void OnStart() { // Put your initialization logic here } /* This method performs an action of your choosing every tick. */ protected override void OnTick() { // Put your core logic here } /* This method performs an action of your choosing when a cBot stops working. */ protected override void OnStop() { // Put your deinitialization logic here } } }

Note

If you have chosen 'From the list' during the previous step, your cBot will be ready for action immediately. It will contain detailed trading logic and custom parameters.

As we have discussed previously, the cBot attribute Robot along with its optional properties such as TimeZone and AccessRights, precedes the cBot class (NewcBot) declaration.

The OnStart() method is invoked each time an instance of your cBot is launched. In turn, the OnTick() method is invoked on every tick. Last but not least, the OnStop() method is invoked every time an instance of your new cBot stops operating.

Note that, as the OnTick() method performs a certain action every tick, it is CPU-intensive. In many cases, there is also little practical need for performing a trading operation for every tick, particularly when trading stocks or indices.

Instead, you could replace the OnTick() method with the OnBar() method. As implied by its name, it is only invoked at the opening of every bar, significantly reducing CPU loads.

These are far from the only methods you can use to set up the behaviour of your cBot. However, they are the simplest to use if you are just starting out with C#.

Please refer to the 'References' section to learn more about the classes, methods, and properties you can use when coding cBots. In addition, you can always choose to write custom methods as shown in our introduction to C# and .NET.

Given what you have just learned and the examples provided in other parts of this documentation, edit the code of your cBot to suit your requirements.

Creating and Running a cBot (2)

To replicate the screenshot, you can copy and paste the below code after the namespace declaration.

 1 2 3 4 5 6 7 8 91011121314
 [Robot()] public class Sample_cBot : Robot { protected override void OnStart() { var result = ExecuteMarketOrder(TradeType.Buy, SymbolName, 10000); if (result.IsSuccessful) { var position = result.Position; Print("Position entry price is {0}", position.EntryPrice); } } }

Save and Build Your cBot

Save your code by clicking on the 'Save' button located above the code editor window. Alternatively, press Ctrl+S. You can also right-click anywhere in the code editor and choose 'Save' from the newly opened menu.

Creating and Running a cBot (3)

Before you can use your code, you need to convert it into a working cBot. To build a cBot, click the 'Build' icon at the top of the code editor or in the cBot menu. The keyboard shortcut for this action is Ctrl+B.

If the build succeeds, a message confirming this will appear in the 'Build Result' viewer. If the build fails, this window will, instead, display a summary of all errors encountered when the build action was performed. Clicking on an error description in the 'Build Result' viewer will show you the exact place in your code where this error occurs.

If there are changes to your code made since the last build, you should see a red asterisk sign next to the 'Build' icon. In this case, build the bot again before running it.

Create and Customize a cBot Instance

If you have successfully completed all of the above actions, your cBot should be ready for action. To start using it, create a new instance by performing one of the following actions.

  • Click on the '+' icon to the right of the extension name. In the menu that appears, select a symbol that you would like to trade.

Creating and Running a cBot (4)

  • Click on the 'three dots' icon to the right of the cBot name and select 'Add Instance'. cTrader will automatically create a new instance trading the EURUSD symbol (or a similar symbol) using h1 as the timeframe of the candlestick chart on which the instance is supposed to run on.

You should see a new instance located directly below your cBot.

Creating and Running a cBot (5)

If you have specified any customizable parameters in your code, they will be listed in the 'Parameters' tab located to the left of the 'Trade Watch' display. Before running an instance, make sure that these parameters match your requirements.

Creating and Running a cBot (6)

You can save your current parameter values to a locally stored .cbotset file by clicking on the 'Save' icon in the upper-right corner of the 'Parameters' tab.

Alternatively, you can upload parameter values from an already existing .cbotset file by pressing the 'Folder' icon.

Run a cBot Instance

To run the newly created instance, press the 'Start cBot' button to the right of the instance name. If this is your first time using cBots, you will see a warning window. Check the "**I understand how algorithmic trading works...**" flag and press 'OK'. If prompted, provide your cBot with the required access rights.

Creating and Running a cBot (7)

To stop the newly created instance, press the 'Stop' button. Note that you can change the symbol and timeframe for the currently chosen instance but only if it is not running. It is impossible to change the parameters of any currently running instances.

Creating and Running a cBot (2024)
Top Articles
Cloud VPNs & Site-to-Cloud VPN Architecture | Aviatrix
What Does It Mean When Your Ex Boyfriend Becomes Distant?
Cpmc Mission Bernal Campus & Orthopedic Institute Photos
Frases para un bendecido domingo: llena tu día con palabras de gratitud y esperanza - Blogfrases
Skycurve Replacement Mat
Amc Near My Location
Breaded Mushrooms
Couchtuner The Office
Craigslist Benton Harbor Michigan
Wausau Marketplace
Kostenlose Games: Die besten Free to play Spiele 2024 - Update mit einem legendären Shooter
Mikayla Campinos Videos: A Deep Dive Into The Rising Star
Ucf Event Calendar
Nichole Monskey
Builders Best Do It Center
Troy Athens Cheer Weebly
Local Dog Boarding Kennels Near Me
Grace Caroline Deepfake
Craftology East Peoria Il
Wal-Mart 140 Supercenter Products
Richland Ecampus
Vandymania Com Forums
Heart Ring Worth Aj
Rqi.1Stop
Quick Answer: When Is The Zellwood Corn Festival - BikeHike
The Old Way Showtimes Near Regency Theatres Granada Hills
Scream Queens Parents Guide
Del Amo Fashion Center Map
Directions To Nearest T Mobile Store
Weather Underground Durham
Vadoc Gtlvisitme App
Vlacs Maestro Login
Tokioof
Roadtoutopiasweepstakes.con
Craigslist Dallastx
ATM Near Me | Find The Nearest ATM Location | ATM Locator NL
Bitchinbubba Face
Rage Of Harrogath Bugged
Evil Dead Rise (2023) | Film, Trailer, Kritik
Oriellys Tooele
Mars Petcare 2037 American Italian Way Columbia Sc
Hellgirl000
Craigslist Putnam Valley Ny
Puretalkusa.com/Amac
Live Delta Flight Status - FlightAware
Carteret County Busted Paper
Courses In Touch
Linkbuilding uitbesteden
Rocket Lab hiring Integration & Test Engineer I/II in Long Beach, CA | LinkedIn
Studentvue Calexico
Florida Lottery Powerball Double Play
How to Get a Check Stub From Money Network
Latest Posts
Article information

Author: Kieth Sipes

Last Updated:

Views: 5989

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Kieth Sipes

Birthday: 2001-04-14

Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

Phone: +9663362133320

Job: District Sales Analyst

Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.