TradingView
Thumpyr
26 מרץ 2022 19:43

Backtesting- Indicator 

תיאור

For anyone interested, Here is an example of how to put backtesting results into an Indicator. This calculates the same values as you find in the Summary Screen of the built in Strategy backtester. This will use the same result size as the standard backtester i.e. 5 minute chart grabs roughly 1 month of data, 1 minute chart grabs 1 week of data, etc... I tried to keep this as self-contained as possible so I put most of the code for the results in the bottom of the Indicator. The results stop at the last completed trade signal i.e. a Buy has a Sell to it. This is the same indicator I posted earlier with the PCT Trailing StopLoss so you will see that code in here as well. As said in my previous posting, the indicator is just a simple EMA crossover to give it something to do and I would not recommend using this indicator on its own, but instead copy the code to your own indicator if you find it useful. I also left the code in so that you can switch back to a Strategy if you want to verify the results.

Additional Notes:
- The results are within an acceptable margin of error due to the fact that the Indicator is having to calculate based on when the Buy and Sell Signal occur as opposed to when actual trades occur like in the Strategy Backtester
- I was trying to find a way to set the number of Buy Signals to use i.e. show me the results from the past 100 trades but couldn't sort out the logic. I am open to suggestions. Also keep in mind I am not a coder by profession so if you have any ideas on that front, please explain it to me as though I am a 5 year old child and provide code examples if possible :)
- I included the Strategy results in the Screen Shots so that you can see where the results line up.
Additional Additional Note:
This is not financial advice. Use at your own risk.
תגובות
luckyEggs35697
Thank you very much for your job
A_Traders_Edge
Should be easy (though just from my thinking… I’m not sure how that would be helpful data to see). What info do you want to store from each of your “last 100 trades”(as per your example) to be able to view?
Thumpyr
@chasinalts, The chart only pulls in a certain amount of data by default. In the example I posted, that amount of data results in 51 trades. In general, for backtesting I like to see as much data as possible across a range of market conditions that occur over time. I don't know how to get more historical data into the chart or if that is possible. Provided it is possible to pull in more historical data, it would be neat to be able to be able to set how many trades to look back for the backtest. I guess the primary question is, can you pull in more historical data than what the chart does by default? As far as the data to store is concerned, it would be the same data it is tracking now just across a larger data set.
עוד