Open Close Cross Strategy plus ExplorerOpen Close Cross Strategy plus Explorer
V 1.0
There is a code that can control sensitivity. try to change 'ATR Multiplier' menu
There is a code for prevent 'repaint'. If you want it check 'Forces Non-Repainting' menu
thanks to
PMax Explorer STRATEGY & SCREENER KivancOzbilgic
Open Close Cross Strategy R5 revised by JustUncleL JustUncleL
Repainting
HTF High/Low Repaint StrategyHere is an another attempt to demonstrate repainting and how to avoid them. It happened few times to me that I develop a strategy which is giving immense returns - only to realize after few forward testing that it is repainting. Sometimes, it is well disguised even during forward testing.
In this simple strategy, conditions are as below:
Buy : When a 3M bar produces high and low higher than it's previous 3M bar high, low
Sell : When a 3M bar produces high and low lower than its previous 3M bar high, low.
Default setting is : lookahead = on and offset = 0
This means current 3M bar high low is plotted for all the daily bars within this month. Which means, strategy looks ahead of time to see this 3M bar high is higher than previous 3M bar high during the start of the first daily bar. Hence, this combination leads to massive repaint.
For example, trade made on October 2nd 2018 already knows well ahead of time that price is going to go down in next 3 months:
Similarly, after 2 years on October 2nd 2020 - the strategy already knows that last 3M high is going to be breached on 7th December 2020
Solution: If you are using security for higher timeframes, safer option is always to use offset 1. Further details in the trading view script:
BUT
It may still repaint if we are passing function to security.
For example:
f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src , lookahead = barmerge.lookahead
This function will likely avoid any repainting with Higher timeframe if we are passing in built variables such as high, low, close, open etc. But, if we try to pass supertrend, this will not produce right results. This is because supertrend calculation in turn uses high/low/close values which do not consider the offset while calculating. Hence, even with offset 1, this will still produce issues.
Hence, the call:
= f_secureSecurity(syminfo.tickerid, derivedResolution, supertrend(3,10), offset) will again lead to massive repainting. Solution to this is to implement supertrend function and use high, low, close values derived from secureSecurity.
Quick tips to identify or be suspicious about repainting
Unbelievable results on all timeframes and all instruments with both long and short trades
Lower timeframes giving significantly higher returns on backtest when compared to higher timeframe
If these things happen, be wary about repainting and do a through check of all security function usage in your strategy.
All the best :)
PS: Apply 3-5 days resolution and see the fun. Also, WHC is one hell of a Christmas tree. Could have made immense profit in the same strategy even without repainting.
Higher TF - Repainting + Limiting backtest resultsThis strategy is for illustration purpose only. Do not use this as there is massive repainting.
As usual, I was experimenting with adding different entry/exit filters to my main strategy. Thought of adding higher frame filter, picked the code for getting higher time frame supertrend from someone else's script and copied it without thinking much about it.
security(syminfo.tickerid, f_multiple_resolution(HTFMultiplier), supertrend(SupertrendMult, SupertrendPd), lookahead = true, gaps=true)
Started getting better results with this result. I was very much impressed and while trying to enhance further, I started disabling my other entry and exit filters which I generally use.
That worked pretty well without any of my other filters. Hence, thought I will forward test this on a smaller timeframe.
To my surprise, even in forward testing, i was not able to notice repainting very much. It also appeared that smaller timeframes yielded better results. (This wasn't the case with any of my strategies)
Which then prompted me to study the security function and lookahead and gap parameters. Learned that lookahead and gap when set to true will lead to massive repainting - specially if you are using higher timeframes. Hence, these parameters are not advisable to use in strategies.
Further information here: www.tradingview.com
I added three repaint options to further illustrate how security function will work:
Yes : Use security with lookahead and merge set to true
No - set lookahead false : Use security with lookahead and merge set to false
No - do not use security : Falls back to original command on current timeframe. Switch timeframe to HTF resolution to compare the difference.
Conclusion : Always set lookahead and gaps to false when using security function in strategies.
PS: Script also contains code to limit backtesting to certain days/months/years. This can be used as is in other scripts.
Upper Timeframe - Repaint FixThis script is a proof of concept and one possible solution for how to deal with upper timeframe repainting issues. It works for Strategies only .
Strategies that utilize data from upper timeframes can still be subject to repainting issues when forward testing. Users can copy the code and use a similar solution in your own scripts.
For full code commentary, explanations and examples visit the backtest-rookies (.com) website.
Daily Close repainting resultsit's a repainting script cheating on tester, on backtesting %100 correct but on forward testing it will only work % 15 correct and %85 wrong. I did another script showing real forward testing results of this script.
Daily Close Comparison Strategy (by ChartArt via sirolf2009)Comparing daily close prices as a strategy.
This strategy is equal to the very popular "ANN Strategy" coded by sirolf2009(1) which calculates the percentage difference of the daily close price, but this bar-bone version works completely without his Artificial Neural Network (ANN) part.
Main difference besides stripping out the ANN is that my version uses close prices instead of OHLC4 prices, because they perform better in backtesting. And the default threshold is set to 0 to keep it simple instead of 0.0014 with a larger step value of 0.001 instead of 0.0001. Just like the ANN strategy this strategy goes long if the close of the current day is larger than the close price of the last day. If the inverse logic is true, the strategy goes short (last close larger current close). (2)
This basic strategy does not have any stop loss or take profit money management logic. And I repeat, the credit for the fundamental code idea goes to sirolf2009.
(2) Because the multi-time-frame close of the current day is future data, meaning not available in live-trading (also described as repainting), is the reason why this strategy and the original "ANN Strategy" coded by sirolf2009 perform so excellent in backtesting.
All trading involves high risk; past performance is not necessarily indicative of future results. Hypothetical or simulated performance results have certain inherent limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not actually been executed, the results may have under- or over-compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profits or losses similar to those shown.
(1) You can get the original code by sirolf2009 including the ANN as indicator here:
(1) and this is sirolf2009's very popular strategy version of his ANN: