@jimmyliu Have you found any other solution to your problem? I am facing the same issue here.
Latest posts made by BernardLin
-
RE: FX trading base currency problem
-
RE: How do I set up correct position close logic?
@backtrader
Hi, would you mind providing me a link on how 'define a CommissionInfo object which converts the profit and loss (and commissions) of the given pair to your base currency' is done? I searched throughout the community but haven't found the relating thread on this. Thanks a lot! -
RE: How do I set up correct position close logic?
@backtrader
Thanks, I will look it up.
A new question just hit me, to further build up on this question. It seems that your reply implies that backtrader assumes that assets are denominated in USD. What if I am trading forex pairs? I guess it works the same way for currency pairs like EURUSD as the price is denominated also in USD. But what if I am trading USDCHF, USDJPY or USDCHN? These pairs are denominated in other currencies other than USD, yet my base currency is USD and I would like my backtrader to reflect that. This seems to pose an issue, do you have any suggestions how I can solve this? Much gratitude for your help! -
RE: Forex trading leverage settings in backtrader
Ah, many thanks! I will look again at the difference between the terms in depth!
A new question just hit me, to further build up on this question. It seems that your reply implies that backtrader takes the asset class by default as shares or futures which are denominated in USD. What if I am trading forex pairs? I guess it works the same way for currency pairs like EURUSD as the price is denominated also in USD. But what if I am trading USDCHF, USDJPY or USDCHN? These pairs are denominated in other currencies other than USD, yet my base currency is still USD. This seems to pose an issue, do you have any suggestions how I can solve this? Much gratitude for your help!
-
RE: How do I set up correct position close logic?
@backtrader Okay, but I am now only backtesting my trading strategy with the historical OHLC prices of some forex currency pairs, since it was only historical rates in imported csv files, how does backtrader distinguish the asset class? Or could there be a way to set up counter positions of forex currency paris as on many forex trading platforms such as MT4 and Oanda? Thanks for any advice!
-
RE: How do I set up correct position close logic?
@backtrader Hi, thanks so much for the clarification, so it means that we cannot hedge against a position on the same asset in Backtrader, right? Is it possible to add this feature in the future?
-
RE: TradeAnalyzer appears to be incorrect
@backtrader Hi, I changed traderanalyzer.py file script as instructed on Github and that is when it went wrong, then I downloaded a traderanalyzer.py directly from Github, reinstalled Backtrader and copied and pasted the traderanalyzer.py into the backtrader module, it is working now. Though I couldn't figure out the reason for that error to occur.
By the way, would you mind taking a look at this question https://community.backtrader.com/topic/1303/how-do-i-set-up-correct-position-close-logic/4 ?
I have been scratching my heads over how to use self.close() order to close only long or short positions when I have both existing long and short positions. It is a very important question for me, and many thanks if you can clarify it for me cos I didn't find a page on the website explaining how it works.Have a good weekend.
-
Forex trading leverage settings in backtrader
Hi, @backtrader @ab_trader , I am trying to backtest a forex trading strategy on backtrader, I read the Docs and it seems that the go-to method is cerebro.broker.setcommission(). I would like to trade forex with a 200 leverage, however, when I set cerebro.broker.setcommission(leverage=200) or cerebro.broker.setcommission(margin=0.05). there was no change to my backtest results. The only notable change happened when I set cerebro.broker.setcommission(mult=200), but @ab_trader you specified in https://community.backtrader.com/topic/729/difference-between-leverage-and-multi/2 that mult is usually not 1/margin, so how should I set it up?
Ialso see in https://www.backtrader.com/docu/user-defined-commissions/commission-schemes-subclassing.html that "margin=2000 # Margin is needed for futures-like instruments", does that mean I don't need to designate a margin for forex? So it is only "mult" then? -
RE: TradeAnalyzer appears to be incorrect
Hi @advandenoord @backtrader
I have updated the traderanalyzer.py as in branch: https://github.com/backtrader/backtrader/commit/cc2751a5f53166f68c5340eb876579f1a5590bf5
but now when I run my backtrader, Python returns this:File "D:\Anaconda3\lib\site-packages\backtrader\analyzers\tradeanalyzer.py", line 73, in stop super(TradeAnalyzer, self).stop() TypeError: super(type, obj): obj must be an instance or subtype of type
Do you guys know why this happens? How should I fix it? Thanks!
-
RE: How do I set up correct position close logic?
@ab_trader So it is self.close(), not self.buy(exectype=bt.Order.Close) right? But what if I have both existing long and short positions, I wanna close only the long position under one circumstance and short under another, how do I ask Backtrader to distinguish between them?
For example, if I wanna close a long position, and specify in the command that close only a long position, should I use
self.buy(exectype=bt.Order.Close)
or
self.sell(exectype=bt.Order.Close)
or
self.close() ??? (but this one seems to close all existing long and short positions, can I specify, for example, asking it to close only long positions, leaving short positions alone for me?)
Thanks!