The idea makes sense and is actually pretty clever. Using a 500-tick reference to estimate TP based on a money amount is a practical approach.
It's a bit strange that it works well for SL but not for TP. That might come from small differences due to rounding, spread, or how OrderCalcProfit calculates profit exactly.
Maybe adding a small final adjustment (like a quick iteration) could help get the TP closer to the expected result.
Hi everyone,
I've read some topics on this function, but I'm really stuck with this situation. I wrote two functions to get the takeprofit price and the stoploss price for a position that is already opened manually.
Takeprofit and Stoploss prices are calculated knowing the details of the opened position (opening price, volume), the desired profit and loss in the account currency and a closed price that is 500 points distant from the opening price of the position.
The problem is that the function for calculating the SL is working perfectly, the function calculating the TP is giving values that are distant from the desired target (the value in account currency).
The calculation is done with the intention to "revert" the OrderCalcSize function: calculating a profit having a certain closing price (in my case I use 500 ticks) and then rescaling this value based on the ratio between desired profit and profit obtained via the OrderCalcProfit function (like suggested from @Fernando Carreiro for calculating the size of a position knowing the risk).
I know that the conversion from the position enum to the order enum in order to make it work with the OrderCalcProfit function is not nice, but in my opinion it makes sense and it was the only idea to get it working.
Let me know if you have suggestions for this problem or any better method to obtain the desiderd TP or SL price based on the desired risk of a position
PS. I'm evaluating the correctness of the calculations after the prices of TP and SL from these two functions are sent and placed on the market as TP and SL for the opened position and I hover with the mouse on the placed TP and SL lines and I see the expected profit and expected loss when the price will trigger those prices
Hi everyone,
I've read some topics on this function, but I'm really stuck with this situation. I wrote two functions to get the takeprofit price and the stoploss price for a position that is already opened manually.
Takeprofit and Stoploss prices are calculated knowing the details of the opened position (opening price, volume), the desired profit and loss in the account currency and a closed price that is 500 points distant from the opening price of the position.
The problem is that the function for calculating the SL is working perfectly, the function calculating the TP is giving values that are distant from the desired target (the value in account currency).
The calculation is done with the intention to "revert" the OrderCalcSize function: calculating a profit having a certain closing price (in my case I use 500 ticks) and then rescaling this value based on the ratio between desired profit and profit obtained via the OrderCalcProfit function (like suggested from @Fernando Carreiro for calculating the size of a position knowing the risk).
I know that the conversion from the position enum to the order enum in order to make it work with the OrderCalcProfit function is not nice, but in my opinion it makes sense and it was the only idea to get it working.
Let me know if you have suggestions for this problem or any better method to obtain the desiderd TP or SL price based on the desired risk of a position
PS. I'm evaluating the correctness of the calculations after the prices of TP and SL from these two functions are sent and placed on the market as TP and SL for the opened position and I hover with the mouse on the placed TP and SL lines and I see the expected profit and expected loss when the price will trigger those prices
Here's the code that I use to convert points to account currency (for swaps). Obviously, you're not calculating swaps but the general principle might be helpful if you edit it and input your TP in points.
swap_long = swap_value_currency(symbol.SwapLong(), symbol.TickValueProfit(), symbol.TickValueLoss()); swap_short = swap_value_currency(symbol.SwapShort(), symbol.TickValueProfit(), symbol.TickValueLoss());
The complete code with the #include and NormailizeDouble() are at:
Swaps Monitor for a Single Symbol
Ryan L Johnson, 2025.05.14 01:27
A simple utility for monitoring long and short swaps of a single symbol. If your broker-dealer's swaps are specified in points instead of account currency, this utility automatically converts points into account currency. Swaps are tripled on Wednesday. Horizontal and vertical alignment can be adjusted in the inputs.The idea makes sense and is actually pretty clever. Using a 500-tick reference to estimate TP based on a money amount is a practical approach.
It's a bit strange that it works well for SL but not for TP. That might come from small differences due to rounding, spread, or how OrderCalcProfit calculates profit exactly.
Maybe adding a small final adjustment (like a quick iteration) could help get the TP closer to the expected result.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone,
I've read some topics on this function, but I'm really stuck with this situation. I wrote two functions to get the takeprofit price and the stoploss price for a position that is already opened manually.
Takeprofit and Stoploss prices are calculated knowing the details of the opened position (opening price, volume), the desired profit and loss in the account currency and a closed price that is 500 points distant from the opening price of the position.
The problem is that the function for calculating the SL is working perfectly, the function calculating the TP is giving values that are distant from the desired target (the value in account currency).
The calculation is done with the intention to "revert" the OrderCalcSize function: calculating a profit having a certain closing price (in my case I use 500 ticks) and then rescaling this value based on the ratio between desired profit and profit obtained via the OrderCalcProfit function (like suggested from @Fernando Carreiro for calculating the size of a position knowing the risk).
I know that the conversion from the position enum to the order enum in order to make it work with the OrderCalcProfit function is not nice, but in my opinion it makes sense and it was the only idea to get it working.
Let me know if you have suggestions for this problem or any better method to obtain the desiderd TP or SL price based on the desired risk of a position
PS. I'm evaluating the correctness of the calculations after the prices of TP and SL from these two functions are sent and placed on the market as TP and SL for the opened position and I hover with the mouse on the placed TP and SL lines and I see the expected profit and expected loss when the price will trigger those prices