Welcome to The Lengthy and the Quick—a present the place you’ll be able to anticipate an sincere tackle buying and selling. One thing you received’t hear elsewhere. I’m Sandeep Rao.

Why Be taught Backtesting?

Again in episode 6, we lined the what and the why of backtesting, its historical past, and the core ideas. Now could be the time for the how a part of it. This has been a extremely requested subject, and at present I’m overlaying it.

On this e-newsletter, I’ll stroll you thru step-by-step the exact strategies and instruments we use to run the backtests you see in lots of our episodes. You’ll discover ways to run them precisely like we do. With that, let’s get began.

The Two Instruments We Use: TradingView + Claude AI

As all the time, I need to set the stage by introducing the 2 important instruments that make our backtesting course of potential.

First, you want TradingView. That is an unbiased third-party platform for charting and, extra importantly, for backtesting. I ought to point out that the TradingView charts you see on Zerodha Kite are simply charts.

To run the backtests that I focus on, you want direct entry to the TradingView platform itself. You should use the free tier, however in the mean time I’m utilizing a paid plan which merely provides me entry to extra longer historical past of knowledge for extra thorough backtesting.

We’ll use Claude for 2 key causes: one, to put in writing the backtesting script, which can be written within the Pine Script language, and two, we would wish Claude to research the commerce logs, which might come after the backtest. Once more, you should use the free plan for Claude, however in the mean time, I’m utilizing a paid one.

Now right here’s a disclaimer: this isn’t a paid promotion for both TradingView or for Claude. These are merely the instruments that I take advantage of to run the backtests you see on this present. So with the disclaimers out of the way in which, now let’s get began with the important thing steps.

The 5 Key Steps of Backtesting

Backtesting includes 5 key steps:

1. Speculation Choice or Creation

This implies defining the particular technique or concept you need to check. For instance, you could need to check a trend-following technique on Nifty. That might be one speculation. You may make it extra particular by saying “long-only trend-following technique on Nifty.” That’s additionally potential, which implies you are taking solely lengthy indicators and ignore the quick indicators.

2. Selecting the Technique or Indicator

To create a trend-following technique or to generate trend-following indicators, you want a technique. Two strategies we’ve spoken about up to now are shifting averages and utilizing a breakout indicator like SuperTrend.

3. Code the Technique in Pine Script

It is a step the place we’ll use Claude AI to put in writing the technique code. You see, that is such a boon, proper? I imply, earlier you needed to write the code your self, however now you don’t must. Claude does a tremendous job at it.

4. Run the Technique in TradingView

Run the technique throughout a number of timeframes to watch its preliminary efficiency and outcomes. It is a quite simple step.

5. Obtain and Analyze the Commerce Logs

Crucial step is to obtain and analyze the commerce logs utilizing Claude AI once more to carry out a deep evaluation of the detailed commerce historical past for additional refinement.

The main focus of this video can be on steps three to 5, which incorporates the end-to-end demonstration of writing the Pine Script code utilizing Claude, operating the backtest, and doing the evaluation of the commerce logs generated by the TradingView platform.

Setting Up and Operating the Backtest in TradingView

The method begins with logging into TradingView and opening your chosen image. For this demonstration, we’ll work with two devices: Nifty spot and Gold M futures. Gold M will illustrate some particular factors we’ll cowl shortly, however let’s begin with Nifty.

The Nifty spot chart shows customary timeframes—every day, hourly, and others—with a clear slate. No indicators are utilized but, and the chart stays uncluttered.

Step one on this course of includes shifting to Claude to put in writing the technique script. This kinds the muse for the whole lot that follows.

Writing the Technique Code with Claude

The subsequent step is easy: immediate Claude with a easy request—” Write me a method indicator in Pine Script utilizing SuperTrend.”

That’s it. Sonnet 4.5 handles the heavy lifting. Inside moments, the code is generated on display.

The output consists of a number of default parameters that Claude has preset, together with extra configurable choices. As soon as the code seems, copy it from the highest of the response.

Implementing the Code

Again in TradingView, open the Pine Editor from the toolbar. Inside the editor, create a brand new technique. The editor shows some default code—delete this solely and paste the code copied from Claude.

After pasting, click on to compile the script. The consequence: a functioning SuperTrend technique seems in your editor. Click on Save to protect the work.

Seeing the Technique in Motion

As soon as saved and utilized, the chart transforms. Lengthy and quick place markers now populate the worth chart, indicating the place the technique would have triggered entry and exit indicators based mostly on the SuperTrend indicator.

Configuring Technique Settings

With the technique now lively on the chart, the essential subsequent step includes configuring the settings appropriately. Click on on the technique title to entry its settings menu.

Reviewing the Inputs

The Inputs tab shows the default parameters—these work fantastic for now. We’ll revisit and modify these later within the course of.

Important Properties Configuration

The Properties tab requires particular changes to make sure correct calculations:

Forex: Change the setting to INR to match the instrument’s denomination.

Default Order Dimension: Set this to 75. This amount serves because the baseline for all technique calculations. Whereas this quantity can fluctuate, sustaining 75 ensures consistency throughout the backtesting course of.

Order Execution Timing: Allow the “bar shut” choice. This setting ensures trades register solely upon the completion of every bar, somewhat than triggering mid-bar. This strategy supplies extra lifelike backtesting outcomes that align with precise buying and selling situations.

After making these changes, the technique is correctly configured and prepared for testing.

Reviewing Technique Efficiency

The technique report supplies a complete view of efficiency metrics. Switching to share phrases reveals the comparability between two approaches: the inexperienced line represents the fairness curve of the technique, whereas the blue line reveals a easy buy-and-hold strategy.

The numbers inform an attention-grabbing story. Holding the instrument from inception would have generated returns of 114%. Buying and selling the technique, nevertheless, would have yielded roughly 118%—a modest however significant outperformance.

Understanding Drawdowns

The bar chart beneath the fairness curve illustrates drawdown durations—the peak-to-trough declines the technique skilled. Notable drawdowns of 18% seem at a number of factors all through the backtest interval.

Regardless of these drawdowns, the technique demonstrates appreciable advantage when in comparison with buy-and-hold, notably in the way it manages these declines. The drawdown profile reveals much less severity than the buy-and-hold various, with the fairness curve displaying comparatively smoother declines throughout market corrections.

Efficiency Breakdown

The efficiency abstract separates outcomes by path. Lengthy positions contributed roughly 111% to total returns, whereas quick positions added simply 7%. This disparity suggests the technique may doubtlessly perform successfully with out the quick aspect—an perception value exploring additional.

Open P&L displays the present operating commerce, which isn’t related for historic evaluation.

The interface shows quite a few extra parameters for monitoring, although these will be reviewed on an as-needed foundation. Many merchants want calculating customized metrics from the uncooked commerce logs—a course of we’ll cowl shortly. Nonetheless, these built-in metrics serve effectively for fast visible assessments of technique efficiency.

Commerce Evaluation and Key Ratios

The commerce evaluation part comprises important statistics: complete variety of trades, open positions, profitable and shedding trades, and the share worthwhile (win fee). Common P&L per commerce seems right here as effectively.

The ratios part follows, displaying Sharpe ratio, Sortino ratio, revenue issue, and margin name information—customary metrics for evaluating risk-adjusted returns.

Exporting Commerce Knowledge

Probably the most essential part sits on the backside: the whole listing of trades. This granular information kinds the muse for deeper evaluation. The subsequent step includes exporting this commerce listing from TradingView and importing it into Claude for customized calculations and insights.

Utilizing Claude AI to Parse Metrics & Construct Stories

Exporting and Validating Commerce Knowledge

The obtain choice seems on the prime of the commerce listing. Click on this to export the whole commerce log from TradingView.

Transferring to Claude for Evaluation

With the file downloaded, return to Claude and add the commerce log. The primary essential step includes verifying information integrity earlier than continuing with any evaluation.

Immediate Claude with: “Are you able to please parse the information? Present me the 5 most up-to-date trades from the log.”

Why This Verification Issues

This preliminary verify serves as high quality management. The 5 most up-to-date trades displayed by Claude ought to match precisely what seems within the TradingView interface. Cross-reference the entry and exit factors, timestamps, and P&L figures between Claude’s output and the unique TradingView chart.

This verification step is non-negotiable. If discrepancies exist at this stage—if the information hasn’t been captured precisely—each subsequent calculation and perception can be compromised. Rubbish in, rubbish out.

Solely after confirming the information matches completely must you proceed to deeper evaluation.

Verifying Knowledge Accuracy

Claude shows the newest commerce: a protracted place initiated on November seventeenth with an entry at 26,010.5. This commerce stays lively.

Cross-referencing with the TradingView chart confirms the accuracy. The chart reveals the lengthy entry marker at exactly 26,010—matching the shut worth of that particular candle. The information aligns completely.

Double-Checking with Earlier Trades

