Code Library / Martingale

Pine Script Martingale Backtest

Backtest martingale position sizing on TradingView.

Language: Pine Script · Category: Martingale · Tags: martingale, backtest, Pine Script, position sizing, risk

Source code

//@version=5
strategy("Martingale Backtest",overlay=false)
var float lot=1, var int lvl=0
if ta.crossover(ta.rsi(close,14),30)
    strategy.entry("M",strategy.long,qty=lot)
plot(lot,"Lot",color.orange)
plot(lvl,"Level",color.red)

How to use this snippet

This is a building block, not a finished trading system. Paste it into your own Pine Script project, compile it, and test it on a demo account with your broker's real spreads before relying on it. You can convert it to MQL4 or MQL5 with the Pine Script converter.

Related snippets