[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]publicclassSupercBot:Robot{// === Fields ===// Declare indicators, variables or parameters, state flags, etc. hereprotectedoverridevoidOnStart(){// Called once when the cBot starts// Initialize indicators, variables, parameters, or subscribe to events}protectedoverridevoidOnTick(){// Called on every market tick// Useful for high-frequency strategies (but may be CPU-intensive)}protectedoverridevoidOnBar(){// Called at the start of each new bar (candle)// Preferred for most strategies to reduce CPU load}protectedoverridevoidOnStop(){// Called when the cBot is stopped// Useful for cleanup, logging, or resetting state}// === Custom Methods ===// Add your own helper methods below to modularize your logicprivatevoidExampleMethod(){// A placeholder for your custom logic (e.g., strategy evaluation)}privatevoidClosePositions(){// Example of a method that could close open positions}privateboolCheckCondition(){// Example of a method that could return a boolean conditionreturnfalse;}}
classSupercBot():# === Fields ===# Declare indicators, variables, state flags, etc. here# self.example_indicator = None# self.some_flag = Truedefon_start(self):# Called once when the cBot starts# Initialize indicators, variables, parameters, or subscribe to eventspassdefon_tick(self):# Called on every market tick# Useful for high-frequency strategies (but may be CPU-intensive)passdefon_bar_closed(self):# Called at the start of each new bar (candle)# Preferred for most strategies to reduce CPU loadpassdefon_stop(self):# Called when the cBot is stopped# Useful for cleanup, logging, or resetting statepass# === Custom Methods ===# Add your own helper methods below to modularize your logicdefexample_method(self):# A placeholder for your custom logic (e.g., strategy evaluation)passdefclose_positions(self):# Example of a method that could close open positionspassdefcheck_condition(self):# Example of a method that could return a boolean conditionreturnFalse
这些方法通常默认包含:
on_start 方法在每次启动 cBot 实例时调用。
on_tick 方法在每个报价变动时调用。
on_bar_closed 方法在每个柱形图更新时调用。
on_stop 方法在每次新 cBot 实例停止运行时调用。
on_tick 方法在每个报价变动时执行某个操作,这使得它对 CPU 的要求很高。 在许多交易情况下,没有必要在每个报价变动时执行交易操作。 使用 on_bar_closed 方法更加实用。