Agent trading settings

Agent settings

You can access the agent settings in the Autotrading Control Center window. The Autotrading Control Center window can be opened by selecting the Main menu item: Trading - Autotrading Control Center.

You can configure an agent both during and after its creation. To configure an already created agent, use the shortcut buttons

Shortcut buttons:

  • The button with the image of the list opens the tab of the common settings of the agent

  • The gear button opens the agent's trading settings

Common agent settings

After creating an agent, you can open this menu by clicking on the list icon in the Agent column

In the "Common" menu, you can select the required script from the list, specify the trading instrument, and also specify the type of limit management.

In order to make changes to the Common settings of an agent, it is necessary to stop the agent. Make sure the button in the Status column is in the disabled (gray) state

Menu itemDescription

Script

Selecting a script from the list to create an agent.

Trading name (Optional field)

You can give an optional name to the agent for easy tracking of processes. This field is optional. Changing or assigning a trading name will result in the loss of the agent's trading statistics if the agent has already made trades or placed orders.

Limit management type

Select how to manage the funds available to the agent. Possible values: "Managed by agent", "In money equivalent", "In lots", "% of portfolio", "Maximum % of portfolio"

Volume of limit

The value of the funds limit, which is set in accordance with the method for determining the limit in the "Limit management type" field.

Sources

Opens a window for choosing instruments.

Limit management type

Calculation of the number of lots in the application:

  • In lots. The number in the "Volume of limit" field is multiplied by the number in the position opening block;

  • Managed by agent. The number in the position opening block is the number of lots in the order. The "Volume of limit" field is ignored;

  • In money equivalent. The number in the "Volume of limit" field is divided by the current price of the instrument and multiplied by the number in the position opening block;

  • % of portfolio. The number in the "Volume of limit" field is multiplied by the amount of money on the account and divided by the current price of the instrument and multiplied by the number in the position opening block;

  • Maximum % of portfolio. When submitting an application, the amount of free money is determined and the application goes without exceeding this amount. ("Maximum % of portfolio", differs in that if there is not enough free money in the portfolio, then securities for a smaller amount will be purchased.)

Source selection

By clicking on the wallet icon in the Sources line, you can open the menu for changing the provider in the sources. This option can be useful if you use multiple sources in your script and need to change the account in one of them.

The "+ Add Instrument" button allows you to add another data source in the agent. An example of one of the options for using the button:

If your provider limits the amount of data you can upload, such as a few months, you can download ticks for a longer period of time as a text file and add that data as a second source.

Agent trading settings

The agent's Trading settings as well as the Common settings are available when creating a new agent, as well as the Trading settings window can be opened by clicking on the gear icon in the Agent column

Script execution

Menu itemDescription

Send position entry order immediately

A parameter that determines the possibility of automatic entry into a position without manual confirmation. The entry command will be executed only if the entry signal was formed on the last closed bar.

Send position exit order immediately

A parameter that determines the possibility of automatic exit from a position without manual confirmation. The exit command will be executed in two ways depending on the auto-close setting. If the auto-close parameter is equal to zero, the command will be executed with the formation of a price based on the last closed bar, otherwise the command will be executed on the market in accordance with the auto-close settings.

Automated opening (bars)

The number of bars during which a missed entry will be executed automatically by the market if the "Send position entry order immediately" option is selected. Next, a message will be displayed about the missed entry and the need for manual intervention. It should be remembered that if you set a large interval, then opening a position may occur too late and the entry price will be very different from the expected one. Attention! "Change By ...". For position change blocks, auto-opening does not work!

Blocks "By market at fixed price" for auto opening

Blocks the "by market" option with a fixed price for auto-opening and applies to the Commands Manager.

Automated closing (bars)

The number of bars during which the missed exit will be closed automatically by the market if the "Execute exits immediately" option is selected. Further, if the set number of bars is not enough, a message will be displayed about the missed exit and the need for manual intervention. Attention! "Change By ...". Auto-closing does not work for position change blocks! Auto-closing when using "Change By" works only if there was an attempt to close the position at 0 and failed.

Blocks "By market at fixed price" for auto closing

Blocks the "by market" option with a fixed price for auto-closing and applies to the Commands Manager

Ignore positions outside history