A second verification provides confidence. The commerce earlier than the present one was a brief place. Given this can be a system that operates constantly, the exit of 1 commerce corresponds to the entry of the subsequent. The quick place’s exit ought to subsequently match the present lengthy entry at 26,010—which it does.

Transferring backward, that quick commerce’s entry occurred at 25,780 in line with the log. Again on the chart, the quick entry marker seems on the shut of the candle at 25,780. Once more, good alignment.

The Sanity Examine Full

These cross-checks—evaluating the log information towards precise chart markers—represent the important sanity check. The information has been captured appropriately within the commerce log. With this affirmation in place, the evaluation can proceed with confidence that the underlying information is dependable.

Producing Efficiency Metrics

With information validation full, the evaluation strikes to visualizing efficiency. The immediate to Claude: “Are you able to draw a cumulative P&L when it comes to factors based mostly on this commerce log? Additionally, draw a drawdown chart together with it.”

Claude processes the request and delivers greater than requested. Together with the charts, it supplies key efficiency metrics upfront: 331 trades executed over 5.9 years, gathered returns of 118%, remaining fairness worth, complete factors gained, and most fairness peak.

The fairness curve seems first—a visible illustration of cumulative revenue and loss over time. Under it, the drawdown chart illustrates the decline from peak fairness at varied factors all through the testing interval. This drawdown visualization in factors wasn’t available in TradingView’s interface, making Claude’s automated era notably precious.

Calculating Customized Metrics

Each dealer has most well-liked metrics—particular measurements that reveal whether or not a method meets their threat and return standards. Relatively than manually calculating each, the method will be streamlined.

The strategy: present Claude with a complete listing of desired metrics in a single immediate. “Are you able to learn this listing of 19 metrics and calculate it for me?”

Claude parses the request, identifies every metric, and performs the calculations based mostly on the backtest information. Inside moments, a whole efficiency abstract seems.

The output consists of the whole lot specified: testing interval, complete P&L, win fee, complete variety of trades, common profitable commerce, common shedding commerce, return to most drawdown ratio, and all different requested metrics. This complete view supplies the muse for evaluating whether or not the technique meets funding standards.

Creating Customized Stories

Past mixture metrics, granular time-based evaluation reveals patterns. The immediate: “Are you able to make a 12 months and month-wise desk in factors with the full column for every year?”

Claude generates a complete matrix exhibiting P&L in factors throughout each month and 12 months of the backtest. The desk shows efficiency for each lengthy and quick positions, with annual totals within the rightmost column.

The patterns emerge clearly: 2021 delivered subpar outcomes, 2022 proved distinctive, whereas 2023, 2024, and 2025 confirmed comparatively constant efficiency ranges. This temporal view helps determine whether or not the technique’s edge stays steady or varies considerably throughout totally different market regimes.

The Energy of Conversational Evaluation

The true benefit of utilizing Claude for commerce log evaluation lies in its flexibility. Any query concerning the information will be posed in pure language and answered instantly.

For instance: “When was the longest streak of worthwhile trades and what number of trades had been these?”

The response arrives immediately: the longest profitable streak consisted of seven consecutive worthwhile trades, operating from March thirteenth by Could twenty eighth, 2024.

Limitless Analytical Depth

This functionality extends to nearly any metric or query possible. Wish to know efficiency throughout particular market situations? Ask. Inquisitive about commerce distribution by day of week? Ask. Want to know drawdown restoration durations? Ask.

The fantastic thing about analyzing commerce logs by Claude lies on this conversational interface—no want to put in writing customized scripts or construct advanced spreadsheets. The information solutions no matter questions come up, remodeling backtest evaluation from a inflexible, predefined course of right into a dynamic exploration.

Steady Futures & Again-Adjusted Knowledge Defined

The demonstration to this point has targeted on Nifty spot—a simple instrument for backtesting. The methodology, nevertheless, applies equally to derivatives. The subsequent instance illustrates the right way to run the identical course of on Gold M, a futures product.

Earlier than continuing with the Gold M backtest, an essential idea requires clarification: steady futures contracts.

Gold M represents a steady futures sequence. To grasp what this implies and why it issues for backtesting…

Understanding Steady Futures

Steady futures information represents a single, prolonged worth sequence constructed by stitching collectively a number of particular person futures contracts.

At any second, three lively futures contracts commerce concurrently: the present month, subsequent month, and the month thereafter—every carrying its personal distinct worth. In November, for example, November, December, and January contracts all commerce in parallel.

For charting and backtesting functions, nevertheless, a single clean and uninterrupted worth sequence is important. When analyzing historic information, the sequence ought to replicate what was then the present month contract at every time limit.

The Rollover Downside

A complication arises at contract expiration. When one month-to-month contract ends and the subsequent begins, a worth distinction—referred to as the unfold—exists between the 2 sequence. This unfold creates a spot within the information that doesn’t signify precise market motion.

Platforms handle this by a course of referred to as back-adjustment.

How Again-Adjustment Works

Contemplate a sensible instance. On rollover day, suppose Nifty November futures trades at 25,800 whereas Nifty December futures trades at 25,950.

Merely switching from November to December would create a 150-point soar on the chart. This soar isn’t an actual market transfer—it’s merely an artifact of fixing contracts.

TradingView solves this by proportional back-adjustment. The platform divides the subsequent month’s futures worth by the present month’s worth, then multiplies all earlier historic costs by this issue.

Utilizing the instance: 25,950 divided by 25,800 equals 1.005814. Each historic worth level earlier than the rollover will get multiplied by this issue, successfully eliminating the factitious hole whereas preserving the relative worth relationships all through the sequence.

Making use of Again-Adjustment in TradingView

With the idea of back-adjustment defined, the sensible utility in TradingView turns into easy. Earlier than operating any technique on steady futures, find the adjustment button within the chart toolbar and activate it. This step is non-negotiable—the information have to be back-adjusted earlier than technique testing begins.

As soon as clicked and highlighted, the historic worth sequence has been correctly adjusted to eradicate rollover gaps.

Optimizing Technique Parameters

Navigate to the Technique Tester and entry the general portfolio settings. Right here, parameter optimization can start.

On this instance, the ATR interval began at seven. Testing with a worth of ten reveals improved efficiency in comparison with two. This iterative course of—adjusting parameters and observing outcomes—helps determine optimum settings for the instrument.

Lengthy, Quick, or Each?

The place path setting affords three choices. The present choice reveals long-only trades. Switching to short-only reveals poor efficiency for this specific technique on gold. Enabling each lengthy and quick naturally produces higher returns than long-only, although the advance relies on the quick aspect’s contribution.

Experimentation with these settings reveals which configuration delivers superior risk-adjusted returns.

Configuration Settings

Within the Properties tab, futures contracts require particular settings: set each default order measurement and amount to 1, and guarantee execution happens on bar shut. These settings differ from the spot instrument configuration used earlier for Nifty.

Finishing the Evaluation

The remaining course of mirrors the Nifty workflow precisely. Obtain the commerce logs from the technique tester, add them to Claude, and proceed with complete evaluation utilizing the identical questioning strategy demonstrated earlier.

Why Gold Issues

This gold futures instance serves a particular objective: demonstrating the back-adjustment function obtainable in TradingView for sure futures contracts. For merchants working with Indian gold futures, this performance ensures correct backtesting that accounts for contract rollovers correctly.

Limitations of TradingView Backtests (India Context)

Whereas I’ve shared the right way to use TradingView for backtesting, it’s additionally essential to know its limitations:

First , in an Indian context, we don’t have historic choices information. In order that’s out.
Second , you can’t do portfolio-level testing at one level. You possibly can check a method solely on one image. Due to this fact, you can’t run a method in parallel on a number of symbols or make use of any technique that requires switching symbols.
Third , statistics-wise, if we have a look at it, there aren’t any options for segregating the information as in-sample and out-of-sample, and even stuff like walk-forward evaluation, and so on. Although this may be taken care of by deciding on totally different time durations whereas backtesting and downloading the information individually as two totally different datasets, and letting Claude do the job.

That stated, it’s nonetheless an excellent place to begin to do primary backtests and use instruments like Claude to do additional evaluation.

Closing Ideas: The “Blind Monkey vs. Backtesting Monkey” Analogy

Our base reference right here is being a blind monkey throwing darts versus being a monkey that does a backtest after which throws darts. The concept is to be extra just like the second monkey. However bear in mind, simply backtesting by itself doesn’t assure success. For all you recognize, the blind monkey should win.

I hope this supplies a transparent understanding of how we conduct backtests for episodes. And I additionally hope it encourages you to attempt totally different backtests.

Do share your questions, ideas, and suggestions within the feedback. I’ll do my finest to reply. Thanks for watching, and see you within the subsequent one.

Source link

Leave A Reply

Company

Bitcoin (BTC)

$ 91,005.00

Ethereum (ETH)

$ 3,008.24

BNB (BNB)

$ 877.96

Wrapped SOL (SOL)

$ 136.15
Exit mobile version