### Algo Installation Example Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/InstallationResult This example demonstrates how to install an algo using AlgoRegistry.Install and check the InstallationResult. ```csharp using cAlgo.API; [Robot(AccessRights = AccessRights.None)] public class TestExample : Robot { protected override void OnStart() { var result = AlgoRegistry.Install("path/to-algo-file.algo"); if (!result.Succeeded) Print($"Algo installation failed with error: {result.Error}"); } } ``` ```python import clr clr.AddReference("cAlgo.API") from cAlgo.API import * from robot_wrapper import * class Test(): def on_start(self): result = api.AlgoRegistry.Install("path/to-algo-file.algo") if result.Succeeded == False: print(f"Algo installation failed with error: {result.Error}") ``` -------------------------------- ### InstallAsync Example Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/InstallationOperation Demonstrates how to use AlgoRegistry.InstallAsync to install an algo and handle the installation result. ```APIDOC ## Method: AlgoRegistry.InstallAsync ### Description Initiates an asynchronous installation of an algo file. ### Parameters #### Path Parameters - **filePath** (string) - Required - The path to the algo file to install. #### Query Parameters - **callback** (Action) - Required - A callback function to be executed upon completion of the installation. ### Request Example (C#) ```csharp var operation = AlgoRegistry.InstallAsync("path/to/algo-file.algo", result => { if (!result.Succeeded) Print(result.Error); }); Print($"Is Executing: {operation.IsExecuting}"); ``` ### Request Example (Python) ```python operation = api.AlgoRegistry.InstallAsync("path/to/algo-file.algo", Action[InstallationResult](self.on_installation_operation_completed)) print(f"Is Executing: {operation.IsExecuting}") ``` ``` -------------------------------- ### Example: Installing an Algo Asynchronously (C#) Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/InstallationOperation?q= Demonstrates how to use AlgoRegistry.InstallAsync to install an algo and handle the completion callback in C#. ```APIDOC ## Example: Installing an Algo Asynchronously (C#) ```csharp [Robot(AccessRights = AccessRights.None)] public class TestExample : Robot { protected override void OnStart() { var operation = AlgoRegistry.InstallAsync("path/to-algo-file.algo", result => { if (!result.Succeeded) Print(result.Error); }); Print($"Is Executing: {operation.IsExecuting}"); } } ``` ``` -------------------------------- ### C# Initialize Method Implementation Example Source: https://help.ctrader.com/ctrader-algo/references/General/Indicator?q= Example implementation of the Initialize method for custom indicator setup. ```csharp protected override void Initialize() { // Place your Initialization logic here } ``` -------------------------------- ### Example: Installing an Algo Asynchronously (Python) Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/InstallationOperation?q= Demonstrates how to use AlgoRegistry.InstallAsync to install an algo and handle the completion callback in Python using clr. ```APIDOC ## Example: Installing an Algo Asynchronously (Python) ```python import clr clr.AddReference("cAlgo.API") # Import cAlgo API types from cAlgo.API import * # Import trading wrapper functions from robot_wrapper import * from System import Action class Test(): def on_start(self): operation = api.AlgoRegistry.InstallAsync("path/to-algo-file.algo", Action[InstallationResult](self.on_installation_operation_completed)) print(f"Is Executing: {operation.IsExecuting}") def on_installation_operation_completed(self, result): if result.Succeeded == False: print(result.Error) ``` ``` -------------------------------- ### Python Initialize Method Implementation Example Source: https://help.ctrader.com/ctrader-algo/references/General/Indicator?q= Example implementation of the initialize method for custom indicator setup in Python. ```python def initialize(self): # Place your Initialization logic here ``` -------------------------------- ### Install Algo Asynchronously in Python Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/InstallationOperation?q= Shows how to perform an asynchronous algo installation using Python within the cTrader API. This example includes setting up the necessary imports and defining a callback for installation completion. ```python import clr clr.AddReference("cAlgo.API") # Import cAlgo API types from cAlgo.API import * # Import trading wrapper functions from robot_wrapper import * from System import Action class Test(): def on_start(self): operation = api.AlgoRegistry.InstallAsync("path/to-algo-file.algo", Action[InstallationResult](self.on_installation_operation_completed)) print(f"Is Executing: {operation.IsExecuting}") def on_installation_operation_completed(self, result): if result.Succeeded == False: print(result.Error) ``` -------------------------------- ### OnStart Method Implementation (C#) Source: https://help.ctrader.com/ctrader-algo/references/General/Robot?q= Provides an example of implementing the OnStart method in C#. This method is executed once when the cBot begins operation, suitable for initial setup. ```csharp protected override void OnStart() { //This method is invoked when the cBot is started. } ``` -------------------------------- ### Get Algo Metadata (Argument Example) Source: https://help.ctrader.com/ctrader-algo/documentation/ctrader-cli?q= Demonstrates using the path to an algorithm as a direct argument to the metadata command. ```bash ctrader-cli metadata C:/Users/{username}/Documents/cAlgo/Sources/Robots/mycoolcbot.algo ``` -------------------------------- ### Get Ticks Example (Python) Source: https://help.ctrader.com/ctrader-algo/references/MarketData/Ticks/Ticks This example demonstrates how to get tick data for a symbol and handle tick events using the Ticks interface in Python. ```APIDOC ## Get Ticks Example (Python) ### Description This Python code snippet illustrates how to obtain tick data for a given symbol, subscribe to tick events, and load historical tick data using the Ticks interface. ### Code ```python import clr clr.AddReference("cAlgo.API") from cAlgo.API import * class TicksSample(): def initialize(self): # Getting a symbol ticks data self.ticks = api.MarketData.GetTicks(api.InputSymbolName) # Subscribing to upcoming ticks self.ticks.Tick += self.on_ticks_tick self.ticks.HistoryLoaded += self.on_ticks_history_loaded self.ticks.LoadMoreHistoryAsync(); # Load more history asynchronously self.ticks.Reloaded += self.on_ticks_reloaded def on_ticks_tick(self, args): api.Print(str(args.Ticks.LastTick)) def on_ticks_history_loaded(self, args): api.Print(f"New ticks loaded: #{args.Count}") def on_ticks_reloaded(self, args): api.Print("Ticks got reloaded") ``` ``` -------------------------------- ### Get Ticks Example (C#) Source: https://help.ctrader.com/ctrader-algo/references/MarketData/Ticks/Ticks This example demonstrates how to get tick data for a symbol and handle tick events using the Ticks interface in C#. ```APIDOC ## Get Ticks Example (C#) ### Description This C# code snippet shows how to initialize an indicator to retrieve tick data for a specified symbol, subscribe to tick events, and load historical tick data. ### Code ```csharp using cAlgo.API; using cAlgo.API.Internals; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class TickSample : Indicator { private Ticks _ticks; [Parameter("Symbol Name", DefaultValue = "EURUSD")] public string InputSymbolName { get; set; } protected override void Initialize() { // Getting a symbol ticks data _ticks = MarketData.GetTicks(InputSymbolName); // Subscribing to upcoming ticks _ticks.Tick += Ticks_Tick; _ticks.HistoryLoaded += Ticks_HistoryLoaded; _ticks.LoadMoreHistoryAsync(); // Load more history asynchronously _ticks.Reloaded += Ticks_Reloaded; } private void Ticks_Reloaded(TicksHistoryLoadedEventArgs obj) { Print("Ticks got reloaded"); } private void Ticks_HistoryLoaded(TicksHistoryLoadedEventArgs obj) { Print("New ticks loaded: #", obj.Count); } private void Ticks_Tick(TicksTickEventArgs obj) { // Printing Last tick inside Ticks collection Print(obj.Ticks.LastTick); } public override void Calculate(int index) { // Calculation logic here } } } ``` ``` -------------------------------- ### OnStart Method Example Source: https://help.ctrader.com/ctrader-algo/references/General/Indicator?q= This is a placeholder for the OnStart method, typically used for initialization in cTrader Algos. The actual implementation would follow. ```csharp protected override void OnStart() { ``` -------------------------------- ### Get Installed Robots Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Retrieves a read-only list of all installed robot types. This allows you to query and manage your installed trading robots. ```csharp public abstract IReadonlyList Robots {get;} ``` -------------------------------- ### Install Algo Asynchronously in C# Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/InstallationOperation?q= Demonstrates how to initiate an asynchronous installation of an algo file and handle the completion callback. Use this to install algos without blocking the main thread and to process the installation outcome. ```csharp [Robot(AccessRights = AccessRights.None)] public class TestExample : Robot { protected override void OnStart() { var operation = AlgoRegistry.InstallAsync("path/to-algo-file.algo", result => { if (!result.Succeeded) Print(result.Error); }); Print($"Is Executing: {operation.IsExecuting}"); } } ``` -------------------------------- ### Initialize and Configure WebView Source: https://help.ctrader.com/ctrader-algo/references/Controls/WebView Demonstrates how to create a WebView instance, set its background color, and attach event handlers for navigation completion, web message reception, and load/unload events. It also shows how to navigate to a URL and integrate the WebView into a window. ```csharp addressBarPanel.BackgroundColor = Color.Black addressBarPanel.Orientation = Orientation.Horizontal addressBarPanel.AddChild(goBackButton) addressBarPanel.AddChild(goForwardButton) addressBarPanel.AddChild(self.addressTextBox) addressBarPanel.AddChild(goButton) addressBarPanel.AddChild(reloadButton) addressBarPanel.AddChild(stopButton) addressBarPanel.AddChild(self.scriptTextBox) addressBarPanel.AddChild(self.executeScriptButton) self.webView = WebView() self.webView.DefaultBackgroundColor = Color.Red self.webView.NavigationCompleted += self.on_web_view_navigation_completed self.webView.WebMessageReceived += lambda args: print(f"Source: {args.Source} | Message: {args.Message}") self.webView.Loaded += lambda args: print(f"Webview loaded, IsLoaded: {args.WebView.IsLoaded}") self.webView.Unloaded += lambda args: print(f"Webview unloaded, IsLoaded: {args.WebView.IsLoaded}") self.webView.NavigateAsync(self.addressTextBox.Text) mainGrid = Grid(2, 1) mainGrid.Rows[0].SetHeightToAuto() mainGrid.Rows[1].SetHeightInStars(1) mainGrid.AddChild(addressBarPanel, 0, 0) mainGrid.AddChild(self.webView, 1, 0) window = Window() window.Child = mainGrid window.Show() ``` -------------------------------- ### C# ToString Method Usage Example Source: https://help.ctrader.com/ctrader-algo/references/General/Indicator?q= Example demonstrating how to get and print the string representation (name) of an indicator instance. ```csharp private SampleSMA sma; //... sma = Indicators.GetIndicator(Source, Period); Print(sma.ToString()); ``` -------------------------------- ### Access and Manage Installed Algorithms (C#) Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Demonstrates how to retrieve specific algorithms by name and kind, iterate through all installed algorithms, and handle registry change events. Also shows how to install a new algorithm and check for installation errors. ```csharp [Robot(AccessRights = AccessRights.None)] public class TestExample : Robot { protected override void OnStart() { if (AlgoRegistry.Get("Simple Moving Average", AlgoKind.StandardIndicator) is IndicatorType smaIndicatorType) Print($"Name: {smaIndicatorType.Name} | Parameters #: {smaIndicatorType.Parameters.Count} | Lines #: {smaIndicatorType.Lines.Count} | Bars: {smaIndicatorType.Bars.Count}"); if (AlgoRegistry.Get("Sample Break Even", AlgoKind.Robot) is RobotType robotType) Print($"Name: {robotType.Name} | Parameters #: {robotType.Parameters.Count}"); if (AlgoRegistry.Get("Sample Test Plugin", AlgoKind.Plugin) is PluginType pluginType) Print($"Name: {pluginType.Name} | Parameters #: {pluginType.Parameters.Count}"); foreach (var algo in AlgoRegistry) { Print($"Name: {algo.Name} | Kind: {algo.AlgoKind}"); } AlgoRegistry.AlgoTypeChanged += args => Print($"Algo updated: {args.AlgoTypeName}"); AlgoRegistry.AlgoTypeDeleted += args => Print($"Algo deleted: {args.AlgoTypeName}"); AlgoRegistry.AlgoTypeInstalled += args => Print($"Algo installed: {args.AlgoTypeName}"); var result = AlgoRegistry.Install("path/to-algo-file.algo"); if (!result.Succeeded) Print($"Algo installation failed with error: {result.Error}"); } } ``` -------------------------------- ### Install Async Algo and Handle Result (C#) Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/InstallationOperation Demonstrates how to asynchronously install an algo file and handle the installation result via a callback. Checks if the operation is currently executing. ```csharp [Robot(AccessRights = AccessRights.None)] public class TestExample : Robot { protected override void OnStart() { var operation = AlgoRegistry.InstallAsync("path/to-algo-file.algo", result => { if (!result.Succeeded) Print(result.Error); }); Print($"Is Executing: {operation.IsExecuting}"); } } ``` -------------------------------- ### Get Installed Indicators Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Retrieves a read-only list of all installed indicator types. Use this to access information about available indicators. ```csharp public abstract IReadonlyList Indicators {get;} ``` -------------------------------- ### Get Installed Plugins Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Retrieves a read-only list of all installed plugin types. Access this list to manage or inspect available plugins. ```csharp public abstract IReadonlyList Plugins {get;} ``` -------------------------------- ### Install Algo and Check Result (C#) Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/InstallationResult Demonstrates how to install an algo using AlgoRegistry.Install and check if the installation succeeded. Prints an error message if the installation fails. ```csharp [Robot(AccessRights = AccessRights.None)] public class TestExample : Robot { protected override void OnStart() { var result = AlgoRegistry.Install("path/to-algo-file.algo"); if (!result.Succeeded) Print($"Algo installation failed with error: {result.Error}"); } } ``` -------------------------------- ### Get AlgoRegistry Source: https://help.ctrader.com/ctrader-algo/references/General/Algo Provides access to the registry of installed algorithms. ```csharp public AlgoRegistry AlgoRegistry {get;} ``` -------------------------------- ### Access and Manage Installed Algorithms (Python) Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Shows how to retrieve specific algorithms by name and kind, iterate through all installed algorithms, and subscribe to registry change events. Also demonstrates installing a new algorithm and handling installation failures. ```python import clr clr.AddReference("cAlgo.API") # Import cAlgo API types from cAlgo.API import * # Import trading wrapper functions from robot_wrapper import * class Test(): def on_start(self): indicatorType = api.AlgoRegistry.Get("Simple Moving Average", AlgoKind.StandardIndicator) if indicatorType is not None: smaIndicatorType = IndicatorType(indicatorType) print(f"Name: {smaIndicatorType.Name} | Parameters #: {smaIndicatorType.Parameters.Count} | Lines #: {smaIndicatorType.Lines.Count} | Bars: {smaIndicatorType.Bars.Count}") robotType = api.AlgoRegistry.Get("Sample Break Even", AlgoKind.Robot) if robotType is not None: breakEventRobotType = RobotType(robotType) print(f"Name: {breakEventRobotType.Name} | Parameters #: {breakEventRobotType.Parameters.Count}") pluginType = api.AlgoRegistry.Get("Sample Test Plugin", AlgoKind.Plugin) if pluginType is not None: testPluginType = PluginType(pluginType) print(f"Name: {testPluginType.Name} | Parameters #: {testPluginType.Parameters.Count}") for algo in api.AlgoRegistry: print(f"Name: {algo.Name} | Kind: {algo.AlgoKind}") api.AlgoRegistry.AlgoTypeChanged += lambda args : print(f"Algo updated: {args.AlgoTypeName}") api.AlgoRegistry.AlgoTypeDeleted += lambda args : print(f"Algo deleted: {args.AlgoTypeName}") api.AlgoRegistry.AlgoTypeInstalled += lambda args : print(f"Algo installed: {args.AlgoTypeName}") result = api.AlgoRegistry.Install("path/to-algo-file.algo") if result.Succeeded == False: print(f"Algo installation failed with error: {result.Error}") ``` -------------------------------- ### Count Property Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry?q= Gets the total number of installed algorithms. ```APIDOC ## Count ### Description Gets number of installed algorithms. ### Signature ```csharp public abstract int Count {get;} ``` ### Return Value int ``` -------------------------------- ### Get Installed Algorithm Count Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Retrieves the total number of algorithms currently installed. This property provides a quick count of all managed algorithms. ```csharp public abstract int Count {get;} ``` -------------------------------- ### PlaceLimitOrderAsync Example 1 (C#) Source: https://help.ctrader.com/ctrader-algo/references/General/Plugin?q= Basic example of placing a limit buy order. ```APIDOC api.PlaceLimitOrderAsync(TradeType.Buy, api.Symbol.Name, 10000, api.Symbol.Bid - 10 * api.Symbol.PipSize,"myLabel") ``` -------------------------------- ### OnStart Method Implementation in Python Source: https://help.ctrader.com/ctrader-algo/references/General/Robot Demonstrates the implementation of the on_start method in Python, which is called once when the cBot is initiated. ```python # This method is invoked when the cBot is started. def on_start(self): pass ``` -------------------------------- ### Install Async Algo and Handle Result (Python) Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/InstallationOperation Shows how to install an algo file asynchronously using Python and process the installation outcome. Includes checking the execution status. ```python import clr clr.AddReference("cAlgo.API") # Import cAlgo API types from cAlgo.API import * # Import trading wrapper functions from robot_wrapper import * from System import Action class Test(): def on_start(self): operation = api.AlgoRegistry.InstallAsync("path/to-algo-file.algo", Action[InstallationResult](self.on_installation_operation_completed)) print(f"Is Executing: {operation.IsExecuting}") def on_installation_operation_completed(self, result): if result.Succeeded == False: print(result.Error) ``` -------------------------------- ### Plugins Property Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Gets a read-only list of all installed plugin types. ```APIDOC ### Plugins ### Description Gets the list of all installed plugins. ### Signature ```csharp public abstract IReadonlyList Plugins {get;} ``` ### Return Value A read-only list of `PluginType` objects. ``` -------------------------------- ### PlaceLimitOrder Examples Source: https://help.ctrader.com/ctrader-algo/references/General/Plugin?q= Code examples demonstrating how to use the PlaceLimitOrder function with different parameters. ```APIDOC ## Examples ### Example 1 (C#) ```csharp PlaceLimitOrder(TradeType.Buy, Symbol.Name, 100000, Symbol.Bid - 2*Symbol.PipSize); ``` ### Example 2 (C#) ```csharp PlaceLimitOrder(TradeType.Buy, Symbol.Name, 200000, Symbol.Bid - 2*Symbol.PipSize, "myLabel"); ``` ### Example 3 (C#) ```csharp PlaceLimitOrder(TradeType.Buy, Symbol.Name, 10000, Symbol.Bid - 5*Symbol.PipSize, "112", 10, 10, ProtectionType.Relative); ``` ### Example 4 (C#) ```csharp var targetPrice = Symbol.Bid - 5*Symbol.PipSize; var expiry = Server.Time.AddMinutes(30); PlaceLimitOrder(TradeType.Buy, Symbol.Name, 10000, targetPrice, "112", 10, 10 , ProtectionType.Relative, expiry); ``` ### Example 5 (C#) ```csharp var targetPrice = Symbol.Bid - 5*Symbol.PipSize; var expiry = Server.Time.AddMinutes(30); PlaceLimitOrder(TradeType.Buy, Symbol.Name, 10000, targetPrice, "112", 10, 10, ProtectionType.Relative, expiry, "first order"); ``` ### Example 6 (PYTHON) ```python api.PlaceLimitOrder(TradeType.Buy, api.Symbol.Name, 100000, api.Symbol.Bid - 2 * api.Symbol.PipSize) ``` ``` -------------------------------- ### Robots Property Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Gets a read-only list of all installed robot types. ```APIDOC ### Robots ### Description Gets the list of all installed robots. ### Signature ```csharp public abstract IReadonlyList Robots {get;} ``` ### Return Value A read-only list of `RobotType` objects. ``` -------------------------------- ### Install Algo and Handle Errors (C#) Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/InstallationError?q= Demonstrates how to install an algo using AlgoRegistry and check the result for installation errors. Use this to programmatically install algos and provide user feedback on failures. ```csharp [Robot(AccessRights = AccessRights.None)] public class TestExample : Robot { protected override void OnStart() { var result = AlgoRegistry.Install("path/to-algo-file.algo"); if (!result.Succeeded) Print($"Algo installation failed with error: {result.Error}"); } } ``` -------------------------------- ### Indicators Property Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Gets a read-only list of all installed indicator types. ```APIDOC ### Indicators ### Description Gets the list of all installed indicators. ### Signature ```csharp public abstract IReadonlyList Indicators {get;} ``` ### Return Value A read-only list of `IndicatorType` objects. ``` -------------------------------- ### Count Property Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Gets the total number of algorithms currently installed. ```APIDOC ### Count ### Description Gets number of installed algorithms. ### Signature ```csharp public abstract int Count {get;} ``` ### Return Value An integer representing the total count of installed algorithms. ``` -------------------------------- ### Install Algo from File Path Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Installs an algorithm from a local file path. Ensure the provided path is correct and the file is a valid algorithm. ```csharp public abstract InstallationResult Install(string filePath) ``` -------------------------------- ### Full cTrader Algo Initialization with PlaceLimitOrderAsync (Python) Source: https://help.ctrader.com/ctrader-algo/references/General/Indicator?q= Complete Python script demonstrating the setup of a cTrader algo, including necessary imports and the use of PlaceLimitOrderAsync with a callback. ```python import clr clr.AddReference("cAlgo.API") # Import cAlgo API types from cAlgo.API import * # Import trading wrapper functions from robot_wrapper import * from System import Action class Test(): def on_start(self): api.PlaceLimitOrderAsync(TradeType.Buy, api.Symbol.Name, 10000, api.Symbol.Bid, Action[TradeResult](self.on_limit_order_placed)) def on_limit_order_placed(self, result): print(f"Limit order placed {result.PendingOrder.Label}") ``` -------------------------------- ### Plugins Property Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry?q= Gets a read-only list of all installed plugin types. ```APIDOC ## Plugins ### Description Gets the list of all installed plugins. ### Signature ```csharp public abstract IReadonlyList Plugins {get;} ``` ### Return Value IReadonlyList ``` -------------------------------- ### Robots Property Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry?q= Gets a read-only list of all installed robot types. ```APIDOC ## Robots ### Description Gets the list of all installed robots. ### Signature ```csharp public abstract IReadonlyList Robots {get;} ``` ### Return Value IReadonlyList ``` -------------------------------- ### Initialize and Configure WebView Source: https://help.ctrader.com/ctrader-algo/references/Controls/WebView Sets up the WebView control, its background color, and event handlers for navigation completion, message reception, and lifecycle events. It then navigates to a specified URL. ```Python self.webView = WebView() self.webView.DefaultBackgroundColor = Color.Red self.webView.NavigationCompleted += self.on_web_view_navigation_completed self.webView.WebMessageReceived += lambda args: print(f"Source: {args.Source} | Message: {args.Message}") self.webView.Loaded += lambda args: print(f"Webview loaded, IsLoaded: {args.WebView.IsLoaded}") self.webView.Unloaded += lambda args: print(f"Webview unloaded, IsLoaded: {args.WebView.IsLoaded}") self.webView.NavigateAsync(self.addressTextBox.Text) ``` -------------------------------- ### Indicators Property Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry?q= Gets a read-only list of all installed indicator types. ```APIDOC ## Indicators ### Description Gets the list of all installed indicators. ### Signature ```csharp public abstract IReadonlyList Indicators {get;} ``` ### Return Value IReadonlyList ### Related Tutorials * Managing Chart Indicators ``` -------------------------------- ### Get Prices Data Series (Python) Source: https://help.ctrader.com/ctrader-algo/references/MarketData/Bars/Bars Retrieves a DataSeries for a specified PriceType using the Python API wrapper. This example shows how to get Median prices. ```python import clr clr.AddReference("cAlgo.API") # Import cAlgo API types from cAlgo.API import * # Import trading wrapper functions from robot_wrapper import * class Test(): def on_start(self): medianPrices = api.Bars.GetPrices(PriceType.Median) print(medianPrices.Count) ``` -------------------------------- ### Start a Specific Plugin Source: https://help.ctrader.com/ctrader-ai-agent-connect/local-mcp/plugins?q= Use this prompt to initiate a plugin by its exact name. Ensure the plugin name is correctly specified. ```text Start the plugin called 'Trade copier'. ``` -------------------------------- ### C# TimerTick Example Source: https://help.ctrader.com/ctrader-algo/references/Timer/Timer This example shows how to subscribe to the TimerTick event and start a timer with a 1-second interval. It draws the current time on the chart every time the timer ticks. ```csharp protected override void OnStart() { Timer.TimerTick += OnTimerTick; Timer.Start(1);//start timer with 1 second interval } private void OnTimerTick() { Chart.DrawStaticText("time", Time.ToString("HH:mm:ss"), VerticalAlignment.Center, HorizontalAlignment.Center, Color.Red); } ``` -------------------------------- ### Example Usage 1 Source: https://help.ctrader.com/ctrader-algo/references/General/Plugin?q= Example of placing a buy limit order using the first overload of PlaceLimitOrderAsync. ```APIDOC ## Example 1 ```csharp PlaceLimitOrderAsync(TradeType.Buy, Symbol.Name, 10000, Symbol.Bid - 10 * Symbol.PipSize, "myLabel"); ``` ``` -------------------------------- ### C# Example: Subscribing to Ticks Source: https://help.ctrader.com/ctrader-algo/references/EventArgs/BarsTickEventArgs?q= This C# example demonstrates how to get tick data for a symbol and subscribe to upcoming ticks. It prints the last tick's bid, ask, and time. ```C# using cAlgo.API; using cAlgo.API.Internals; namespace cAlgo { // This sample indicator shows how to use Tick [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class TickSample : Indicator { private Ticks _ticks; [Parameter("Symbol Name", DefaultValue = "EURUSD")] public string InputSymbolName { get; set; } protected override void Initialize() { // Getting a symbol ticks data _ticks = MarketData.GetTicks(InputSymbolName); // Subscribing to upcoming ticks _ticks.Tick += Ticks_Tick; } private void Ticks_Tick(TicksTickEventArgs obj) { // Printing Last tick inside Ticks collection Print("Bid: {0} | Ask: {1} | Time: {2}", obj.Ticks.LastTick.Bid, obj.Ticks.LastTick.Ask, obj.Ticks.LastTick.Time); } public override void Calculate(int index) { } } } ``` -------------------------------- ### PlaceLimitOrder Examples Source: https://help.ctrader.com/ctrader-algo/references/General/Indicator Code examples demonstrating how to use the PlaceLimitOrder method in C# and Python. ```APIDOC ## Examples ### Example 1 (C#) ```csharp PlaceLimitOrder(TradeType.Buy, Symbol.Name, 100000, Symbol.Bid - 2*Symbol.PipSize); ``` --- ### Example 2 (C#) ```csharp PlaceLimitOrder(TradeType.Buy, Symbol.Name, 200000, Symbol.Bid - 2*Symbol.PipSize, "myLabel"); ``` --- ### Example 3 (C#) ```csharp PlaceLimitOrder(TradeType.Buy, Symbol.Name, 10000, Symbol.Bid - 5*Symbol.PipSize, "112", 10, 10, ProtectionType.Relative); ``` --- ### Example 4 (C#) ```csharp var targetPrice = Symbol.Bid - 5*Symbol.PipSize; var expiry = Server.Time.AddMinutes(30); PlaceLimitOrder(TradeType.Buy, Symbol.Name, 10000, targetPrice, "112", 10, 10 , ProtectionType.Relative, expiry); ``` --- ### Example 5 (C#) ```csharp var targetPrice = Symbol.Bid - 5*Symbol.PipSize; var expiry = Server.Time.AddMinutes(30); PlaceLimitOrder(TradeType.Buy, Symbol.Name, 10000, targetPrice, "112", 10, 10, ProtectionType.Relative, expiry, "first order"); ``` --- ### Example 6 (PYTHON) ```python api.PlaceLimitOrder(TradeType.Buy, api.Symbol.Name, 100000, api.Symbol.Bid - 2 * api.Symbol.PipSize) ``` ``` -------------------------------- ### Get Bot Positions Example Source: https://help.ctrader.com/ctrader-algo/references/Indicators/LinearRegressionSlope?q= Retrieves all open positions associated with the current algo label. ```python def get_bot_positions(self): return api.Positions.FindAll(api.Label) ``` -------------------------------- ### Install Algo Asynchronously from File Path Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Initiates an asynchronous installation of an algorithm from a local file path. Returns an operation object to track progress. ```csharp public abstract InstallationOperation InstallAsync(string filePath) ``` -------------------------------- ### OnStart Method Implementation in C# Source: https://help.ctrader.com/ctrader-algo/references/General/Robot Provides an example of overriding the OnStart method in C# to perform initialization tasks when a cBot begins execution. ```csharp protected override void OnStart() { //This method is invoked when the cBot is started. } ``` -------------------------------- ### Get Deal List Example Source: https://help.ctrader.com/ctrader-algo/documentation/plugins/sdk-integration-example Button to retrieve the list of deals. Requires a connected client. ```javascript e("button",{disabled:!connected,onClick:handleDealList},"getDealList"), ``` -------------------------------- ### Install Algo Asynchronously from File Path with Callback Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Initiates an asynchronous installation of an algorithm from a local file path, providing a callback function to be executed upon completion. ```csharp public abstract InstallationOperation InstallAsync(string filePath, Action callback) ``` -------------------------------- ### Full cBot Example with Canvas Source: https://help.ctrader.com/ctrader-algo/how-tos/all-algos/use-a-canvas A complete cBot implementation demonstrating how to initialize a Canvas, add it to the chart, and draw a rectangle and text. This example includes necessary using statements and the OnStart method for setup. ```csharp using System; using cAlgo.API; using cAlgo.API.Collections; using cAlgo.API.Indicators; using cAlgo.API.Internals; namespace cAlgo.Robots { [Robot(AccessRights = AccessRights.None, AddIndicators = true)] public class CanvasExample : Robot { [Parameter(DefaultValue = "Hello world!")] public string Message { get; set; } private Canvas _canvas; protected override void OnStart() { _canvas = new Canvas(); Chart.AddControl(_canvas); var rectangle = new Rectangle { Left = 50, Top = 50, Width = 100, Height = 50, StrokeColor = Color.Blue }; _canvas.AddChild(rectangle); var text = new TextBlock { Left = 70, Top = 70, Text = "Hello Canvas!", }; _canvas.AddChild(text); } protected override void OnTick() { // Handle price updates here } protected override void OnStop() { // Handle cBot stop here } } } ``` -------------------------------- ### Get Market Depth Example Source: https://help.ctrader.com/ctrader-algo/references/MarketData/MarketData Demonstrates how to retrieve market depth data for a symbol in C# and Python. ```csharp var md = MarketData.GetMarketDepth("EURUSD"); ``` ```python md = api.MarketData.GetMarketDepth("EURUSD") ``` -------------------------------- ### Install Algo and Check Result (C#) Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/InstallationResult?q= Use AlgoRegistry.Install to install an algo and check the Succeeded property of the returned InstallationResult. Print an error message if the installation fails. ```csharp using cAlgo.API; namespace cAlgo.API { [Robot(AccessRights = AccessRights.None)] public class TestExample : Robot { protected override void OnStart() { var result = AlgoRegistry.Install("path/to-algo-file.algo"); if (!result.Succeeded) Print($"Algo installation failed with error: {result.Error}"); } } } ``` -------------------------------- ### Get Bot Positions Example Source: https://help.ctrader.com/ctrader-algo/references/Indicators/Aroon Retrieves all open positions associated with the current bot's label. ```cAlgo return api.Positions.FindAll(api.Label) ``` -------------------------------- ### Install Another Algo Using AlgoRegistry Source: https://help.ctrader.com/ctrader-algo/guides/algo-registry This cBot demonstrates how to use the AlgoRegistry.Install method to programmatically install another cBot from a given URL. The installation success is printed to the log. ```csharp using System; using cAlgo.API; using cAlgo.API.Collections; using cAlgo.API.Indicators; using cAlgo.API.Internals; namespace cAlgo.Robots { [Robot(AccessRights = AccessRights.None, AddIndicators = true)] public class Installation : Robot { protected override void OnStart() { InstallationResult result = AlgoRegistry.Install("https://ctrader.com/algos/download/4392/"); Print(result.Succeeded); } protected override void OnTick() { } protected override void OnStop() { } } } ``` -------------------------------- ### PlaceLimitOrderAsync Example 7 (Python) Source: https://help.ctrader.com/ctrader-algo/references/General/Plugin?q= Python example demonstrating the use of PlaceLimitOrderAsync with basic parameters. ```APIDOC import clr clr.AddReference("cAlgo.API") # Import cAlgo API types from cAlgo.API import * # Import trading wrapper functions from robot_wrapper import * from System import Action class Test(): def on_start(self): api.PlaceLimitOrderAsync(TradeType.Buy, api.Symbol.Name, 10000, api.Symbol.Bid, Action[TradeResult](self.on_limit_order_placed)) def on_limit_order_placed(self, result): print(f"Limit order placed {result.PendingOrder.Label}") ``` -------------------------------- ### Get Account Balance in C# Source: https://help.ctrader.com/ctrader-algo/references/Account/IAccount Stores the account balance at the start and stop of the robot to print the difference. ```csharp double balanceBefore; double balanceAfter; protected override void OnStart() { // store the balance upon start up of the robot balanceBefore = Account.Balance; } protected override void OnStop() { // Store the balance upon stop of the robot. balanceAfter = Account.Balance; // print the difference Print("The difference of balanceBefore and balanceAfter is: {0}", balanceBefore-balanceAfter); } ``` -------------------------------- ### Access and Manage cTrader Algorithms (C#) Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry?q= Demonstrates how to retrieve specific algorithms by name and kind, iterate through all installed algorithms, and handle registry change events. It also shows how to install a new algorithm and check the installation result. ```csharp [Robot(AccessRights = AccessRights.None)] public class TestExample : Robot { protected override void OnStart() { if (AlgoRegistry.Get("Simple Moving Average", AlgoKind.StandardIndicator) is IndicatorType smaIndicatorType) Print($"Name: {smaIndicatorType.Name} | Parameters #: {smaIndicatorType.Parameters.Count} | Lines #: {smaIndicatorType.Lines.Count} | Bars: {smaIndicatorType.Bars.Count}"); if (AlgoRegistry.Get("Sample Break Even", AlgoKind.Robot) is RobotType robotType) Print($"Name: {robotType.Name} | Parameters #: {robotType.Parameters.Count}"); if (AlgoRegistry.Get("Sample Test Plugin", AlgoKind.Plugin) is PluginType pluginType) Print($"Name: {pluginType.Name} | Parameters #: {pluginType.Parameters.Count}"); foreach (var algo in AlgoRegistry) { Print($"Name: {algo.Name} | Kind: {algo.AlgoKind}"); } AlgoRegistry.AlgoTypeChanged += args => Print($"Algo updated: {args.AlgoTypeName}"); AlgoRegistry.AlgoTypeDeleted += args => Print($"Algo deleted: {args.AlgoTypeName}"); AlgoRegistry.AlgoTypeInstalled += args => Print($"Algo installed: {args.AlgoTypeName}"); var result = AlgoRegistry.Install("path/to-algo-file.algo"); if (!result.Succeeded) Print($"Algo installation failed with error: {result.Error}"); } } ``` -------------------------------- ### Get Dynamic Leverage Example Source: https://help.ctrader.com/ctrader-algo/documentation/plugins/sdk-integration-example Button to retrieve dynamic leverage information. Requires a connected client. ```javascript /* getDynamicLeverage */ e("div",null,[ e("button",{disabled:!connected,onClick:handleDynamicLeverage},"getDynamicLeverage"), " leverageId:", e("input",{style:{width:30},value:leverageId, onChange:ev=>setLeverageId(+ev.target.value)}), ]), ``` -------------------------------- ### C# Example: Subscribing to Ticks Source: https://help.ctrader.com/ctrader-algo/references/EventArgs/BarsTickEventArgs This C# example demonstrates how to get tick data for a symbol and subscribe to upcoming ticks. It prints the last tick's bid, ask, and time when a new tick arrives. ```csharp using cAlgo.API; using cAlgo.API.Internals; namespace cAlgo { // This sample indicator shows how to use Tick [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class TickSample : Indicator { private Ticks _ticks; [Parameter("Symbol Name", DefaultValue = "EURUSD")] public string InputSymbolName { get; set; } protected override void Initialize() { // Getting a symbol ticks data _ticks = MarketData.GetTicks(InputSymbolName); // Subscribing to upcoming ticks _ticks.Tick += Ticks_Tick; } private void Ticks_Tick(TicksTickEventArgs obj) { // Printing Last tick inside Ticks collection Print("Bid: {0} | Ask: {1} | Time: {2}", obj.Ticks.LastTick.Bid, obj.Ticks.LastTick.Ask, obj.Ticks.LastTick.Time); } public override void Calculate(int index) { } } } ``` -------------------------------- ### Install Algorithm Asynchronously from URI with Callback Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Initiates an asynchronous installation of an algorithm from a given URI, with a callback to handle the result. ```APIDOC ## InstallAsync (4 of 4) ### Description Installs an algo file from provided URI asynchronously. ### Method Signature ```csharp public abstract InstallationOperation InstallAsync(Uri uri, Action callback) ``` ### Parameters - **uri** (Uri): The URI of the algorithm file. - **callback** (Action): A callback action that will be invoked with the `InstallationResult` upon completion. ``` -------------------------------- ### BacktestingBar Time Property Source: https://help.ctrader.com/ctrader-algo/references/Plugin/Backtesting/DataSource/BacktestingBar Gets or sets the opening time of the bar. This property represents the timestamp when the bar started. ```csharp public DateTime Time {get; set;} ``` -------------------------------- ### PlaceLimitOrder Examples Source: https://help.ctrader.com/ctrader-algo/references/General/Indicator?q= Code examples demonstrating how to use the PlaceLimitOrder function in C# and Python. ```C# PlaceLimitOrder(TradeType.Buy, Symbol.Name, 100000, Symbol.Bid - 2*Symbol.PipSize); ``` ```C# PlaceLimitOrder(TradeType.Buy, Symbol.Name, 200000, Symbol.Bid - 2*Symbol.PipSize, "myLabel"); ``` ```C# PlaceLimitOrder(TradeType.Buy, Symbol.Name, 10000, Symbol.Bid - 5*Symbol.PipSize, "112", 10, 10, ProtectionType.Relative); ``` ```C# var targetPrice = Symbol.Bid - 5*Symbol.PipSize; var expiry = Server.Time.AddMinutes(30); PlaceLimitOrder(TradeType.Buy, Symbol.Name, 10000, targetPrice, "112", 10, 10 , ProtectionType.Relative, expiry); ``` ```C# var targetPrice = Symbol.Bid - 5*Symbol.PipSize; var expiry = Server.Time.AddMinutes(30); PlaceLimitOrder(TradeType.Buy, Symbol.Name, 10000, targetPrice, "112", 10, 10, ProtectionType.Relative, expiry, "first order"); ``` ```PYTHON api.PlaceLimitOrder(TradeType.Buy, api.Symbol.Name, 100000, api.Symbol.Bid - 2 * api.Symbol.PipSize) ``` -------------------------------- ### Initialize Custom Window and UI Elements Source: https://help.ctrader.com/ctrader-algo/guides/ui/Window Sets up a custom window with a grid layout, styling, and interactive elements like a text box for symbol input and a button to trigger updates. This is the entry point for creating a custom UI window. ```csharp protected override void Initialize() { _mainGrid = new Grid(2, 2) { BackgroundColor = Color.Gold, Opacity = 0.6, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, }; _mainGrid.Rows[0].SetHeightToAuto(); _mainGrid.Rows[1].SetHeightInStars(1); _style = new Style(); _style.Set(ControlProperty.Padding, 1); _style.Set(ControlProperty.Margin, 2); _style.Set(ControlProperty.BackgroundColor, Color.Black); _style.Set(ControlProperty.FontSize, 12); _symbol = Symbol; _symbolNameTextBox = new TextBox { Text = _symbol.Name, Style = _style, }; _mainGrid.AddChild(_symbolNameTextBox, 0, 0); _updateButton = new Button { Text = "Update", }; _updateButton.Click += OnUpdateButtonClick; _mainGrid.AddChild(_updateButton, 0, 1); _infoGrid = GetSymbolDataGrid(_symbol); _mainGrid.AddChild(_infoGrid, 1, 0, 1, 2); _window = new Window { Child = _mainGrid, Title = "Symbol Info", WindowStartupLocation = WindowStartupLocation.CenterScreen, Topmost = true }; _window.Show(); _symbol.Tick += Symbol_Tick; Timer.Start(TimeSpan.FromSeconds(1)); } ``` -------------------------------- ### Balance Property Source: https://help.ctrader.com/ctrader-algo/references/Plugin/Backtesting/BacktestingSettings?q= Gets or sets the initial balance for the backtesting simulation. This value is used to start the trading account. ```csharp public double Balance {get; set;} ``` -------------------------------- ### Robot AdditionalInfoUrl Configuration Source: https://help.ctrader.com/ctrader-algo/references/Attributes/PluginAttribute?q= Gets or sets additional info url. This example shows how to set the AdditionalInfoUrl for a Robot. ```csharp [Robot(AdditionalInfoUrl = "https://ctrader.com/")] public class AdditionalInfoUrlExampleBot : Robot ``` -------------------------------- ### Install Algorithm Asynchronously from File Path with Callback Source: https://help.ctrader.com/ctrader-algo/references/AlgoRegistry/AlgoRegistry Initiates an asynchronous installation of an algorithm from a local file path, with a callback to handle the result. ```APIDOC ## InstallAsync (2 of 4) ### Description Installs an algo file from provided URI asynchronously. ### Method Signature ```csharp public abstract InstallationOperation InstallAsync(string filePath, Action callback) ``` ### Parameters - **filePath** (string): The full file path to the algorithm file. - **callback** (Action): A callback action that will be invoked with the `InstallationResult` upon completion. ```