Ignores (does not count) positions that were closed outside the requested historical data.

Inform about missed entries

Notifies about missed entries to a position.

Do not entry position if there's missed exit

Does not open new positions if there is a "position exit missed" error.

Do not notify about recalculation

Does not notify about script recalculation.

Keep virtual position active. Maximum Bars

Determines how long to inform about a missed position before it disappears (0 - infinite, any other positive value is equal to the number of candles).

Ignore exit signal not on latest bar

Ignores the signal to exit the position, created by the agent not on the last (current) bar.

Wait for exit

The number of candles during which the program will wait for the execution of the limit order to exit the position. Then the application will be cancelled. The setting works for an active order (the price of the instrument touched the order price, but was not executed due to lack of liquidity)

Wait for entry

The number of candles during which the program will wait for the execution of a limit order to enter a position. Then the application will be cancelled. The setting works for an active order (the price of the instrument touched the order price, but was not executed due to lack of liquidity)

Add order commission

Take into account the commission from trade requests in profit calculation. If the broker sends a commission in transactions, then the commission will be taken into account in the results of the agent's trading.

Script execution. Additional Information

Execute entry/exit immediately

Starts automatic trading. If this option is disabled, signals will only be sent to the Command Manager for manual execution.

Automated opening/closing

Performs automatic market execution if the order was not executed for the specified number of bars in the Wait for entry menu item (activated when the price is touched), or if there was a failure in the Internet connection. Actually, you can set a larger value than 2 and 3, the main thing is that it should not be more than the bars loaded into the script. You can view it in the "Log" window of the agent or script. When compiling or recalculating, the number of bars is written.

Ignore positions outside of history

When trading, in the absence of a loaded history, requests to the agent are drawn on the first bar of the agent. The flag disables the drawing of these trades. Set the script properties in such a way that at least the agent sees the last entry and exit from the position. If the agent "does not look" at the history of his trades to place new orders (for example, he does not consider the average entry price of all trades), then the flag can be set. If you need a story, then it is better to download more of it. By limiting the Maximum bars parameter in the script Properties.

Inform about missed entries

If the flag is set, then when a position entry signal is missed, a notification will be sent in messages or by mail (if the notification manager is configured).

Do not entry position if there's missed exit

The flag prohibits the opening of new positions if the signal to exit the position was missed.

Do not notify about recalculation

The flag prohibits the output of information in messages and mail, when recalculating the agent. As a rule, it is used for very fast scripts, where non-execution of orders is due to liquidity in the market. This is a very important flag for the Support service. If it is set, the agent's recalculations are not written to the log. By setting this flag, you understand that it is pointless to analyze the requests of an agent who submits them in hundreds a day. Which of them worked and which did not, he will count himself and put up the missing.

Keep virtual position active. Maximum Bars

Adjusts the number of bars, how long the last counted signal in the history is valid. For example, if you set 10, and the last signal was 11 bars ago, the signal will disappear from the chart and in the Command Manager (even if the entry is skipped), and the agent will count a more "fresh" signal.

Ignore exit signal not on latest bar

The flag acts like the "Keep virtual position active. Maximum Bars" setting, but only works to exit the position and only for one bar.

By setting this flag, you expect the agent to place each order to exit a position by only one bar. On the next bar, if the signal from the script continues, the order will continue to stand. If the price in the order changes, the order will change. But as soon as the signal to place is lost in the agent, the order will be canceled, even if it was active ("Active" - ​​it means that the price on the market touched the order, but there was not enough liquidity for execution).

As a rule, the flag is used for scripts that output only take profits, but can also be used for other purposes. The main thing is to understand the mechanism, that is, with this flag, you cannot use Auto-Close or Wait for entry.

Wait for entry/exit execution

Works only with conditional and limit orders. It is included in the event that the current price touched the order price, but was not executed. The number of bars during which the order will continue to stand in the order queue. After the expiration of the number of bars, the order will simply be cancelled. This parameter must be configured in conjunction with "Automated opening/closing ".

If "Automated opening/closing" is greater than Wait for execution, then after the unexecuted order is canceled, a replacement order "on the market" will go. If "auto" is less than "wait", then the request will simply be canceled and the agent will count the next signal. The flag also applies to orders for which the flag "on the market with a fixed price" applies.

