Guarda come scaricare robot di trading gratuitamente
Ci trovi su Facebook!
Unisciti alla nostra fan page
Script interessante?
Pubblica il link!
lasciare che altri lo valutino
Ti è piaciuto lo script? Provalo nel Terminale MetaTrader 5
Script

Correlation-Aware Lot Size Calculator - script per MetaTrader 5

ali rajput
Pubblicati da::
Rana Ali
Rana Ali
  • MQL5 Developer & Algorithmic Trading Specialist al  Freelance
  • Pakistan
  • 183
Hi, I'm Ali. 24 years old, trading for around 5 years, and developing MQL5/MQL4 tools. I mainly work on automating manual strategies, fixing broken EA logic, and building clean indicators. I care more about clean architecture and proper risk management than over-complicated code. Always down to talk
Visualizzazioni:
94
Valutazioni:
(2)
Pubblicato:
Freelance MQL5 Hai bisogno di un robot o indicatore basato su questo codice? Ordinalo su Freelance Vai a Freelance

Correlation-Aware Lot Size Calculator

I got tired of position size calculators that only look at the trade you're about to open and ignore everything else sitting on your account. If you're already long EURUSD and you open GBPUSD too, most calculators will happily size that second trade using your full risk % again — even though the two pairs move together most of the time and you've basically doubled your bet on the dollar without realizing it.


This script tries to fix that. Before you open a new trade, it:

- Works out the normal risk-based lot size from your balance, risk %, and stop loss in points
- Goes through every position you currently have open, on any symbol
- Calculates the actual correlation between each of those symbols and the one you're about to trade, using real recent price history (not a fixed correlation table that's already outdated by the time someone publishes it)
- Checks direction too — same-direction trades on correlated pairs stack risk, opposite-direction trades on correlated pairs usually offset each other
- Adds up how much risk is already sitting in correlated positions, and shrinks your new lot size if you're close to (or past) a basket risk limit you set yourself

Everything gets printed to the Experts/Journal tab — which positions got flagged, why, and what lot size it recommends instead of your "normal" one.

A few things worth knowing before you use it:

- If a correlated position has no stop loss set, the script can't know its real dollar risk, so it warns you instead of guessing
- Correlation is calculated from the last N bars (you pick the timeframe and how many), so it reflects current market behavior — but it's still a backward-looking number and can shift over time
- This is read-only. It doesn't open, modify, or close anything on your account

Inputs:
- InpTargetSymbol — symbol you're about to trade (leave blank to use the current chart)
- InpNewTradeIsBuy — direction of the new trade
- InpRiskPercent — risk % for the new trade
- InpStopLossPoints — stop loss distance in points
- InpMaxBasketRiskPercent — max combined risk you're willing to carry across correlated positions
- InpCorrelationThreshold — how strong a correlation needs to be before it counts
- InpCorrelationBars / InpCorrelationTimeframe — controls how correlation is measured

I built this after catching myself stacking correlated pairs a few too many times without noticing until the drawdown showed up. If you only ever trade one pair at a time it won't do much for you — but if you run multiple positions across majors/minors together, it should catch things a plain lot calculator won't.

Free to use, modify, and adapt.
Prop Firm Rule Checker Prop Firm Rule Checker

Checks your trade history against common prop-firm challenge rules — profit target, max daily loss, max drawdown, consistency rule, and minimum trading days — with a clear PASS/FAIL report.

GDS Renko Donchian Demo EA GDS Renko Donchian Demo EA

A small educational Expert Advisor showing how a classic Donchian breakout can be applied directly to completed Renko bricks.

Risk-Based Lot Size Calculator Risk-Based Lot Size Calculator

A simple MQL5 script that calculates the correct lot size for a trade based on your account risk percentage and stop loss distance in pips, so every trade risks a consistent, controlled amount of your balance.

Server Time Offset: the three clocks in MQL5 and how timestamps shift on export Server Time Offset: the three clocks in MQL5 and how timestamps shift on export

A datetime in MQL5 is seconds since 1970 - but server time (TimeCurrent, bar times, deal times) is the broker's wall clock stored AS IF it were UTC. Export it to CSV, read it in Python or a spreadsheet with a "seconds since 1970 UTC" parser, and every timestamp shifts by the server's UTC offset. On a UTC-3 broker that is three hours: the daily bar dated 00:00 reads as 21:00 of the previous day, and "yesterday's session" silently becomes "today's, half formed". That happened to a morning report of mine before this script existed. The script prints TimeTradeServer, TimeCurrent, TimeGMT and TimeLocal, the three offsets between them, the tick lag, and this chart's last bar time in server time and in real UTC - then states the rule: export server timestamps as wall-clock text, or export the epoch together with the offset, and never let the consumer apply its own timezone.