Skip to content

bugswritter/Risk_Calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Pre-Trade Risk Calculator (MT5 Expert Advisor)

A MetaTrader 5 Expert Advisor that shows a chart panel to plan entries, stop loss, and take profit with position sizing, then confirm to send the order. It does not manage open trades; it is only for pre-trade planning and one-shot execution.

Version: 2.01 (see #property in the source file)

Requirements

  • MetaTrader 5
  • Algo Trading enabled in the terminal toolbar
  • On the EA’s Common tab: Allow Algo Trading checked
  • Account must allow automated trading (not investor/read-only if your broker blocks EAs)

Installation

  1. Copy this folder (or place RiskCalculator.mq5) under your terminal’s MQL5 Experts tree, for example:
    • .../MQL5/Experts/risk_calculator/RiskCalculator.mq5
  2. Open RiskCalculator.mq5 in MetaEditor and compile (F7). That produces RiskCalculator.ex5 next to the source (this repo’s .gitignore excludes *.ex5). Fix any errors if your build environment differs.
  3. In MT5, open Navigator → Expert Advisors, drag the EA onto the chart of the symbol you want to trade.
  4. Adjust Inputs if needed (see below), then OK.

What you see on the chart

  • Entry line — Horizontal line at the current ask when the EA starts; drag it to your desired entry.
  • Optional SL / TP lines — Toggle with SL and TP on the panel. When first enabled, SL is placed about 50 pips and TP about 100 pips from entry (in the correct direction for buy/sell); you can drag them anywhere.
  • Panel — Live readouts: order type, risk % or lot size, distances, risk/reward in money, R:R when both SL and TP are on, and required margin. Use to collapse the panel; click the collapsed bar to expand again.

Inputs (EA properties)

Input Meaning
Magic number Identifies orders (comment is also set to RiskCalc).
Default Risk % Starting risk percent when Risk % mode is on.
Manual Lot Size Starting lot size when Risk % mode is off.
Entry / SL / TP colors Colors of the horizontal lines.
Line Width Thicker lines are easier to grab on the chart.
Panel Background Panel fill color.
Panel X / Y Top-left position of the panel in pixels.

Using the panel

  1. BUY / SELL — Sets direction. Flipping direction moves default SL/TP to the correct side of entry when those lines exist.
  2. RISK % ON / OFF
    • ON: Lot size is calculated so that if price hits SL, loss is about Risk % of account balance. SL must be enabled and placed; turning Risk % on will turn SL on if it was off.
    • OFF: You type manual lot size; the panel shows the implied risk % when SL is on.
  3. SL / TP — Turn each line on or off. Turning SL off while in Risk % mode switches Risk % off (risk sizing needs a stop).
  4. Edit Risk % or Lots in the boxes; press Enter or click outside to apply. Values are clamped to sensible ranges (e.g. risk 0.1–100%).
  5. Order type — If the entry line is near current ask/bid (within about 3× spread), the EA treats it as Market Buy/Sell. Otherwise it uses Buy/Sell Stop or Buy/Sell Limit depending on whether entry is above or below the market (standard pending logic).
  6. CONFIRM ORDER — Sends one order at the computed type, price, volume, SL, and TP. The button text turns red and explains issues (e.g. no lots, lot limits, insufficient margin).

Trading checklist

  • Toolbar: Algo Trading (green) on.
  • EA: Allow Algo Trading in properties.
  • Server/account: automated trading allowed (no investor-only restriction unless your broker allows EAs).
  • Sufficient free margin for the shown Margin Req.

If something fails, check the Experts log and any Alert popups from the EA.

Files in this repository

  • RiskCalculator.mq5 — Main EA source (#property copyright / version are set in the file; compile this in MetaEditor to build the expert).
  • README.md — This guide.

Disclaimer

This software is provided as-is for planning and execution assistance. Trading carries risk; past or simulated behavior does not guarantee future results. You are responsible for compliance with your broker’s rules and for testing on a demo account first.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages