Dear Muhammad,
I stumbled upon your code, it is really nice. Thank you so much.
I have some corrections for the math calculations in your code:
1. avoid negative int inputs.
//input int MinimumProfit = 0; // Minimum current profit in points to apply BE //input int AdditionalProfit = 0; // Additional profit in points to add to BE input uint MinimumProfit = 0; // Minimum current profit in points to apply BE input uint AdditionalProfit = 0; // Additional profit in points to add to BE
2. the right way to compare doubles.
// Compare doubles by calculating difference. If this difference is greater than Point / 2, the position's profit is below the MinimumProfit parameter. //if ((MinimumProfit > 0) && ((double)MinimumProfit - MathAbs(PositionGetDouble(POSITION_PRICE_OPEN) - PositionGetDouble(POSITION_PRICE_CURRENT)) / point > point / 2)) continue; if ((MinimumProfit > 0) && ((double)MinimumProfit * point >= MathAbs(PositionGetDouble(POSITION_PRICE_OPEN) - PositionGetDouble(POSITION_PRICE_CURRENT)) + point / 2) continue;
3. rounding should not be done at the intermediate calculations not to lose precision.
//if (tick_size > 0) //{ // // Adjust for tick size granularity. // extra_be_distance = NormalizeDouble(MathRound(extra_be_distance / tick_size) * tick_size, digits); //}
4. rounding should only be done in the final step of calculations to chop fp roundoff errors.
if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) { double BE_price = NormalizeDouble(PositionGetDouble(POSITION_PRICE_OPEN) + extra_be_distance, digits); if (tick_size > 0) { // Adjust for tick size granularity. BE_price = MathRound(BE_price / tick_size) * tick_size; } ... ... else if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) { double BE_price = NormalizeDouble(PositionGetDouble(POSITION_PRICE_OPEN) - extra_be_distance, digits); if (tick_size > 0) { // Adjust for tick size granularity. BE_price = MathRound(BE_price / tick_size) * tick_size; } ... ...
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Titik Impas Breakeven:
While manually adjusting the stop-loss of a single trade to match its open price is a relatively simple task, managing numerous positions individually can be cumbersome and time-intensive. The Titik Impas Breakeven script for MT4/MT5 streamlines this process, providing efficiency and convenience for traders dealing with multiple positions.
Author: Muhammad Sholihuddin Rozio