Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Scripts

SetSLByLoss — set Stop Loss on all open positions by target loss amount - script for MetaTrader 5

Views:
251
Rating:
(1)
Published:
SetSLByLoss.mq5 (8.46 KB) view
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

Script that sets a Stop Loss on every open position based on a target loss amount expressed in the account's currency (e.g. $50 per position). Works for any deposit currency (USD, AUD, EUR, NZD, etc.) and any forex symbol - currency conversion is handled automatically via SYMBOL_TRADE_TICK_VALUE_LOSS. Validates broker stops/freeze levels before submitting changes, skips positions whose SL is already correct, and reports clear reasons for any positions that cannot be modified. The target loss is set in an input parameter: Maximum loss (amount in account currency) for each position.




LOGIC


  • For each open position, calculates the SL price such that if hit, the loss equals approximately InpTargetLossAmount (in the account's currency). 

  • Validates against stops level and freeze level before submitting modifications.

  • Skips positions that already have a correct SL (within 1 tick of the target).

  • Skips positions whose price has moved so far that placing the SL would violate broker constraints, logging the reason. 


TickValue_Compare — diagnose differences between TICK_VALUE, LOSS and PROFIT TickValue_Compare — diagnose differences between TICK_VALUE, LOSS and PROFIT

Diagnostic script that compares SYMBOL_TRADE_TICK_VALUE, SYMBOL_TRADE_TICK_VALUE_LOSS and SYMBOL_TRADE_TICK_VALUE_PROFIT for every symbol in Market Watch. Classifies each symbol into one of four categories (ALL_EQUAL, TV_MATCHES_PROFIT, TV_MATCHES_LOSS, ALL_DIFFER) and provides an aggregated summary plus interpretation tip. Useful for verifying which tick-value property to rely on when implementing risk-based lot sizing in EAs. Exports full per-symbol report to CSV in MQL5/Files.

Heiken ashi as series Heiken ashi as series

Heiken ashi with all buffers set as series

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.