1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.
Source Code
12 lines of Pine Script v6 from benches/test_data/strategy_trades.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.
strategy_trades.pine
//@version=6
strategy("strategy_trades", initial_capital = 1000000, default_qty_type = strategy.fixed, default_qty_value = 1)
// Closes a trade every other bar, so the closed-trade log grows with the run,
// while reading account figures every bar. The per-bar cost must not grow with
// the number of trades closed so far.
if bar_index % 2 == 0
strategy.entry("L", strategy.long)
else
strategy.close("L")
plot(strategy.netprofit + strategy.grossprofit + strategy.avg_trade_percent + strategy.max_drawdown)
Overview
Strategy Trades initiates a fixed-size long position on every even bar index and closes the position on the subsequent odd bar. In a separate indicator pane, it plots a composite sum of strategy net profit, gross profit, average trade percentage, and maximum drawdown. The strategy includes no technical indicators, input parameters, or stop loss safeguards, functioning purely as an engine performance benchmark.
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
HA UnivLong&Short Futures calculates Heikin Ashi candles and builds a channel using simple moving averages of Heikin Ashi highs and lows. It enters long positions when the upper channel line crosses above the lower channel line and opens short positions on the
This strategy combines the ATR-banded Q-Trend indicator with the Klinger Volume Oscillator (KVO) to execute confluence trades. It enters long when a Q-Trend buy trigger aligns with a positive KVO value and a bullish candle confirmation, taking short trades und
This strategy calculates the Moving Average Convergence Divergence indicator and plots the MACD line, signal line, and histogram in a separate pane. It enters long positions when the MACD line crosses above the signal line and enters short positions when it cr
This strategy estimates price behavior using ordinary least squares regression between higher-timeframe data and a generated dataset, smoothed by a Karobein oscillator. It enters long positions when the oscillator turns upward and short positions when it turns
10PreBuyer is a dip-buying strategy that submits limit orders below recent price action using a discounted Hull Moving Average (HMA). It calculates the highest HMA value of high prices over a selected period, multiplied by a percentage discount factor, and pla
This Pine Script strategy demonstrates the usage of bar state variables by highlighting the chart background color. It evaluates whether the current candle is the final bar on the chart using the barstate.islast condition and applies a silver background color