Loading…

Size From Two Chart Lines

Marking up an entry and a stop on the chart is the easy part; converting that into a correctly sized order is the part that gets rushed or done in the trader's head. This script reads two horizontal line objects already on the chart - one marking the entry, one marking the stop - measures the distance between them using the broker's live tick value and tick size, and prints the exact lot size that risks the chosen amount if price reaches the stop line. No order is sent, modified, or even prepared for sending. This is deliberately a measuring tool, not an execution tool: the trader still places the order themselves, with the lot size this script printed. If either line is missing, the script offers to draw a pair of starter lines twenty pips either side of the current price (when InpCreateLinesIfMissing is left at its default of true) so there is something to drag into position on first use, rather than a script that does nothing until two objects are created by hand. Notes and limitations - Places nothing. The printed lot size still has to be entered manually into an order ticket, or into whatever tool actually sends the trade. - Reads OBJPROP_PRICE1 off each named object, which works for a horizontal line (OBJ_HLINE) as created by this script. Using a different object type for either name may read an unexpected price. - The lot size is rounded down to the broker's lot step and clamped to its minimum/maximum, so the actual risk taken can be slightly less than the target risk (rounding down never risks more than requested). - The margin figure shown alongside the lot size is a separate concern from risk - it is what the broker would require to open the position, not what would be lost if the stop is hit. The two numbers are printed together for convenience only. - Does not check that the entry line sits on the correct side of the current market price for a realistic order (e.g. a buy stop above the market) - it only measures the distance between the two lines.

Script · MT5 · v1.0 · Free

About Size From Two Chart Lines

Size From Two Chart Lines is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as Entry line name, Stop line name and Use risk percent. MQL source code included.

Files in the download: SizeFromChartLines.ex5, SizeFromChartLines.mq5, SizeFromChartLines.txt.

Settings

SettingDefaultWhat it does
Entry line nameSFC_EntryName of the horizontal line marking the entry price
Stop line nameSFC_StopName of the horizontal line marking the stop price
Use risk percenttruetrue = risk a percent of balance, false = risk a fixed money amount
Risk percent1.0Percent of account balance to risk (used when InpUseRiskPercent = true)
Risk money100.0Fixed money amount to risk (used when InpUseRiskPercent = false)
Create lines if missingtrueDraw starter lines above/below current price if either name is not found

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Risk & Lot Size · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria