Average tester – are averages any good?
Forums › ProRealTime English forum › ProBuilder support › Average tester – are averages any good?
- This topic has 15 replies, 4 voices, and was last updated 3 years ago by Khaled.
-
-
02/23/2021 at 11:11 AM #162414
I have always hated averages. They are horrible lagging things that can easily be curve fitted but I decided to code something to see a little more easily how bad they are and to see if any of the popular average types are better than others.
So I coded this simple code that uses arrays to record the average gain/loss of any candle if it is preceded by a candle that meets a preset average condition. This condition can be something like close > average or low > average or even fast average > slow average. This tests long conditions but you can also test short by using the reverse condition.
The 8 most popular average types are tested so that their performance can be compared. The result is the average gain per candle. A datum of every candle on the chart is also calculated so we can see how our average condition performance compares to buy and hold.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647//Period setting for average//p = 24if barindex > 1 then//Choose only 1 of these result conditions//c1 = close - open //for long//c1 = open - close //for shortif islastbarupdate then$lastopen[0]=openendifif open<>$lastopen[0] thenfor t = 0 to 8//Choose only 1 of these entry conditions////Long Conditions//avgcond = low[1] > average[p,t](customclose)[1] //Low is above average//avgcond = close[1] > average[p,t](customclose)[1] //Close is above average//avgcond = average[p,t](close[1]) > average[p,t](close[2]) //Average is risingavgcond = average[p,t](close[1]) > average[p*2,t](close[1]) //Fast average is above slow average//Short Conditions//avgcond = high[1] < average[p,t](customclose[1]) //High is below average//avgcond = close[1] < average[p,t](customclose[1]) //Close is below average//avgcond = average[p,t](close[1]) < average[p,t](close[2]) //Average is falling//avgcond = average[p,t](close[1]) < average[p*2,t](close[1]) //Fast average is below slow averageif avgcond then$count[t] = $count[t] + 1if c1 then$total[t] = $total[t] + c1$avg[t] = ($total[t]/$count[t])endifendifnextendifdcount = dcount + 1dtotal = dtotal + c1davg = (dtotal/dcount)endifreturn $avg[0] as "Simple", $avg[1] as "Exponential", $avg[2] as "Weighted", $avg[3] as "Wilder", $avg[4] as "Triangular", $avg[5] as "End Point", $avg[6] as "Time Series", $avg[7] as "Hull", $avg[8] as "Zero Lag", davg as "Datum"The first attached image is of a test on the DJI daily chart. It tests long performance if the 24 day average > 48 day average. All averages have a lower average gain per candle than the buy and hold datum except for Hull, Zero Lag, Time Series and End Point averages where the performance is improved. So perhaps a simple filter like this can improve a strategy?
The second image tests if close > 24 day average and only the Time Series average beats buy and hold.
1 user thanked author for this post.
02/23/2021 at 11:21 AM #162418The 200 day average is often cited as a good filter for long term trading. Don’t be long unless price is above a simple moving average of it. Attached is the results of testing all the popular 200 day average types and it can be seen that on the DJI performance is terrible with a simple moving average compared to buy and hold. In fact only Time Series and End Point averages have improved performance by a little but if you look back at history they also were often under performing buy and hold in the past.
I think I’d give the 200 day average a total miss as a filter.
02/23/2021 at 11:31 AM #162420By changing lines 8 and 9 to:
12c1 = ((close - open)/open)*100 //for long//c1 = ((open - close)/open)*100 //for short….we can show the average gain per candle as a % of opening price which I think shows historical performance in a better format.
Attached is close > 50 day average for DJI in %.
02/23/2021 at 11:36 AM #162422MA’s alone are no good signals; they need further indicators or price action to be meaningful.
MA200 effectiveness should be tested on a strategy based on other inicators, say a combination of price action + Rsi divergences. Testing that strategy (or any other strategy) with/without MA200 would be indicative.
02/23/2021 at 11:43 AM #162424The idea Roberto is that an average is used only as a filter to decide whether to allow long or to allow short trades. If it works as a filter then we should see more up price movement when above it and more down price movement when below it. So if we check average up movement per candle when our filter is true then we can see if the filter is actually likely to add anything to a strategies performance or even perhaps subtract from potential performance.
My tester lets us purely compare different averages without the added curve fit of other conditions of entry such as RSI etc.
02/23/2021 at 11:54 AM #162428Yes, you are right Vonasi.
02/23/2021 at 1:31 PM #16243202/23/2021 at 3:41 PM #162450Well facts are facts. It is possible to add an average filter to a strategy and that filter mean that we are long on a market or short on a market during periods that statistically would have in the past given us an advantage (i.e more upward or downward pips per candle than the norm).
What I think is also interesting in the small amount of testing that I have done is how useless comparing price to an average is compared to using a fast average and a slow average.
Also pretty much all the time simple moving average, exponential and weighted averages are pretty useless as a filter whereas Hull and zero lag seem to fair much better.
No average filter will stop you from trading in a market when that market is going to lose you money.
So until I test further I would say that there is a place for averages in trading but I think it is limited.
1 user thanked author for this post.
02/23/2021 at 3:52 PM #16245302/23/2021 at 4:10 PM #162457I tested this code on Dax, Daily TF, using 200K units.
You can see, from attached pic, that pips in favor of the position of price (compared to Sma200) are always more than adverse pips:
123456789101112131415161718192021222324252627282930Defparam DrawOnLastBarOnly = TRUEONCE AboveBULL = 0ONCE AboveBEAR = 0ONCE BelowBULL = 0ONCE BelowBEAR = 0ONCE BullCount = 0ONCE BearCount = 0Bullish = close > openBearish = close < openIF BarIndex >= 200 ThenSma200 = average[200,0](close)If close > Sma200 thenBullCount = BullCount + 1AboveBULL = AboveBULL + (range * Bullish)AboveBEAR = AboveBEAR + (range * Bearish)ElseBearCount = BearCount + 1BelowBEAR = BelowBEAR + (range * Bearish)BelowBULL = BelowBULL + (range * Bullish)EndifAbull = round((AboveBULL / BullCount) / pipsize)Abear = round((AboveBEAR / BullCount) / pipsize)Bbull = round((BelowBULL / BearCount) / pipsize)Bbear = round((BelowBEAR / BearCount) / pipsize)DrawText("close ABOVE sma200 - bull pips #Abull#",BarIndex,high + (average[200,0](range) * 7.5))DrawText(".................................... - bear pips #Abear#",BarIndex,high + (average[200,0](range) * 6.0))DrawText("close BELOW sma200 - bull pips #Bbull#",BarIndex,high + (average[200,0](range) * 3.0))DrawText(".................................... - bear pips #Bbear#",BarIndex,high + (average[200,0](range) * 1.5))ENDIFReturn02/23/2021 at 4:57 PM #162464Not sure I understand why you are adding up the range of all red candles and the range of all green candles. Range size is just volatility and tells us nothing about direction.
In my code I check the previous candle is above the average as this is the candle that would be used to make our choice as to whether the filter is met or not. I then add up the values of the following candle.
02/23/2021 at 5:49 PM #162465do you use more seasonality as filter or just different indicators? just curious as to what you prefer over averages wich are so popular and used in almost every strategy posted here.
Seasonality in my mind is only of any use on some commodities – especially those that are seasonal in real life such as crops and pigs!
The best filter is the news. Donald Trump is President of the biggest economy in the world – get the hell out of the markets unless you love volatility. Donald Trump is no longer President of the biggest economy in the world – time to go long on indexes.
Averages are used in many strategies because they can be curve fitted so easily to make a strategy look better than it is.
02/23/2021 at 6:06 PM #16246702/23/2021 at 6:57 PM #162472Not sure I understand why you are adding up the range of all red candles and the range of all green candles. Range size is just volatility and tells us nothing about direction.
Because strategies are supposed to earn pips, so I think knowing that when price is ABOVE sma200 you may gain more pips when there’s a bullish candle rather than a bearish one…. may be of some interest (the other way round when price is BELOW sma200).
02/23/2021 at 7:04 PM #162473OK Roberto – I guess there is some logic in that but in the real world we can’t trade that range unless we are really very good and can get in at the low and out at the high on every candle. Perhaps comparing the ratio between high and open and low and open for candles above and below the average would tell us more.
-
AuthorPosts