TradingView
jdehorty
2023年2月10日早上5點44分

Backtest Adapter 

Bitcoin / US DollarBinance

描述

This is a proof-of-concept Backtest Adapter that can be used with my recent publication "Machine Learning: Lorentzian Classification" located here:

tradingview.com/script/WhBzgfDu-Machine-Learning-Lorentzian-Classification/

This adapter is helpful because it enables interactive backtesting with TradingView's built-in "Strategy Tester" framework without the need to translate the logic from an "indicator" script to a "strategy" script.

To use this, one must have the "Machine Learning: Lorentzian Classification" script and this Backtest Adapter open simultaneously on the same chart. From there, simply change the "Source" setting of the Backtest Adapter to "Lorentzian Classification: Backtest Stream" to transfer the entry/exit signals stream to the Backtest Adapter.

For an example of how to implement your own backtest stream in your indicators, please refer to the "Backtesting" section in the source code of the "Machine Learning: Lorentzian Classification" script, which is shown below for convenience:

發布通知

Updated the Source of the Backtest Adapter to be set to "Lorentzian Classification: Backtest Stream"

發布通知

Removed hardcoded `transactionQty` to use default strategy quantity, simplifying order execution code.
評論
Trendoscope
I use similar technique but not for strategy. Instead use that for coding external filters. And plug these as external inputs to existing strategies and indicators.

1 : only allow long trades
-1 : only allow short trades
0 : do not allow any trades
2 : allow both sides.
jdehorty
@HeWhoMustNotBeNamed I like that idea a lot. Keeps the logic reusable and pure. I'd love to take a look; do you have any links to any open-source examples of this?
Trendoscope
@jdehorty, this was first one. It only defines trading zone based on volatility (0 and 2 only)

tradingview.com/script/5egLveLn-Relative-Bandwidth-Filter/

There are few more trend filters.
djmad
kkimpa
Hello, first of all, appreciate the indicator.

I have the "Machine Learning: Lorentzian Classification" script and this Backtest Adapter open simultaneously on the same chart.
And I also changed the "Source" setting of the Backtest Adapter to "Lorentzian Classification: Backtest Stream". But strategy tester tab shows "no data". What shoud I change?
obviousPython29625
Hi Great Work on Lorentzian Classification, Has removed transaction Qty which is really useful for Calculating P&L to exact Dime, Tested on BTCUSTD for 8 Hrs on 1min Timeframe by activating the alert and validating the trade book, Never missed a single trade worked like a charm.

if startLongTrade and inTradeWindow
strategy.order("Enter Long", strategy.long)

if endLongTrade and strategy.position_size > 0 and inTradeWindow
strategy.order("Exit Long", strategy.short)

if startShortTrade and inTradeWindow
strategy.order("Enter Short", strategy.short)

if endShortTrade and strategy.position_size < 0 and inTradeWindow
strategy.order("Exit Short", strategy.long)
info74940
@obviousPython29625, indeed.. thanks for the great work, one way to improve even better is to allow USD or % of initial capital to be adjusted into the backtesting rather than just a standard Qty = 1

Also I noticed in the backtest that once closing a long position, the strategy does not automatically open another short position. Was wondering if that's on purpose and if it could have the option to do so.
Zerotic_
@obviousPython29625, This just breaks the script for me
EDIT: Actually it resets the source, gotta reselect the stream
papy777
@obviousPython29625, Hello
I would like to know where to place this in the indicator script please...
I would like to be able to change the alerts in the indicator like you did

sorry for my english it's the translator

I await your response with impatience

THANKS
helpfulDingo69431
Really good tool but the backtest adapter seems to always close the trade on the 4th candle after open, is this by design or adjustable? Sorry only just starting to learn about this stuff I would have thought it should be possible to define the strategy?
更多