Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ATRExitInputs = []string{"stop-atr", "take-profit-atr"}
ATRExitInputs are the flags of the stop loss and the take profit in ATR from the entry, taken by the strategies placing levels of their own too (eg: fimathe), which then replace them, see strategies.BracketConfig.ATRStop.
var BracketInputs = []string{"stop-atr", "take-profit-atr", "max-bars", "min-atr-pct"}
BracketInputs are the flags of Inputs.Bracket, the ones of the strategies placing each entry with its stop loss and take profit at the broker.
Functions ¶
func Run ¶
func Run(agent Agent)
Run runs a strategy of agent on MetaTrader 5 symbols, from the command line: the shared flags defined here, the ones of its strategies by the agent before:
# backtest on the candles written by `xtrader download`, 0.05 lot of gold # and 0.01 of bitcoin, converted with the contract sizes the package knows # (100 ounces, 1 bitcoin) go run ./agents/trendagent -pair XAUUSDm,BTCUSDm -csv xau-1h.csv,btc-1h.csv -lot 0.05,0.01 # the same on gold, with a stop 3 ATR from the entry close go run ./agents/trendagent -pair XAUUSDm -csv xau-1h.csv -lot 0.05 -stop-atr 3 # a symbol of unknown contract size, eg: silver, 5000 ounces in a lot go run ./agents/trendagent -pair XAGUSDm -csv xag-1h.csv -lot 0.01 -mt5-contract-size 5000 # the market data of the bridge, trading a paper wallet go run ./agents/trendagent -mode paper -pair XAUUSDm -lot 0.05 # the same, the stop loss and the take profit placed with the entry, a # stop loss losing 1 and a take profit earning 2 in the currency of the # account (of the simulation in paper: the quote, USD for XAUUSDm) in place # of the ones in ATR go run ./agents/trendagent -strategy matrend -mode paper -pair XAUUSDm -lot 0.05 \ -stop-value 1 -take-profit-value 2
The live mode takes the same flags from the settings of the agent in the database of the controller, eg: -strategy matrend -pair XAUUSDm -lot 0.05 -broker-stop, or -position-fraction 0.1 -leverage 20 for positions of 10% of the free margin at 1:20, or -mt5-comment nb:orb-ny for a second bot of a strategy on the account, with a magic number of its own.
MT5 trades the account the terminal is logged in, through the bridge of -mt5-bridge (tools/mt5bridge/mt5bridge.py, running with the terminal), and refuses a real account unless -mt5-live is set. The account must be hedging, as the ones of Exness: the adapter nets the positions of the bot, the ones of its magic number, -mt5-magic (by default a hash of its comment, -mt5-comment, "nb:" and the strategy name unless set), so bots of magic numbers of their own share an account, next to the manual trades: two bots of a strategy on one account need comments of their own, eg: nb:emacross-15m and nb:emacross-1h. -lot is read in MT5 lots and converted into units of the base asset with the contract size of the symbol (100 ounces a lot of XAUUSDm), or in units with -mt5-size unit; a backtest takes the contract sizes of -mt5-contract-size, else the ones the package knows. The paper mode reads the market data of the bridge only. Leverage needs the margin of the account, which the paper wallet doesn't simulate, so it is for the live mode only.
The live mode runs launched by the controller (cmd/controller), from the settings of the agent in its database, its flags and the token of the bridge, which keeps its orders (see package remote): the order controller replays them on a restart, so the positions it followed and the history of the chart are the bot's own. The backtest and paper modes keep them in memory.
-api serves the bot to the controller, at an address such as localhost:5556: once the backtest ends, or while the bot trades in paper and live modes. The controller serves the bots of its database on the web dashboard and on Telegram, relaying the orders, messages and errors of the bot. Keep the address on localhost, as its control panel (start/stop and manual orders) operates the bot: in paper mode from the trade panel of the dashboard and from Telegram, in live mode from the channels its settings turn on, the trade panel and the Telegram controls, switched while it runs; the dashboard starts and stops the bot whatever its trade panel, which gates the orders only.
Types ¶
type Agent ¶
Agent is a binary running strategies (see Run): its name, of its usage, and its strategies, the default one first.
func (Agent) CheckInputs ¶
CheckInputs fails on a flag set that the strategy name of the agent doesn't take, see checkInputs.
func (Agent) DefaultStrategy ¶
DefaultStrategy returns the strategy the agent trades without -strategy, its first one, "" for none: the one of agentapi.DefaultStrategy for its kind, as the comment of its orders on MT5, and so its magic number, depend on it.
type Inputs ¶
type Inputs struct {
Set map[string]bool
Timeframe string
Direction strategies.RKDirection
StopATR, TrailingATR float64
TakeProfitATR, MinATRPct float64
MaxBars int
StopValue, TakeProfitValue float64
MinValue, Fraction, Leverage float64
Lots map[string]float64
MaxRiskPct float64
}
Inputs are the inputs of the strategies shared by the agents: the flags set, the timeframe (for the bracket strategies, only when set: each keeps its own), the side of the positions, the stops, the targets, the sizing and the max risk of an entry.
func (Inputs) Bracket ¶
func (in Inputs) Bracket(cfg *strategies.BracketConfig, timeframe *string)
Bracket sets the exits and the sizing of a bracket strategy from the inputs, its timeframe when -timeframe is set, and its max risk when -max-risk-pct is set. Unset, each keeps its default.
type Strategy ¶
type Strategy struct {
Name string
About string
Inputs []string
New func(in Inputs) (strategy.Strategy, error)
}
Strategy is a strategy of an agent: its name for -strategy, what it trades, the flags it takes of its own (see BracketInputs), refused with the other strategies of the agent, and how it is created from the inputs of the agent.
func Signals ¶
Signals returns the signal strategies of names, see strategies.NewSignal: each takes the inputs of Inputs.Bracket, and -trailing-atr the ones trailing their stop loss, eg: donchianatr (see TrailingSignals).
func TrailingSignals ¶
TrailingSignals is Signals, each strategy taking -trailing-atr, which trails its stop loss (strategies.SignalConfig.TrailingATR): the strategies of momentumagent, which took it before it was declared.