Adjusting TP to Include Commission in a Manual Trading Bot
-
Hello, good day.
I have a manual trading bot in FXDreema that executes market trades or pending orders when a button is clicked.
I want the bot to calculate the commission before opening a trade and add it to the take profit (TP) so that the net reward is exactly my target.For example, if I want to exit at 1R reward, the bot should first calculate the commission and then adjust the TP so that after deducting the commission, the net reward remains 1R (e.g., the final TP might be 1.3R if the commission is 0.3R).
Additionally, I use "Risk fixed amount of money" for risk management.
The stop loss for Sell trades is set at the high of candle ID 1 + spread,
and for Buy trades, it is set at the low of candle ID 1. -
If the commission is fixed value you can add it directly to your formula, but I guess it is dynamic, right?
-
Yes, because I want to use this bot on different brokers, the commission is different.
But if the commission is a fixed amount, how should I code it?
-
The problem is as you said brokers, and assets have different values. FX can only get this from running trades/orders, I put this together that places an order retrieves the value then deletes the order, not ideal but should work. On backtest it didn't work, test it on a live account and see what it does, it should update if the chart symbol is changed: https://fxdreema.com/shared/RAgL4J6Pb
-
Hello @jstap,
I reviewed the code you sent, but unfortunately, it didn't work properly. I even tried writing the code as a market buy order, but the issue still wasn't resolved.
I decided to add an input (constant) for the commission to the bot and set it to something like $7 per lot. Under these circumstances, please guide me on what changes I need to make in the code.
I intend for the commission to be applied in two different sections:1️⃣ In the input lot size: Since my risk management is based on a fixed dollar risk per trade, I want the commission to be included in the total account risk calculation. For example, if I set the risk to $30, this amount should include the commission as well. This means that if the stop loss is hit, the total loss, including the commission, should be $30.
2️⃣ In the risk-to-reward ratio: I also want the commission to be considered when calculating the take profit. For example, if the risk-to-reward ratio is 1:1, I want the final reward to be calculated as 1 plus the commission amount.
Ultimately, my goal is that if I am risking $30, in case the stop loss is hit, the net loss should be $30, and in case the take profit is hit, the net profit should also be $30.
I will send the link to the bot I have written. I would appreciate it if you could review the code and guide me on how to implement these changes.
-
You can't add candle price to spread (level - fraction (distance)). You can try candle price + 0 (in adjust put, SymbolInfoInteger(NULL, SYMBOL_SPREAD)
Let me know if it works
-
I didn't understand what you meant.
If possible, please write the code so I can check it and let you know whether it works or not. -
Addt to a project and place a shared link to look at, Ill see what's right/wrong from there