Join our fan page
- Views:
- 65
- Published:
-
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance
ATR Trailing Stop (Pine Script port)
A worked example of converting a TradingView Pine Script indicator to MQL5, kept in parity with a Python reference implementation.
Rules (same in all three versions):
- nLoss = ATR multiplier x SMA of true range over InpATRLength bars
- The stop ratchets up under price while price stays above it, and down over price while price stays below it
- The stop flips to the other side, and an arrow is drawn, when price closes through it
Pine to MQL5/Python translation notes (the actual porting work):
- ta.tr(true): the first bar has no previous close, so true range there is just high minus low
- ta.sma(x, n): stays na until n bars exist (first valid value at bar n-1)
- nz(stop[1], src): the previous stop, or the current price while the previous stop is still na
- var float stop = na: state carried from bar to bar, translated to a persistent buffer in MQL5 and a running array in Python
- ta.crossover / ta.crossunder: strictly false while either side is na, which matters for the first valid bar
Repository (Pine source, Python port with a literal bar-by-bar reference implementation for cross-checking, and a parity test comparing both to the MQL5 output): github.com/RAo797bit/pine-python-mql5-conversion
Compiles clean in MetaEditor with 0 errors, 0 warnings
.
EMA Cross Demo EA with ATR Stops
A small demo Expert Advisor: EMA fast/slow cross entries (evaluated on closed bars only, no repainting), ATR-based stop-loss and take-profit, spread filter, and position handling that works on both hedging and netting accounts. Includes a Python reference implementation for parity testing. This is a deliverable example, not a trading recommendation - the attached equity curve is from synthetic data and shows the method, not an edge.
Session TWAP: time weighted average price from the cash open, with deviation bands
Time weighted average price of the running session, anchored at the cash open of Frankfurt, London, New York or Tokyo with automatic daylight saving. Every second counts the same, minutes without a tick carry the last price, and two bands show the time weighted standard deviation around the line.
Trade Reporter Lite - Telegram trade notifications
Posts your MT5 opens and closes to a Telegram chat: side, symbol, entry, stop and target in pips, lots, and on close the result, pips, R-multiple and time held. Retry queue, restart-safe, never trades. Free version of Trade Reporter Telegram and Discord.
MACD Signals
Indicator edition for new platform.