거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Facebook에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

Risk Lot Calculator - lot size from risk percent and stop distance - MetaTrader 5용 라이브러리

Lukas Szyry
Lukas Szyry
Gold Trading Specialist | XAUUSD Expert Advisors
MetaTrader 5용 금(XAUUSD) 규칙 기반 Expert Advisor를 개발합니다. 장기적인 계좌 성장을 위한 견고한 시스템에 집중합니다: 마틴게일 없음, 그리드 없음, 손실 시 물타기 없음.
모든 업데이트는 출시 전에 2010년부터 현재까지 XAUUSD 실제 틱 데이터로 아웃오브샘플 기간을 포함하여 테스트됩니다. 기존 사용자에게 업데이트는 항상 무료입니다.
조회수:
416
게시됨:
업데이트됨:
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

I needed this in every EA so here it is as one small include file. It calculates the position size (lot) for a trade from the risk you want to take and the stop loss distance.

You give it entry, stop loss and the risk in % (or a fixed money amount) and it gives you back the lot. It uses tick value and tick size of the symbol, so it works for gold, indices and forex the same way. The lot is always rounded DOWN to the volume step, so the real risk is never higher than what you set. If the lot would be below the minimum lot it returns 0 instead of opening a bigger trade than planned. It also checks the free margin and makes the lot smaller if the margin is not enough.

Demo script output in the Experts journal

Demo script output in the Experts journal

Functions

  • LS_LotByRisk(symbol, type, entry, sl, riskPercent) - lot for x % of the balance
  • LS_LotByMoney(symbol, type, entry, sl, riskMoney) - lot for a fixed money amount
  • LS_NormalizeLot(symbol, lot) - rounds down to the volume step, checks min/max/limit
  • LS_RiskOfLot(symbol, lot, entry, sl) - shows the real money at risk after rounding

Both lot functions have an optional last parameter maxMarginShare (default 0.8 = max 80 % of free margin for this trade).

Usage

#include <LS_RiskLot.mqh>
double lot = LS_LotByRisk(_Symbol, ORDER_TYPE_BUY, entry, sl, 1.0);   // 1 % of balance
if(lot > 0) trade.Buy(lot, _Symbol, entry, sl, tp);

Demo script

The small script LS_RiskLot_Demo shows how to use it: drop it on a chart, set risk and stop in points and it prints the lot and the real risk in the Experts journal. It doesnt open any trade. Inputs: InpRiskPct (risk in % of balance, 0 = use money), InpRiskMoney (risk in account currency), InpStopPts (stop distance in points), InpBuy (buy or sell side).

Small accounts: with 0.01 minimum lot and a wide stop the function can return 0. Thats on purpose, better no trade than 3x the risk.

Fits to it: break-even and trailing stop in R /en/code/79902 and safe pyramiding /en/code/79994

Closed Trades to CSV - one row per closing deal (partial closes, reversals) Closed Trades to CSV - one row per closing deal (partial closes, reversals)

Exports closed trades to a CSV file, one row per closing deal: partial closes, close-by and netting reversals are split, each row with the position's open time, volume-weighted open price and its share of the entry commission.

XAUUSD Hourly Volatility Clock: typical range by hour vs today XAUUSD Hourly Volatility Clock: typical range by hour vs today

A 24-hour clock of typical H1 ranges for XAUUSD (and any other symbol) versus the range of the current hour. The profile uses closed hours only. Display only — it does not trade.

Auto Fibonacci Retracement on the Latest Swing Auto Fibonacci Retracement on the Latest Swing

Detects swing highs and lows automatically and draws Fibonacci retracement levels on the latest completed swing leg. The levels move to the new leg as soon as a new swing is confirmed; the levels, their colors and the swing sensitivity are configurable.

False Breakout Envelope False Breakout Envelope

False breaks at an ATR envelope, drawn as trades: price pushes through a band, closes back inside, and a box runs from the entry to the moving midline, with the stop as a thick line. Each label prints the win rate of earlier signals in the same RSI zone, and a corner card charts it for every zone.