Closed hcandra closed 2 years ago
Hi @hcandra ,
You can see here that the commission fee is calculated based on unit_size
.
Thanks for replying my question. Maybe I would like to clarify using example. Let's say I use EURUSD pair, and I use "right" method because I start with USD 1.00. I understand if we are to start with 1 EUR, then the self.unit_side will be "left".
Based on the code below, for the "right" unit_side, trade will happen in 2 conditions:
Please advise
def _update_profit(self, action): trade = False if ((action == Actions.Buy.value and self._position == Positions.Short) or (action == Actions.Sell.value and self._position == Positions.Long)): trade = True
if trade or self._done:
current_price = self.prices[self._current_tick]
last_trade_price = self.prices[self._last_trade_tick]
if self.unit_side == 'left':
if self._position == Positions.Short:
quantity = self._total_profit * (last_trade_price - self.trade_fee)
self._total_profit = quantity / current_price
elif self.unit_side == 'right':
if self._position == Positions.Long:
quantity = self._total_profit / last_trade_price
self._total_profit = quantity * (current_price - self.trade_fee)
In some aspects, you are right. According to MetaTrader5, the most precise way to calculate profit is using bid/ask prices. Every time you sell/buy something, the bid/ask price is considered, and the fee is applied implicitly.
But I found my profit calculation method to be easier to implement and comprehend. I also tested it on some data and didn't find much of a difference. It is like I chose the bid price as the main price and abs(bid - ask)
as the fee. It is not the most precise way but works.
Anyway, you can calculate profit in the way you explained and analyze the difference.
Hi, I notice in the forexenv, there is a commission applied at the sell leg but not at the buy leg. May I understand the reason?
Thanks in advance for your explanation
Rgds