Strategy · Pine Script v6 · On the chart

TradersPost Trade Replay

by TradersPost

This strategy replays trades exported from TradersPost on the price chart by executing entries and exits at exact timestamps and prices from trade history.

View on GitHub

Repaints

GitHub stars218on the repository
Pine versionv6current
Lines of code115
Settings0inputs
LicenceNone statedfile: MPL-2.0
Last update3 months ago23 Jul 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 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

115 lines of Pine Script v6 from projects/traderspost-replay.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

traderspost-replay.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TradersPost

//@version=6
strategy("TradersPost Trade Replay", overlay=true, default_qty_type=strategy.fixed, default_qty_value=1, initial_capital=10000, commission_type=strategy.commission.cash_per_contract, commission_value=0.62, slippage=0, calc_on_every_tick=true, use_bar_magnifier=true, margin_long=0, margin_short=0)

// ══════════════════════════════════════════════════════════════════════════════
// DESCRIPTION
// Replays trades exported from TradersPost by executing at the exact times
// and prices from your trade history.
//
// USAGE:
// 1. Export trades from TradersPost (CSV format)
// 2. Run: python tools/traderspost-to-pine.py your_export.csv
// 3. Copy the generated array code and paste below (TRADE DATA section)
// 4. Apply to chart on appropriate timeframe
//
// The script will execute entries and exits at the exact signal prices.
// ══════════════════════════════════════════════════════════════════════════════

// ═══════════════════════════════════════════════════════════════════════════════
// USER-DEFINED TYPES
// ═══════════════════════════════════════════════════════════════════════════════

type TradeSignal
    int     tradeTime   // Unix timestamp in milliseconds
    int     direction   // 1 = long entry, -1 = short entry, 0 = exit
    float   price       // Signal price
    int     qty         // Quantity

// ═══════════════════════════════════════════════════════════════════════════════
// PERSISTENT STATE
// ═══════════════════════════════════════════════════════════════════════════════

var array<TradeSignal> trades = array.new<TradeSignal>()
var map<int, bool> executedTrades = map.new<int, bool>()

// ═══════════════════════════════════════════════════════════════════════════════
// TRADE DATA - Generated from TradersPost export
// To update: python tools/traderspost-to-pine.py your_export.csv
// ═══════════════════════════════════════════════════════════════════════════════

var array<int> tradeTimes = array.from(1763993700000, 1763994601000, 1764167400000, 1764174065000, 1764680400000, 1764686249000, 1764837900000, 1764858660000, 1765435500000, 1765446797000, 1765471500000, 1765475835000, 1765813500000, 1765816404000, 1765880102000, 1765882548000, 1766067300000, 1766072094000, 1766133900000, 1766149390000, 1766394900000, 1766414001000, 1766416500000, 1766438100000, 1766575800000, 1766599126000, 1766600160000, 1766704500000, 1766780100000, 1766783700000, 1766970900000, 1766997563000, 1766999700000, 1767016257000, 1767022200000, 1767042900000, 1767075300000, 1767129300000, 1767166200000, 1767191803000, 1767200400000, 1767211683000, 1767214800000, 1767215700000, 1767366900000, 1767367801000, 1767369600000, 1767376985000, 1767381300000, 1767388500000, 1767714300000, 1767716564000, 1767796200000, 1767798026000, 1767804300000, 1767808222000, 1767811500000, 1767816850000, 1767833100000, 1767852067000, 1767854700000, 1767882677000, 1767938400000, 1767965400000, 1768386148000, 1768417200000, 1768423211000, 1768890523000, 1768967100000, 1768996154000, 1769004000000, 1769004905000, 1769023800000, 1769024700000, 1769095800000, 1769097005000, 1769098500000, 1769104981000)
var array<int> tradeDirections = array.from(1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0)
var array<float> tradePrices = array.from(24570.00, 24516.00, 25222.00, 25321.50, 25498.75, 25601.50, 25639.25, 25664.00, 25509.75, 25611.50, 25565.25, 25590.00, 25176.75, 25201.75, 25212.00, 25236.75, 25260.25, 25360.00, 25374.25, 25274.00, 25703.75, 25738.50, 25677.75, 25700.50, 25792.00, 25892.25, 25861.75, 25892.75, 25873.00, 25868.75, 25875.25, 25752.75, 25760.50, 25660.50, 25745.00, 25737.25, 25733.25, 25686.50, 25600.00, 25635.00, 25605.25, 25504.50, 25455.00, 25458.50, 25604.00, 25489.75, 25375.00, 25340.00, 25386.25, 25396.50, 25723.50, 25688.75, 25790.75, 25825.00, 25942.25, 25977.00, 25969.50, 25869.00, 25833.50, 25733.50, 25699.50, 25733.75, 25693.25, 25715.75, 25778.75, 25515.00, 25634.50, 25299.50, 25203.75, 25079.00, 25085.00, 25203.50, 25429.75, 25560.25, 25592.50, 25627.00, 25653.75, 25688.00)
var array<int> tradeQtys = array.from(2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)

