bt.And exists because
and cannot be overloaded. But you can pass any number of arguments to
bt.And or nest them.
I want to buy a position and sell it after 2 days
Notice that using anything which is
datetime related won't usually work unless you don't mind weekends and trading holidays adding days to the count.
Without really understanding what you mean with "rates", it seems the value of your asset moves around
1.14-1.15 with a very small variation.
The variation is so small that
matplotlib changes the representation to accommodate such a small variation, indicating the reference value at the top with
You will have to dig in the
matplotlib documentation to understand how this may be changed.
x = bt.If(d(-3) > e(-2) > f(-1), d(-1), float('Inf')) # new error here
The magic of "overloading" cannot handle the chained comparison:
d(-3) > e(-2) > f(-1). Hence
condition = bt.And(d(-3) > e(-2), e(-2) > f(-1)) bt.If(condition, result_if_True, result_if_False)
From my point of view,
Interesting point of view. Go to any exchange, send a
Market order and try to cancel it.
Come then back and let us know how things worked out.
why not cancel on present bar in backtesting?
Because "present" in "present bar" is a fallacy. That bar is already the PAST, because if you see that it has ALREADY happened.
If you go to the market thinking in terms of bars your money will be gone very soon. The market is made of TICKS which is a single price point representing an execution (in FOREX not even that, as most data providers provide the
Bid price even if no execution has happened).
Market order may actually be the one that generates the next tick.
Using bars is simply a representation of the market.
StopTrail order as sent to the broker is also immediately executed because it will be immediately triggered with the given parameters.
TradeAnalyzerwhich already includes this calculation - https://www.backtrader.com/docu/analyzers-reference/#tradeanalyzer
Cerebro returns the strategy instances that have run.
The definition of what's returned is in the
Cerebro reference: https://www.backtrader.com/docu/cerebro/, section Returning the Results
You may pass a dataframe and later get it from the executed strategy.
import backtrader.indicator as btind
Notice that the original problem is the lack on an
s. The code is importing
backtrader.indicator and not
MovAv.Simple and all other aliases aforementioned, do exist.