parameterValues 배열에서 cBot 매개변수는 고정된 순서로 전달되어야 합니다(cTrader UI에서 지정된 순서). 일부 매개변수가 누락된 경우 기본값이 자동으로 삽입됩니다.
백테스트 프로세스
프로그래밍 방식으로 백테스트를 시작할 때 여러 백테스트 프로세스를 병렬로 시작할 수 있으며, 이는 잠재적으로 많은 시간을 절약할 수 있습니다.
또한, 이 인터페이스는 ProgressChanged 및 Completed라는 두 가지 이벤트를 포함합니다. Completed 이벤트(BacktestingCompletedEventArgs)의 인수는 최종 백테스트 결과(JsonReport)의 JSON 객체를 포함하여 필요에 따라 해석하고 결과 통계를 새로운 사용자에게 표시할 수 있습니다.
예제 플러그인 생성
다음 플러그인은 활성 심벌 패널(ASP)에 새로운 블록을 표시합니다. 블록 내부에서 플러그인은 사용자가 소유한 모든 cBot을 선택하고 EURUSD h1에서 백테스트할 수 있도록 합니다. 백테스트가 완료되면 플러그인은 최종 ROI와 순이익을 표시합니다.
usingSystem;usingcAlgo.API;usingcAlgo.API.Collections;usingcAlgo.API.Indicators;usingcAlgo.API.Internals;usingSystem.Linq;usingSystem.Text.Json;usingSystem.Text.Json.Nodes;namespacecAlgo.Plugins{[Plugin(AccessRights = AccessRights.None)]publicclassBacktestingInPluginsSample:Plugin{// Declaring the necessary UI elements// and the cBot (RobotType) selected in the ComboBoxprivateGrid_grid;privateComboBox_cBotsComboBox;privateButton_startBacktestingButton;privateTextBlock_resultsTextBlock;privateRobotType_selectedRobotType;protectedoverridevoidOnStart(){// Initialising and structuring the UI elements_grid=newGrid(3,1);_cBotsComboBox=newComboBox();_startBacktestingButton=newButton{BackgroundColor=Color.Green,CornerRadius=newCornerRadius(5),Text="Start Backtesting",};_resultsTextBlock=newTextBlock{HorizontalAlignment=HorizontalAlignment.Center,VerticalAlignment=VerticalAlignment.Center,Text="Select a cBot...",};_grid.AddChild(_cBotsComboBox,0,0);_grid.AddChild(_startBacktestingButton,1,0);_grid.AddChild(_resultsTextBlock,2,0);varblock=Asp.SymbolTab.AddBlock("Backtesting Plugin");block.Child=_grid;// Populating the ComboBox with existing cBotsPopulateCBotsComboBox();// Assigning event handlers to the Button.Click,// ComboBox.SelectedItemChanged, and Backtesting.Completed events_startBacktestingButton.Click+=StartBacktestingButton_Click;_cBotsComboBox.SelectedItemChanged+=CBotsComboBox_SelectedItemChanged;Backtesting.Completed+=Backtesting_Completed;}protectedvoidStartBacktestingButton_Click(ButtonClickEventArgsobj){// Initialising and configuring the backtesting settingsvarbacktestingSettings=newBacktestingSettings{DataMode=BacktestingDataMode.M1,StartTimeUtc=newDateTime(2023,6,1),EndTimeUtc=DateTime.UtcNow,Balance=10000,};// Starting backtesting on EURUSD h1Backtesting.Start(_selectedRobotType,"EURUSD",TimeFrame.Hour,backtestingSettings);// Disabling other controls and changing// the text inside the TextBlock_cBotsComboBox.IsEnabled=false;_startBacktestingButton.IsEnabled=false;_resultsTextBlock.Text="Backtesting in progress...";}protectedvoidPopulateCBotsComboBox(){// Iterating over the AlgoRegistry and// getting the names of all installed cBotsforeach(varrobotTypeinAlgoRegistry.OfType<RobotType>()){_cBotsComboBox.AddItem(robotType.Name);}}protectedvoidBacktesting_Completed(BacktestingCompletedEventArgsobj){// Attaining the JSON results of backtestingstringjsonResults=obj.JsonReport;// Converting the JSON string into a JsonNodeJsonNoderesultsNode=JsonNode.Parse(jsonResults);// Attaining the ROI and net profit from backtesting results_resultsTextBlock.Text=$"ROI: {resultsNode["main"]["roi"]}\nNet Profit: {resultsNode["main"]["netProfit"]}";// Re-enabling controls after backtesting is finished_cBotsComboBox.IsEnabled=true;_startBacktestingButton.IsEnabled=true;}protectedvoidCBotsComboBox_SelectedItemChanged(ComboBoxSelectedItemChangedEventArgsobj){// Updading the variable to always contain// the cBot selected in the ComboBox_selectedRobotType=AlgoRegistry.Get(obj.SelectedItem)asRobotType;}}}
플러그인은 백테스트 프로세스의 상태에 동적으로 반응합니다. 백테스트가 완료되면 플러그인은 TextBlock에 결과를 표시합니다. _startBacktestingButton과 _cBotsComboBox는 백테스트 동안 비활성화됩니다.
요약
플러그인을 통한 백테스트는 cTrader가 제공하는 강력한 백테스트 로직 위에 UI 확장을 구축할 수 있는 강력한 기능입니다. AlgoRegistry와 같은 다른 API 멤버와 결합하여 플러그인에서의 백테스트는 cTrader 알고리즘을 판매하고 개발하는 모든 사람에게 많은 가능성을 제공합니다.