happydasch / btoandav20

Support for Oanda-V20 API in backtrader
Apache License 2.0
130 stars 52 forks source link

The sizers don't work as my expection #66

Closed eldisa closed 3 years ago

eldisa commented 3 years ago

Greetings,

I have a problem about the OandaV20 sizers.

In my expection, the sizer returns a fixed number after calculating the given params, but it double the size of position when order over two times.

For example with code In the L21-L23 from btoandav20/btoandav20/sizers/oandav20sizer.py

position = self.broker.getposition(data)
if position:
    return position.size

Assume using OandaV20CashSizer with default params: amount=50

no. of order getposition(data) size return
1 0 50
2 50 50
3 100 100
4 200 200
5 400 400
...

In the first order, the sizer calculating the size, because if position is false. And the 2nd oder, the size return the current position size, because if position is true.

However, the size of next orders will accumalte instead of amount=50

happydasch commented 3 years ago

yes, that is expected behaviour. if you have a position open, the sizer will return the open size else it will return the cash amount. just write a different sizer if you need that functionality. they are really simple to code.