Urgent.News

What's breaking now, across thousands of outlets.

Tech

Moving a stop to breakeven in MQL5 without rejected modifies or hidden losses

Moving the stop loss to breakeven once a trade is in profit is one of the most requested Expert Advisor features. It also produces a surprising number of bug reports: the stop never moves, the journal fills with errors, or the trade closes "at breakeven" and still shows a small loss. This tutorial builds a breakeven routine that measures profit from the right price, respects the broker's distance…

Adjusting the stop loss to breakeven once a trade becomes profitable is a popular request for Expert Advisors. However, this simple feature often leads to numerous bug reports, with the stop loss not moving, journal entries filled with errors, or the trade closing at breakeven while still showing a small loss. This tutorial presents a comprehensive breakeven routine that accurately measures profit from the correct price, takes into account the broker's distance rules, ensures the stop is only tightened, and factors in trading costs.

When calculating profit, it's essential to use the appropriate price for closing the position. For a buy position, the closing price should be the bid, while for a sell position, it should be the ask. Failing to measure profit from the correct price will result in the spread being counted as profit and the stop moving too early. This can be particularly problematic on symbols with wide spreads, as it may cause the stop to be moved before the trade is truly in profit.

Breakeven is not the same as the entry price. If the stop is placed exactly at the open price, a trade that returns and hits the stop will still incur commission and any accumulated swap, resulting in a loss. Therefore, breakeven should typically be set at the entry price plus a small positive offset to account for commission and potential slippage. For a buy, this offset is added above the entry price, while for a sell, it is subtracted below the entry price.

On netting accounts, another consideration arises. When adding to an existing position, the POSITION_PRICE_OPEN becomes the volume-weighted average price of the entire position. Consequently, the breakeven level should move accordingly with each addition. While this is often the desired behavior, it's essential to test this functionality to ensure it works as expected.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

curiousBuddy: Stop Re-Reading. Start Explaining. 🎙️🧠

An AI-powered study companion that turns passive learning into focused sessions, real conversations, and active recall. This is my submission for the Hacktoberfest Open-Source AI Challenge — Week 3…

  • curiousBuddy transforms passive learning into active recall sessions.
  • Conversational AI Cube challenges users with questions and analogies.
  • Study notes and quizzes reinforce understanding and track progress.

Decompiling Fast Food Tycoon 2

  • Author decompiled Fast Food Tycoon 2 in days using GPT-6.1 Sol Medium
  • Identified memory addresses for cash, camera, buildings via ReadProcessMemory API
  • Renderer combines pixel colors with lighting values for isometric game display

More from Sunday 25 October →