{"id":12131,"date":"2026-08-29T17:33:14","date_gmt":"2026-08-29T14:03:14","guid":{"rendered":"https:\/\/algoyar.com\/?post_type=tutorials&#038;p=12131"},"modified":"2026-08-29T18:09:36","modified_gmt":"2026-08-29T14:39:36","slug":"replay","status":"publish","type":"tutorials","link":"https:\/\/algoyar.com\/en\/tutorials\/replay\/","title":{"rendered":"Replay on Tradingview Basic Acounts"},"content":{"rendered":"<h2 dir=\"ltr\">Simulating TradingView Bar Replay with Pine Script<\/h2>\n<p dir=\"ltr\">One of TradingView\u2019s most useful features for practice, strategy testing, and analyzing historical price action is <strong>Bar Replay<\/strong>. It allows traders to move the chart back to a specific point in the past and then watch the market unfold from that point onward, one bar at a time.<\/p>\n<p dir=\"ltr\">This makes it possible to recreate conditions similar to a live market, without knowing what happened next in the chart.<\/p>\n<p dir=\"ltr\">In this tutorial, we\u2019ll explore how to use <strong>Pine Script<\/strong> to create a simple version of this functionality. Although this approach does not offer all the features of TradingView\u2019s native Bar Replay, it can still be very useful for practicing and testing trading ideas.<\/p>\n<h3 dir=\"ltr\">What Is Bar Replay and What Is It Used For?<\/h3>\n<p dir=\"ltr\">Bar Replay is a tool for reviewing and analyzing historical market behavior. You can select a specific point on the chart as the starting point and then reveal subsequent bars step by step.<\/p>\n<p dir=\"ltr\">For example, suppose you want to practice a trading strategy. Instead of looking at the entire chart from start to finish, you can go back to a specific date in the past and hide everything that happened afterward.<\/p>\n<p dir=\"ltr\">This way, you only have access to the information that would have been available at that point in time. You can then decide whether you would have entered a trade, set your stop-loss and take-profit levels, and continue advancing through the chart to see how the trade would have played out.<\/p>\n<p dir=\"ltr\">This makes Bar Replay particularly useful for <strong>practicing technical analysis, testing trading ideas, and improving decision-making skills<\/strong>.<\/p>\n<p dir=\"ltr\">TradingView also describes Bar Replay as a tool for simulating historical market conditions and practicing trading. You can select a starting point and replay historical price action at different speeds. (<a title=\"Bar Replay: how and why to test a strategy in the past \u2014 TradingView\" href=\"https:\/\/www.tradingview.com\/support\/solutions\/43000712747-bar-replay-how-and-why-to-test-a-strategy-in-the-past\/?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noopener\">TradingView<\/a>)<\/p>\n<hr dir=\"ltr\" \/>\n<h2 dir=\"ltr\">Limitations of Bar Replay and the Pine Script Approach<\/h2>\n<p dir=\"ltr\">TradingView\u2019s native Bar Replay offers many more features than the approach we\u2019re going to build in this tutorial. For example, you can control the replay, change the playback speed, and, depending on your plan, access a greater amount of historical data.<\/p>\n<p dir=\"ltr\">The features available in Bar Replay and the amount of historical data you can access also depend on your TradingView plan and timeframe. Currently, TradingView provides different levels of historical Intraday data across its plans, with Premium and Professional plans offering access to deeper Intraday history. (<a title=\"How much data is available for Bar Replay? \u2014 TradingView\" href=\"https:\/\/www.tradingview.com\/support\/solutions\/43000692816-how-much-data-is-available-for-bar-replay\/?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noopener\">TradingView<\/a>)<\/p>\n<p dir=\"ltr\">But here\u2019s an interesting question:<\/p>\n<p dir=\"ltr\"><strong>Can we create a simple version of Replay using Pine Script?<\/strong><\/p>\n<p dir=\"ltr\">The answer is yes.<\/p>\n<p dir=\"ltr\">Of course, this approach is not a full replacement for Bar Replay. Instead, it is a simple technique for <strong>hiding part of the chart and gradually revealing it<\/strong>.<\/p>\n<p dir=\"ltr\">The basic idea is straightforward:<\/p>\n<blockquote dir=\"ltr\"><p>Define a specific point in time and display only the bars whose timestamps are earlier than that point.<\/p><\/blockquote>\n<p dir=\"ltr\">Whenever we move this time marker, the number of visible bars will change accordingly.<\/p>\n<hr dir=\"ltr\" \/>\n<h2 dir=\"ltr\">Using <code>plotcandle<\/code> to Recreate Candles<\/h2>\n<p dir=\"ltr\">To implement this idea in Pine Script, we can use the <code>plotcandle<\/code> function.<\/p>\n<p dir=\"ltr\">This function allows us to draw candles on the chart using custom <strong>Open, High, Low, and Close<\/strong> values.<\/p>\n<p dir=\"ltr\">For example, if we want to recreate exactly the same candles shown on the main chart, we can pass the OHLC values directly to <code>plotcandle<\/code>:<\/p>\n<pre dir=\"ltr\"><code class=\"language-pine\">plotcandle(open, high, low, close)<\/code><\/pre>\n<p dir=\"ltr\">An important advantage of this approach is that the OHLC values do not necessarily have to match those of the original candles.<\/p>\n<p dir=\"ltr\">For example, we can create candles using completely different calculations, similar to the way alternative chart types such as <strong>Heikin Ashi<\/strong> calculate their Open, High, Low, and Close values.<\/p>\n<p dir=\"ltr\">In this tutorial, however, our goal is simply to recreate the original candles without changing their values.<\/p>\n<p dir=\"ltr\">We can also define the candle colors based on the relationship between Open and Close.<\/p>\n<p dir=\"ltr\">If Close is greater than Open, we consider the candle bullish; if Close is lower than Open, we consider it bearish:<\/p>\n<pre dir=\"ltr\"><code class=\"language-pine\">COLOR = close &gt; open ? color.green : close &lt; open ? color.red : color.black<\/code><\/pre>\n<p dir=\"ltr\">We can then pass this color to <code>plotcandle<\/code>.<\/p>\n<p dir=\"ltr\">In addition to the candle body, we can also control the color of the wick and border:<\/p>\n<pre dir=\"ltr\"><code class=\"language-pine\">plotcandle(open, high, low, close, color = COLOR, wickcolor = COLOR, bordercolor = COLOR)<\/code><\/pre>\n<p dir=\"ltr\">As a result, we\u2019ll have candles that match the original chart in both their OHLC values and appearance.<\/p>\n<hr dir=\"ltr\" \/>\n<h2 dir=\"ltr\">Setting the Replay Point<\/h2>\n<p dir=\"ltr\">Now we get to the main part of the idea.<\/p>\n<p dir=\"ltr\">We need a time variable that the user can change from the indicator\u2019s settings.<\/p>\n<p dir=\"ltr\">In Pine Script, we can use <code>input.time<\/code> to let the user select a date and time:<\/p>\n<pre dir=\"ltr\"><code class=\"language-pine\">TIME = input.time(defval = timestamp(\"23 Nov 2021\"))<\/code><\/pre>\n<p dir=\"ltr\">We can also specify the hour, minute, and other details when defining the timestamp.<\/p>\n<p dir=\"ltr\">Now we need to answer an important question:<\/p>\n<p dir=\"ltr\"><strong>How do we determine which candles should be displayed?<\/strong><\/p>\n<p dir=\"ltr\">All we need to do is compare the timestamp of each bar with the time selected by the user.<\/p>\n<p dir=\"ltr\">For example:<\/p>\n<pre dir=\"ltr\"><code class=\"language-pine\">RP = time &lt; TIME<\/code><\/pre>\n<p dir=\"ltr\">Here, <code>RP<\/code> will be a Boolean value.<\/p>\n<p dir=\"ltr\">If the bar\u2019s timestamp is earlier than the selected time:<\/p>\n<pre dir=\"ltr\"><code class=\"language-text\">RP = true<\/code><\/pre>\n<p dir=\"ltr\">And if the bar\u2019s timestamp is later:<\/p>\n<pre dir=\"ltr\"><code class=\"language-text\">RP = false<\/code><\/pre>\n<p dir=\"ltr\">We can now use this condition to determine whether a candle should be displayed.<\/p>\n<hr dir=\"ltr\" \/>\n<h2 dir=\"ltr\">Hiding Candles After a Specific Point in Time<\/h2>\n<p dir=\"ltr\">To do this, we can define the OHLC values conditionally.<\/p>\n<p dir=\"ltr\">For example:<\/p>\n<pre dir=\"ltr\"><code class=\"language-pine\">OPEN  = RP ? open  : na\r\nHIGH  = RP ? high  : na\r\nLOW   = RP ? low   : na\r\nCLOSE = RP ? close : na<\/code><\/pre>\n<p dir=\"ltr\">The <code>na<\/code> value is important here.<\/p>\n<p dir=\"ltr\">When the <code>RP<\/code> condition is true, the actual Open, High, Low, and Close values are assigned to the variables.<\/p>\n<p dir=\"ltr\">When the condition is false, the variables receive <code>na<\/code>, so no candle will be plotted for that bar.<\/p>\n<p dir=\"ltr\">Finally, we can pass these values to <code>plotcandle<\/code>:<\/p>\n<pre dir=\"ltr\"><code class=\"language-pine\">plotcandle(OPEN, HIGH, LOW, CLOSE, color = COLOR, wickcolor = COLOR, bordercolor = COLOR)<\/code><\/pre>\n<p dir=\"ltr\">Now, whenever we change the date in the indicator settings, the point after which the candles are hidden will also move.<\/p>\n<hr dir=\"ltr\" \/>\n<h2 dir=\"ltr\">Turning the Indicator into a Simple Replay Tool<\/h2>\n<p dir=\"ltr\">Once we place the indicator on the main chart, we can use the time marker to move through historical price action.<\/p>\n<p dir=\"ltr\">For example, suppose we set the Replay date to a specific day.<\/p>\n<p dir=\"ltr\">Only the candles before that point will be displayed.<\/p>\n<p dir=\"ltr\">If we move the time marker forward, more candles will appear.<\/p>\n<p dir=\"ltr\">If we move it backward, more of the future will be hidden.<\/p>\n<p dir=\"ltr\">This allows us to go back to a point in the market, perform our analysis, and then gradually move the Replay point forward to see whether our analysis matches what actually happened afterward.<\/p>\n<p dir=\"ltr\">Conceptually, this is similar to Bar Replay, but instead of using TradingView\u2019s native Replay controls, we control the process through the <strong>time parameter of our indicator<\/strong>.<\/p>\n<hr dir=\"ltr\" \/>\n<h2 dir=\"ltr\">An Important Limitation When Using Other Indicators<\/h2>\n<p dir=\"ltr\">There is an important limitation to this approach.<\/p>\n<p dir=\"ltr\">Suppose we add a Moving Average to the chart separately.<\/p>\n<p dir=\"ltr\">You might expect the Moving Average to stop at the same point because part of the chart has been hidden.<\/p>\n<p dir=\"ltr\">However, that is not what happens.<\/p>\n<p dir=\"ltr\">The original candles still exist on the chart; we are simply hiding them using <code>plotcandle<\/code>.<\/p>\n<p dir=\"ltr\">As a result, the Moving Average continues to be calculated using the <strong>actual, complete chart data<\/strong>, including candles that are supposed to remain hidden during the Replay.<\/p>\n<p dir=\"ltr\">This means the Moving Average can still have access to future price data, which can compromise the results of the exercise.<\/p>\n<p dir=\"ltr\">For example:<\/p>\n<pre dir=\"ltr\"><code class=\"language-text\">Visible candles\r\n\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\r\n\r\nHidden candles\r\n\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\r\n\r\nMoving Average\r\n\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588<\/code><\/pre>\n<p dir=\"ltr\">In other words, the Moving Average continues to use information from the future, even though those candles are no longer visible.<\/p>\n<hr dir=\"ltr\" \/>\n<h2 dir=\"ltr\">The Solution: Calculate the Indicator Within the Same Script<\/h2>\n<p dir=\"ltr\">If your analytical approach is well-defined and you are using indicators whose code is available to you, this problem can be largely addressed.<\/p>\n<p dir=\"ltr\">For example, if you know exactly how your Moving Average is calculated, you can include its calculation directly inside the same Replay script.<\/p>\n<p dir=\"ltr\">Suppose the Moving Average is calculated as follows:<\/p>\n<pre dir=\"ltr\"><code class=\"language-pine\">MA = ta.sma(close, 20)<\/code><\/pre>\n<p dir=\"ltr\">We can apply the same Replay condition to it:<\/p>\n<pre dir=\"ltr\"><code class=\"language-pine\">MA_REPLAY = RP ? MA : na<\/code><\/pre>\n<p dir=\"ltr\">And then plot it:<\/p>\n<pre dir=\"ltr\"><code class=\"language-pine\">plot(MA_REPLAY)<\/code><\/pre>\n<p dir=\"ltr\">Now the Moving Average will only be displayed while the Replay condition is true.<\/p>\n<p dir=\"ltr\">As a result, when we move the Replay point, both the candles and the Moving Average will move together.<\/p>\n<p dir=\"ltr\">This creates a much more realistic environment for practicing a trading strategy.<\/p>\n<hr dir=\"ltr\" \/>\n<h2 dir=\"ltr\">Which Indicators Can Be Used with This Method?<\/h2>\n<p dir=\"ltr\">This technique is particularly useful when the indicator you are using can be recreated or calculated within the same script.<\/p>\n<p dir=\"ltr\">For example, indicators such as:<\/p>\n<ul dir=\"ltr\">\n<li>Moving Average<\/li>\n<li>EMA<\/li>\n<li>SMA<\/li>\n<li>Bollinger Bands<\/li>\n<li>Some trend-following indicators<\/li>\n<li>Many price-based calculations<\/li>\n<\/ul>\n<p dir=\"ltr\">can be incorporated into this type of setup.<\/p>\n<p dir=\"ltr\">However, things are somewhat different with indicators that are displayed in a separate pane, such as RSI, MACD, and other oscillators. In these cases, the <code>force_overlay<\/code> feature can be used.<\/p>\n<p dir=\"ltr\">The logic for the separate-pane indicator still needs to be handled appropriately. Otherwise, the indicator may continue to display information from bars beyond the Replay point.<\/p>\n<hr dir=\"ltr\" \/>\n<h2 dir=\"ltr\">Another Consideration When Changing Timeframes<\/h2>\n<p dir=\"ltr\">If you set the Replay point on a higher timeframe and then switch to a much lower timeframe, the selected point may no longer fall within the visible range of the chart.<\/p>\n<p dir=\"ltr\">In such cases, you might think that the indicator has disappeared, but that is not necessarily the case.<\/p>\n<p dir=\"ltr\">You can usually select the indicator and locate the Replay line or marker, then move it back into the appropriate area of the chart.<\/p>\n<p dir=\"ltr\">It is also worth noting that TradingView does not provide the same amount of historical data across all timeframes. For example, daily data for a symbol may be available much further back in history, while one-minute data for the same symbol may only be available from a much more recent date. (<a title=\"How much data is available for Bar Replay? \u2014 TradingView\" href=\"https:\/\/www.tradingview.com\/support\/solutions\/43000692816-how-much-data-is-available-for-bar-replay\/?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noopener\">TradingView<\/a>)<\/p>\n<hr dir=\"ltr\" \/>\n<h2 dir=\"ltr\">Conclusion<\/h2>\n<p dir=\"ltr\">Bar Replay is a useful TradingView tool for practicing and analyzing historical market behavior. However, in some situations, you may want a simpler way to hide future price action and gradually reveal it as you analyze the market.<\/p>\n<p dir=\"ltr\">With Pine Script, we can create a basic version of this functionality by combining a few simple concepts:<\/p>\n<ol dir=\"ltr\">\n<li>Define a date and time using <code>input.time<\/code><\/li>\n<li>Compare each bar\u2019s timestamp with the selected time<\/li>\n<li>Use a Boolean condition such as <code>RP<\/code><\/li>\n<li>Hide candles after the Replay point by assigning <code>na<\/code><\/li>\n<li>Recreate the candles using <code>plotcandle<\/code><\/li>\n<li>Apply the same condition to the indicators being used<\/li>\n<\/ol>\n<p dir=\"ltr\">Of course, this method <strong>is not a replacement for TradingView\u2019s native Bar Replay<\/strong> and does not provide features such as playback speed control, standard step-by-step replay, and some of the advanced Replay functionality. TradingView\u2019s native Bar Replay offers a much broader set of features, including the ability to synchronize Replay across multiple charts. (<a title=\"How do I turn Bar Replay on? \u2014 TradingView\" href=\"https:\/\/www.tradingview.com\/support\/solutions\/43000474024-how-do-i-turn-bar-replay-on\/?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noopener\">TradingView<\/a>)<\/p>\n<p dir=\"ltr\">From an educational perspective, however, this technique demonstrates something important: <strong>Pine Script gives us considerable control over how market data is displayed, allowing us to build custom tools tailored to our specific needs.<\/strong><\/p>\n<p dir=\"ltr\">If your goal is to practice a specific trading method, you can take this idea one step further by incorporating the logic of the indicators you use directly into the same script. This allows them to be calculated and displayed only within the portion of the market that is currently visible.<\/p>\n<p dir=\"ltr\">In this way, you can create a simple practice environment where only part of the market is initially available, perform your analysis, and then gradually move the Replay point forward to reveal what happened next\u2014just as you would in a live market, where you have no knowledge of the candles that have yet to form.<\/p>\n<p dir=\"ltr\"><strong>This approach can be a useful tool for practicing technical analysis, testing trading ideas, and evaluating the quality of your trading decisions using historical market data.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bar Replay is one of TradingView\u2019s most useful features for practicing and reviewing historical market behavior, but access to it is limited on the free plan. In this tutorial, we\u2019ll introduce a simple Pine Script workaround that can provide a practical alternative for practicing and analyzing the market in the past.<\/p>\n","protected":false},"featured_media":12134,"comment_status":"open","ping_status":"closed","template":"","class_list":["post-12131","tutorials","type-tutorials","status-publish","has-post-thumbnail","hentry"],"_links":{"self":[{"href":"https:\/\/algoyar.com\/en\/wp-json\/wp\/v2\/tutorials\/12131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/algoyar.com\/en\/wp-json\/wp\/v2\/tutorials"}],"about":[{"href":"https:\/\/algoyar.com\/en\/wp-json\/wp\/v2\/types\/tutorials"}],"replies":[{"embeddable":true,"href":"https:\/\/algoyar.com\/en\/wp-json\/wp\/v2\/comments?post=12131"}],"version-history":[{"count":1,"href":"https:\/\/algoyar.com\/en\/wp-json\/wp\/v2\/tutorials\/12131\/revisions"}],"predecessor-version":[{"id":12133,"href":"https:\/\/algoyar.com\/en\/wp-json\/wp\/v2\/tutorials\/12131\/revisions\/12133"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/algoyar.com\/en\/wp-json\/wp\/v2\/media\/12134"}],"wp:attachment":[{"href":"https:\/\/algoyar.com\/en\/wp-json\/wp\/v2\/media?parent=12131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}