Events
Last updated
Last updated
AgenaTrader is an event-oriented application by definition.
Programming in AgenaTrader using the various application programming interface (API) methods is based initially on the Overwriting of routines predefined for event handling.
The following methods can be used and therefore overwritten:
OnBrokerConnect() is only available for overwriting in UserStrategies!
OnBrokerConnect() method is invoked each time the connection to the broker is established. With the help of OnBrokerConnect(), it is possible to reassign the existing or still open orders to the strategy in the event of a connection abort with the broker and thus allow it to be managed again.
none
OnBrokerDisconnect() is only available for overwriting in UserStrategies!
OnBrokerDisconnect() method is invoked each time the connection to the broker is interrupted.
An object from TradingDatafeedChangedEventArgs
The OnInit() method is called up once at the beginning of an indicator or strategy calculation. This method can be used to set indicator properties, initialize your own variables, or add plots.
none
none
IsAutoScale
Additional Keywords for Strategies
EntriesPerDirection
Caution: The OnInit() method is not only called up at the beginning of an indicator or strategy calculation, but also if the chart is reloaded unexpectedly or if the properties dialog of indicators is opened and so on. Developers of custom AgenaScripts should NOT use this method for running their own routines, opening forms, performing license checks, etc. The OnStart() method should be used for these kind of tasks.
The OnCalculate() method is called up whenever a bar changes; depending on the variables of CalculateOnClosedBar, this will happen upon every incoming tick or when the bar has completed/closed. OnCalculate is the most important method and also, in most cases, contains the largest chunk of code for your self-created indicators or strategies. The editing begins with the oldest bar and goes up to the newest bar within the chart. The oldest bar has the number 0. The indexing and numbering will continue to happen; in order to obtain the numbering of the bars you can use the current bar variable. You can see an example illustrating this below.
none
In an indicator, or strategy, the click event of the mouse can be processed. For this, it is necessary to program an EventHandler as a method and add this method to the Chart.ChartPanelMouseDown event.
It is important to remove the EventHandler from the OnDispose() method, otherwise the EventHandler will still be executed even if the indicator has been removed from the chart.
In an indicator, or strategy, the current position of the mouse can be evaluated and processed. For this, it is necessary to program an EventHandler as a method and add this method to the Chart.ChartPanelMouseMove event.
It is important to remove the EventHandler from the OnDispose() method, otherwise the EventHandler will still be executed even if the indicator has been removed from the chart.
The OnDispose() method can also be overridden in order to once again free up all the resources used in the script.
none
Caution: Please do not override the Dispose() method since this can only be used much later within the script. This would lead to resources being used and held for an extended period and thus potentially causing unexpected consequences for the entire application.
The OnLevel1() method is called up when a change in level 1 data has occurred, meaning whenever there is a change in the bid price, ask price, bid volume, or ask volume, and of course in the last price after a real turnover has occurred. In a multibar indicator, the rocessingBarSeriesIndex property identifies the data series that was used for an information request for OnLevel1(). OnLevel1() will not be called up for historical data.
Notes regarding data from Yahoo (YFeed)
The field "LastPrice" equals – as usual – either the bid price or the ask price, depending on the last revenue turnover.
The MarketDataType" field always equals the "last" value
The fields "Volume", "BidSize" and "AskSize" are always 0.
The OnLevel2() method is called up whenever there is a change in the level 2 data (market depth). In a multibar indicator, the ProcessingBarSeriesIndex property identifies the data series for which the OnLevel2() method is called up. OnLevel2 is not called up for historical data.
An object from Level2Args
The OnOrderChanged() method is called up whenever the status is changed by a strategy-managed order. A status change can therefore occur due to a change in the volume, price or status of the exchange (from “working” to “filled”). It is guaranteed that this method will be called up in the correct order for the relevant events.
Important note: If a strategy is to be controlled by order executions, we highly recommend that you use OnOrderExecution() instead of OnOrderChanged(). Otherwise there may be problems with partial executions.
An order object of the type IOrder
The OnOrderExecution() method is called up when an order is executed (filled). The status of a strategy can be changed by a strategy-managed order. This status change can be initiated by the changing of a volume, price or the status of the exchange (from “working” to “filled”). It is guaranteed that this method will be called up in the correct order for all events.
An execution object of the type IExecution
OnInit OnStart OnStop OnDispose
none
The OnStop() method is called up once a script is terminated. This can be when e.g. an indicator was removed from the chart or a column with an indicator / a scripted condition was removed from the scanner.
none
More information can be found here:
More information can be found here:
Caution: the numbering/indexing is different from the bar index – see
More information can be found here:
See and
More information can be found here:
More information can be found here:
More information can be found here:
More information can be found here:
OnOrderExecution() will always be executed AFTER
More information can be found here:
The OnStart() method can be overridden to initialize your own variables, perform license checks or call up user forms etc. OnStart() is only called up once at the beginning of the script, after and before are called up which results in the following execution sequence:
See
More information can be found here:
See
More information can be found here: