TradingView
Trendoscope
Dec 7, 2020 11:51 AM

HTF High/Low Repaint Strategy 

WHITEHAVEN COAL LIMITEDASX

描述

Here 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:
tradingview.com/script/cyPWY96u-How-to-avoid-repainting-when-using-security-PineCoders-FAQ/

BUT

It may still repaint if we are passing function to security.

For example:
f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], 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:
[supertrend, dir] = 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.
评论
makemoneybysitting
Thanks for sharing!!
when I try it, there's a sign that says "study error, quantity for entry or order must be a positive number les or equal to 1000000 passed value is -1.85"
Wish you all the best!
Trendoscope
@alexisnassimoff, I think setting equity percentage to less than 100% in settings would solve this. Which instrument you were trying?
makemoneybysitting
@HeWhoMustNotBeNamed, Thank you for your answer. I am trying ETHUSD coinbase exchange
makemoneybysitting
@HeWhoMustNotBeNamed, now is fixed. Thanks a lot for your help
OutsourcE
I'll call it "Tony Montana" ,if you don't mind..
Trendoscope
@OutsourcE, Repainting? Oh yeah. it is silent assassin. We don't know when we get killed :P
navrang081
can provide this script logic ?
furqatjabborov397
@HeWhoMustNotBeNamed hello which time frame can we use to eliminate repainting
Trendoscope
@furqatjabborov397, repainting isn't timeframe specific. It can happen on any timeframe if not coded properly
dos32101
Gracias
更多