// ═══════════════════════════════════════════════════════════════════════════════
// INTRABAR DATA - Request 1-minute data to check if exit price was crossed
// ═══════════════════════════════════════════════════════════════════════════════

array<float> lowerTfHighs = request.security_lower_tf(syminfo.tickerid, "1", high)
array<float> lowerTfLows = request.security_lower_tf(syminfo.tickerid, "1", low)

// Function to check if price was crossed within the bar using 1-minute data
priceCrossedInBar(float targetPrice) =>
    bool crossed = false
    if array.size(lowerTfHighs) > 0 and array.size(lowerTfLows) > 0
        for j = 0 to array.size(lowerTfHighs) - 1
            float barHigh = array.get(lowerTfHighs, j)
            float barLow = array.get(lowerTfLows, j)
            if barLow <= targetPrice and targetPrice <= barHigh
                crossed := true
                break
    crossed

// ═══════════════════════════════════════════════════════════════════════════════
// MAIN LOGIC
// ═══════════════════════════════════════════════════════════════════════════════

// Load trade data on first bar only
if barstate.isfirst
    if array.size(tradeTimes) > 0
        for i = 0 to array.size(tradeTimes) - 1
            int tradeTime = array.get(tradeTimes, i)
            if tradeTime > 0
                int direction = array.get(tradeDirections, i)
                float price = array.get(tradePrices, i)
                int qty = array.get(tradeQtys, i)
                array.push(trades, TradeSignal.new(tradeTime, direction, price, qty))

// Calculate bar duration for matching
int barDuration = timeframe.in_seconds(timeframe.period) * 1000
int nextBarTime = time + barDuration

// Check each trade for execution
int tradeCount = array.size(trades)

for i = 0 to math.max(0, tradeCount - 1)
    if tradeCount > 0
        TradeSignal trade = array.get(trades, i)
        int tradeKey = trade.tradeTime

        // Entries: Place order on preceding bar (look ahead to next bar)
        bool entryMatch = trade.direction != 0 and nextBarTime <= trade.tradeTime and trade.tradeTime < nextBarTime + barDuration

        // Exits: Check on current bar if the exit price was crossed
        bool exitMatch = trade.direction == 0 and time <= trade.tradeTime and trade.tradeTime < time + barDuration

        // Execute entries
        if entryMatch and not map.contains(executedTrades, tradeKey)
            if trade.direction == 1
                strategy.entry("Long", strategy.long, qty=trade.qty, comment="Long")
            else if trade.direction == -1
                strategy.entry("Short", strategy.short, qty=trade.qty, comment="Short")
            map.put(executedTrades, tradeKey, true)

        // Execute exits - check if price was crossed using 1-minute data
        if exitMatch and not map.contains(executedTrades, tradeKey)
            if priceCrossedInBar(trade.price)
                if strategy.position_size > 0
                    strategy.close("Long", comment="Exit", immediately=true)
                else if strategy.position_size < 0
                    strategy.close("Short", comment="Exit", immediately=true)
                map.put(executedTrades, tradeKey, true)

Overview

TradersPost Trade Replay uses fixed position sizing of 1 with initial capital 10000 and commission 0.62. The script draws no extra plots, just overlays executions on the price chart. Trade data comes from a hardcoded array generated by a separate Python tool that converts CSV exports. It repaints on the live bar and has no stop loss by default. No user input settings exist since data is preloaded.

Details

Published by

TradersPost on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy enters trades without a stop loss
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.

Similar Pine Scripts

Doge SMA

by hackingthemarkets
474 stars

Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA
440 stars

This script is an empty strategy template for Pine Script developers. It declares a version 4 strategy named Basic Strategy Boilerplate with the short title Strategy Boilerplate and sets overlay to true so any future plots would appear on the price chart. It d

Strategy v4
Updated 7 years ago · GPL-3.0 GitHub repository of Basic Strategy Boilerplate

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow

Strategy v6 TrendMoving averages
Updated today · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy

This overlay strategy offers two selectable entry modes: a Bollinger squeeze on typical price and a simple moving-average cross. It filters trades by weekday, session, date range, and an optional news window, and can restrict direction or invert the side. Risk

Strategy v5 Volatility & bandsMoving averages
Updated today · None stated GitHub repository of Boilerplate Configurable Strategy [Yosiet]

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers