DinGrogu

Backtest Strategy Optimizer Adapter - Supertrend Example

Sample Code
This is a sample code for my Backtest Strategy Optimizer Adapter library.
You can find the library at:
Backtest Strategy Optimizer Tester
With this indicator, you will be able to run one or multiple backtests with different variables (combinations). For example, you can run dozens of backtests of Supertrend at once with an increment factor of 0.1, or whatever you prefer. This way, you can easily grab the most profitable settings and use them in your strategy. The chart above shows different color plots, each indicating a profit backtest equal to tradingview backtesting system. This code uses my backtest library, available in my profile.

Below the code you should edit yourself
You can use ChatGPT or write a python script to autogenerate code for you.

// #################################################################
// # ENTRIES AND EXITS
// #################################################################
// You can use the link and code in the description to create
// your code for the desired number of entries / exits.
// #################################################################
// AUTO GENERATED CODE [BEGIN]
// ▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼

[_, _, _, entry_001, exit_001] = ti.supertrend(10, 0.1)
[_, _, _, entry_002, exit_002] = ti.supertrend(10, 0.2)
[_, _, _, entry_003, exit_003] = ti.supertrend(10, 0.3)
[_, _, _, entry_004, exit_004] = ti.supertrend(10, 0.4)
// 005 etc...

pnl_001 = backtest.profit(date_start, date_end, entry_001, exit_001)
pnl_002 = backtest.profit(date_start, date_end, entry_002, exit_002)
pnl_003 = backtest.profit(date_start, date_end, entry_003, exit_003)
pnl_004 = backtest.profit(date_start, date_end, entry_004, exit_004)

plot(pnl_001, title='0.1', color=backtest.color(001))
plot(pnl_002, title='0.2', color=backtest.color(002))
plot(pnl_003, title='0.3', color=backtest.color(003))
plot(pnl_004, title='0.4', color=backtest.color(004))

// Make sure you set the correct array size.
// The amount of tests + 1 (e.g. 4 tests you set it to 5)
var results_list = array.new_string(5)

if (ta.change(pnl_001))
	array.set(results_list, 0, str.tostring(pnl_001) + '|0.1')

if (ta.change(pnl_002))
	array.set(results_list, 1, str.tostring(pnl_002) + '|0.2')

if (ta.change(pnl_003))
	array.set(results_list, 2, str.tostring(pnl_003) + '|0.3')

if (ta.change(pnl_004))
	array.set(results_list, 3, str.tostring(pnl_004) + '|0.4')

// ▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
// AUTO GENERATED CODE [END]
// #################################################################
オープンソーススクリプト

TradingViewの精神に則り、このスクリプトの作者は、トレーダーが理解し検証できるようにオープンソースで公開しています。作者に敬意を表します!無料で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。 お気に入りに登録してチャート上でご利用頂けます。

免責事項

これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。

チャートでこのスクリプトを利用したいですか?