DEXStrategy#

tradingstrategy.frameworks.backtrader.DEXStrategy class.

class DEXStrategy[source]#

Bases: Strategy

A strategy base class with support for Trading Strategy DEX specific use cases.

__init__(*args, **kwargs)[source]#

Methods

__init__(*args, **kwargs)

add_timer(when[, offset, repeat, weekdays, ...])

Note: can be called during __init__ or start

addindicator(indicator)

addminperiod(minperiod)

The passed minperiod is fed to the lines

advance([size])

backwards([size, force])

bind2line([owner, own])

bind2lines([owner, own])

bindlines([owner, own])

buy(*args, **kwargs)

Stamps each trade with a timestamp.

buy_bracket([data, size, price, plimit, ...])

Create a bracket order group (low side - buy order - high side).

cancel(order)

Cancels the order in the broker

clear()

close(*args, **kwargs)

Counters a long/short position closing it

extend([value, size])

forward([value, size])

get_timestamp()

Get the timestamp of the current candle

getdatabyname(name)

Returns a given data by name using the environment (cerebro)

getdatanames()

Returns a list of the existing data names

getindicators()

getindicators_lines()

getobservers()

getposition([data, broker])

Returns the current position for a given data in a given broker.

getpositionbyname([name, broker])

Returns the current position for a given name in a given broker.

getpositions([broker])

Returns the current by data positions directly from the broker

getpositionsbyname([broker])

Returns the current by name positions directly from the broker

getsizer()

Returns the sizer which is in used if automatic statke calculation is used

getsizing([data, isbuy])

Return the stake calculated by the sizer instance for the current situation

getwriterheaders()

getwriterinfo()

getwritervalues()

home()

incminperiod(minperiod)

The passed minperiod is fed to the lines

minbuffer(size)

Receive notification of how large the buffer must at least be

next()

This method will be called for all remaining data points when the minimum period for all datas/indicators have been meet.

next_open()

nextstart()

This method will be called once, exactly when the minimum period for all datas/indicators have been meet.

nextstart_open()

notify_cashvalue(cash, value)

Receives the current fund value, value status of the strategy's broker

notify_data(data, status, *args, **kwargs)

Receives a notification from data

notify_fund(cash, value, fundvalue, shares)

Receives the current cash, value, fundvalue and fund shares

notify_order(order)

Receives an order whenever there has been a change in one

notify_store(msg, *args, **kwargs)

Receives a notification from a store provider

notify_timer(timer, when, *args, **kwargs)

Receives a timer notification where timer is the timer which was returned by add_timer, and when is the calling time.

notify_trade(trade)

Receives a trade whenever there has been a change in one

once(start, end)

Called to calculate values at "once" when the minperiod is over

oncestart(start, end)

It will be called when the minperiod phase is over for the 1st post-minperiod value

order_target_percent([data, target])

Place an order to rebalance a position to have final value of target percentage of current portfolio value

order_target_size([data, target])

Place an order to rebalance a position to have final size of target

order_target_value([data, target, price])

Place an order to rebalance a position to have final value of target

plotlabel()

prenext()

This method will be called before the minimum period of all datas/indicators have been meet for the strategy to start executing

prenext_open()

preonce(start, end)

It will be called during the "minperiod" phase of a "once" iteration

qbuffer([savemem, replaying])

Enable the memory saving schemes.

reset()

rewind([size])

sell([data, size, price, plimit, exectype, ...])

To create a selll (short) order and send it to the broker

sell_bracket([data, size, price, plimit, ...])

Create a bracket order group (low side - buy order - high side).

set_tradehistory([onoff])

setminperiod(minperiod)

Direct minperiod manipulation.

setsizer(sizer)

Replace the default (fixed stake) sizer

start()

Called right before the backtesting is about to be started.

stop()

Called right before the backtesting is about to be stopped

updateminperiod(minperiod)

Update the minperiod if needed.

Attributes

IndType

ObsType

PriceClose

PriceDateTime

PriceHigh

PriceLow

PriceOpen

PriceOpenInteres

PriceVolume

StratType

alias

aliased

array

csv

frompackages

packages

position

Returns the current position for a given data in a given broker.

positionbyname

Returns the current position for a given name in a given broker.

positions

Returns the current by data positions directly from the broker

positionsbyname

Returns the current by name positions directly from the broker

sizer

Returns the sizer which is in used if automatic statke calculation is used

last_opened_buy

Currently open position

tick

The next() tick counter

__init__(*args, **kwargs)[source]#
last_opened_buy: Optional[BuyOrder]#

Currently open position

tick: Optional[int]#

The next() tick counter

buy(*args, **kwargs)[source]#

Stamps each trade with a timestamp.

Normal Backtrader does not have this functionality.

Return type

BuyOrder

close(*args, **kwargs)[source]#

Counters a long/short position closing it

See the documentation for buy for an explanation of the parameters

Note:

  • size: automatically calculated from the existing position if not provided (default: None) by the caller

Returns: the submitted order

get_timestamp()[source]#

Get the timestamp of the current candle

Return type

Timestamp

lines#

alias of Lines_LineSeries_LineIterator_DataAccessor_StrategyBase_Strategy_DEXStrategy