Add order commission

Whether to take into account the commission coming from the broker (not all brokers send commission in transactions). Not all instruments can be recalculated (for example, for the MOEX futures market, the lot size is always equal to 1), so the commission can be very high in relation to the income schedule. When you see that the commission is too high, do not set the flag, this will exclude the commission from the income calculation. Whether the commission comes in transactions from the broker, you can see in the "My trades" table.

Placing orders

Menu itemDescription

Slippage in price steps

The amount of slippage in price steps of the instrument, which will be transferred to the order created by the agent. An order of the "By market" type does not take into account the slippage settings and is executed at the first offered price. Attention! The slip settings are cumulative.

Slippage in %

The amount of slippage in percent, which will be transferred to the order created by the agent.

Take-profit without slippage

A take-profit order is created not as a "conditional" order, but as a "limit" order (but without slippage).

Open by limit orders

To open a position, the program creates limit orders without slippage.

Convert "by market" to "limit" orders

A market order is created not at the current price, but at the bar's opening price (as in calculations) +/- slippage if "Interval+trade" is selected. If the "Interval" recalculation mode is selected, then the closing price of the last candle is taken.

Incorrect "stop" orders is being converted to "by market" orders

Conditional orders for closing a position with a price worse than the market are set as market orders. If the message appears: "Conditional order on signal '{0}' may not work, because the current market price is {1} (Condition price {2})!" the order leaves as a market order, not as a conditional one.

Order Expiration, Days

Allows you to send the expiration time in days to the broker in a conditional order. By default, the program places conditional orders for two days. It is recommended to use when working with large timeframes. (does not apply to cryptocurrency markets)

Placing orders. Additional Information

Slippage

Works only for conditional orders! For other order types, slippage is not required. In the trading settings, the slippage is set for the entire script, both slippages are added. If you set the slippage both as a percentage and in price steps, then both slippages are summed up. This slippage has a lower priority than slippage directly in the entry and/or exit block of a position (set in absolute values). If there are 5 points in a certain entry block, and 1% in the total slippage, then 5 points will be taken for orders of this entry block, and 1% for the rest of the script.

Take profit without slippage

By default, the "Position close By take-profit" block places a conditional order! This flag changes the order type to "Limit". It should be remembered that for those data providers that have "associated requests", the flag turns them off. And between the stop and profit on each recalculation, the program will select only one order, the price of which is currently closer to the current price.

Open by limit orders

Flag specifically for entry blocks to the "If Greater/If Less" position. By default, these blocks are for placing conditional orders. If the flag is set, then the type of orders is changed to "Limit". We recommend using "Open by limit orders" for real trading.

Convert "by market" to "limit" orders

The flag was specially created for the "By market" blocks, it changes the type of orders from "By market" to "Limit", rather "conditionally limit". The order will be placed with the closing price of the previous bar, taking into account slippage. The flag affects all agent signals, including Auto-open and Auto-close signals in the command manager. If there is a recalculation "Interval + trade" in the laboratory, then the order will be placed with the Opening price of the current bar.

Incorrect "stop" orders is being converted to "by market" orders

Works for conditional closing orders. Places market orders instead of limit orders. It also works for "Take profit without slippage", since it first checks that the price is bad, only then the "Take profit without slippage" flag works.

Explanation on the example of a stop loss order:

Stop loss is a conditional order. When the price touches the condition price, it will be converted into a limit order with the condition price "+- slippage". Since the stop loss changes stepwise, at the next recalculation the price of the condition may turn out to be much worse than the market immediately at the opening of the candle. This is the “bad” trade order. It turns out that you have a long position. The price is now 100, and you submit an order to close if it is less than 120. Or you have a short position, the price is 100, and you want to close the position if the price is more than 80. Such an order will not be executed until the price returns to the price of the "+-" condition. slippage". If the bad market orders option is enabled, then a market order will be placed instead of a limit order. For a stop loss of a short position, respectively, a market order to buy, and for a stop loss of a long position, a market order to sell. Therefore, transactions will take place on the best buy and sell offers that will be in the order queue at the time of recalculation. As a rule, this mechanism works automatically for brokers, but some brokers (for example, Finam) do not have it, in this case it is recommended to set the flag.

Events

Events are the operations of a broker or exchange with an order during the execution of a transaction or general events related to the program.

Read more about Events in the article: Event recalculations

EventDescription

Order rejected

The broker (or exchange) rejected the application

Order filled

There were trades on the market that satisfied the entire requested volume in the order

Order canceled

On the recalculation of the agent, the script calculated that there was no signal, the request must be canceled. The program sends a command to the broker. This event is the result of a "Order Canceled" response from the broker.

Order quantity changed

In the Agent, on the main recalculation, the script calculated the change in the number of lots, which differs from the previous one.

Position opened

The signal was executed, the program received the numbers: Transaction, Order, Deals. All numbers are tied to the agent's signal through the portfolio number.

Position closed

The signal to close the position has been executed. The position opening portfolio number has the filled position closing portfolio number.

Trading is started

Received a status from the exchange that trading is open. Most often, the program uses the first deal of the market. The start of trading is determined by the first quote of the current day, since it is almost always faster than the trading status that the exchange sends for the instrument.

Trading is stopped

Received a status from the exchange that trading has been stopped.

Bar closed, not trades

The bar closed according to server time, but there are no new deals

Some questions and answers

Additional closing of a position

If the "Wait for exit" parameter is activated, then the position is additionally closed within the number of candles specified in this parameter. Then the position is additionally closed by the market during the number of candles specified in the "Automated closing (bars)" parameter. The number of bars in "Automated closing (bars)" must be greater than in "Wait for exit". If the value in the "Automated closing (bars)" parameter is less than or equal to "Wait for exit", then auto-close does not work.

Adding a position

If the "Wait for entry" parameter is activated, then the position is added within the number of candles specified in this parameter. Then the position is added to the market during the number of candles specified in the "Automated opening (bars)" parameter, except for the case of using the "Change By" blocks.

The number of bars in "Automated opening (bars)" must be greater than in "Wait for entry". If the value in the "Automated opening (bars)" parameter is less than or equal to "Wait for entry", then auto-opening does not work.

Additional set of positions or closing a position

Question:

If there are 2 lots to close a position in a limit order. During the first recalculation, only 1 lot was closed. Will the order for the remaining 1 lot be left or re-submitted further if there is a signal?

Answer:

The order will remain at the same price as long as the "Wait for exit" is in effect.

To implement a rearrangement of a limit order to close a position, you can use the "Quantity" and "Updatable value" blocks, together with the "Ignore exit signal not latest bar" setting.

If "Automated closing (bars)" is selected, the rest of the position will be closed automatically according to the market. If "Wait for exit" is less than "Automated closing (bars)" - as soon as "Wait for exit" ends.

All the same applies to the "additional set" of lots in a position, in accordance with the names of the settings. For Opening a position, the "Keep virtual position active. Maximum Bars" setting is in effect. Question:

If "Wait for exit" is NOT set and "Automated opening (bars)" is NOT set and the "Keep virtual position active. Maximum Bars" parameter = 0. We placed a limit order for 10 lots, executed 5 lots. Signal for one bar. How will the program behave?

Answer:

The program will remove the balance even without messages, will keep 5 lots, the algorithm will continue to be executed with the accumulated number of lots.

"Ignore positions outside history"

Question:

"What should I do if my entry point has gone beyond the history. The history is loaded for the last two days, and the entry was 4 days ago. How will the script or agent behave in this case? Will this transaction be closed according to the condition described in the script or will the calculation be carried out incorrectly and there should not be such transactions? "

Answer:

If there is no entry bar, then the data of this bar is often unknown. It is necessary to place such a number of bars that the last entry into the position is always visible in the history.

The calculation MAY be incorrect.

Question:

"Situation 2: the script makes several consecutive entries, some of which go beyond the history. How will the positions that have gone beyond the history be closed in this case? Thank you in advance"

Answer:

MAY NOT close correctly. Signals can be triggered that could not have been when loading the entire history. More depends on the values that calculate the exit from the position and settings. For example, if it is in the trading settings "Ignore positions out of history"

Recommendation: Set the number of bars so that the open entries to the position are on their bars and do not move to the first bar of the loaded history.

Last updated