Adaptive Average in higher timeframes
Forums › ProRealTime English forum › ProOrder support › Adaptive Average in higher timeframes
- This topic has 15 replies, 4 voices, and was last updated 3 months ago by withoutwings.
-
-
09/05/2024 at 5:15 PM #237176
I thought I was going crazy, but it would appear that the AdaptiveAverage function just returns the value
Close
if used in higher timeframes! However it works as expected if used in the Default timeframe section in the same script (i.e. returning the Adaptive Average calculated over the last x bars’ closing value, according to the parameters specified).Can someone please test and verify that they see the same behaviour? If so, then consider this a bug report. Thanks.
Using PRT v12.0 (via IG).
09/05/2024 at 5:57 PM #237185This code works like a charm to me. I used two DAX charts, 1-hour + Daily (as you can see from attached pic):
123456Timeframe(Daily,default)//UpdateOnClose)myAdaptiveAverageD = AdaptiveAverage[10,2,30](close)//Timeframe(default)myAdaptiveAverage = AdaptiveAverage[10,2,30](close)RETURN myAdaptiveAverageD AS "Daily avg",myAdaptiveAverage AS "Default avg"The 1-hour adaptive average returns the same values on both the chart and the indicator.
The Daily adaptive average returns almost the same values on both the chart and the indicator, the tiny difference (just a few decimals) is probably due to a slightly different timing when updating the ticks on the charts.
09/05/2024 at 6:51 PM #237188My apologies, I neglected to mention that this was in ProBackTest and using GRAPH to output it.
Also I was using UpdateOnClose both for 1 Minute and Default (which was running on a 10 Seconds chart).
09/06/2024 at 8:59 AM #237205Here’s an example of what I mean, this being a backtest run on a 10-second chart:
Adaptive Average HTF = Close?1234567891011121314151617181920TIMEFRAME(1 Minute, UPDATEONCLOSE)// ** Adaptive MA **//kama1Slow = AdaptiveAverage[65,2,30](close)kama1Fast = AdaptiveAverage[26,2,30](Close)//kama1Bull = kama1Fast > kama1Slow//kama1Bear = kama1Fast < kama1Slow//GRAPH kama1Bull COLOURED(0,255,0) // Green//GRAPH kama1Bear COLOURED(255,0,0) // RedGRAPH (kama1Fast = Close) COLOURED(255,0,0) // RedTIMEFRAME(10seconds, UPDATEONCLOSE)// ** Adaptive MA **//kama10sSlow = AdaptiveAverage[65,2,30](Close)kama10sFast = AdaptiveAverage[26,2,30](Close)//kama10sBull = kama10sFast > kama10sSlow//kama10sBear = kama10sFast < kama10sSlow//GRAPH kama10sBull//GRAPH -kama10sBearGRAPH (kama10sFast = Close) COLOURED(0,255,0) // GreenAttached is a screenshot with the output of both GRAPH functions for that simple logic check. If it’s ‘1’ it (incorrectly) equals
Close
, and the one that is outputting ‘0’ is functioning correctly.Some other interesting observations:
- Swapping AdaptiveAverage for ExponentialAverage – or any other type of average that I can think of – results in both functioning correctly (output a constant ‘0’ for both).
- Changing the 1 minute timeframe to Default instead of UPDATEONCLOSE also results in it functioning correctly (outputting a constant ‘0’ in red).
I think what I’ve stumbled upon is a corner case which triggers a bug in the AdaptiveAverage function. Unfortunately for me I require all of my higher timeframe code to be using UPDATEONCLOSE.
09/06/2024 at 4:43 PM #237233Hi,
If you think that “Graph (kama1Fast = Close) Coloured(255,0,0)” is a simple logical check, that’s not true…
The only thing that happens here is that you equate “kama1Fast” with the “Close” which has no meaning whatsoever…
I don’t know what you want exactly, but the “adaptive averages” give the right results and if you want to show these results in a backtest, you can use:
TIMEFRAME(1 Minute, UPDATEONCLOSE)
kama1Fast = AdaptiveAverage[26,2,30](Close)
GRAPH (kama1Fast) COLOURED(255,0,0) // Red
TIMEFRAME(10seconds, UPDATEONCLOSE)
kama10sFast = AdaptiveAverage[26,2,30](Close)
GRAPH (kama10sFast) COLOURED(0,255,0) // Green
09/06/2024 at 4:55 PM #237234If you think that “Graph (kama1Fast = Close) Coloured(255,0,0)” is a simple logical check, that’s not true…
Hi, I think you’ve misunderstood: that post was for debugging purposes. So what you see above is just debug code – to prove what is going on! (I’m a software engineer, so I am used to doing this kind of thing all the time.)
As you can see from the screenshot, the constant result of ‘1’ in red in the GRAPH output shows that there is likely a bug in the underlying implementation of
AdaptiveAverage
.09/06/2024 at 5:16 PM #23723709/06/2024 at 5:24 PM #237238Perhaps it will help if I take you through the steps I’ve been through myself:
- I initially wrote functional code that had “meaning”
- I observed that the direct output of that AdaptiveAverage call in the higher timeframe looked very much like it was just the Close value of each higher timeframe (1min) candle
- I changed the GRAPH code to a simple debug-style Boolean equation to prove my hypothesis
- I showed the evidence here that it indeed does returns ‘true’ (‘1’) for each 1min candle, which it shouldn’t ever do
- I’m after someone to verify this bug so that it can be fixed in the next release of PRT
Is that clearer now?
09/06/2024 at 5:51 PM #237240- Okay
- No, the “AdaptiveAverage” in the higher timeframe doesn’t look like the “Close” at all… (see screenshot)
- No, it’s not a (simple) Boolean debug test… (kama1Fast=Close is not a test as you should know as a software engineer)
A Boolean test might look like this:
If kama1Fast = Close then
Output=1
Else
Output=0
EndIf
- See 3.
- There is no “bug”, the Adaptive Averages work as expected…
09/06/2024 at 6:04 PM #237242JS, I’m sorry but I actually know what I’m talking about re how to debug such things.
(kama1Fast=Close)
is indeed a Boolean test; inside a parenthesis it becomes a single statement which is evaluated before it is passed to the GRAPH function as a parameter. You can take shortcuts like that in most programming languages.In my example you can even see the differences between the two lines from the two timeframes. It literally proves my point, very clearly for anyone with a bit of understanding.
And your screenshot is meaningless without code. Did you use a backtest script and the GRAPH code, like I did?
No actually please stop replying so this thread doesn’t get any more muddied by it. This was supposed to be a simple, clear-cut bug report for the eyes of a PRT rep/moderator!
09/06/2024 at 6:19 PM #237246Okay, let’s see what the moderator, @robertogozzi, has to say about it…
09/06/2024 at 11:19 PM #23726509/07/2024 at 6:50 AM #237267Hi there,
Of course your test shows your “right”. Why it is so (wrong) is something else. My reasoning (FWIW) :
UpdateOnClose vs Default may not give the AdaptiveAverage sufficient data to make any proper calculation. I did not test this (nor ran your code), but it feels logic to me. This includes any other (like ExponentialAverage) does working, which would be logic because it will be able to use the last data on its own, which AdaptiveAverage will (?) not.
Again, this is by looking at your (debug) code, and things make sense to me. But :
You should also apply JS’ test with the If / Else on Kama1Fast = Close; This is a little effort. Why do I say this ? because people like JS may check their statements before saying something. Bute merely :
(kama1Fast=Close) is indeed a Boolean test; inside a parenthesis it becomes a single statement which is evaluated before it is passed to the GRAPH function as a parameter. You can take shortcuts like that in most programming languages.
Here you may make a mistake because ProBuilder or whatever it’s called is hardly a programming language; it is the product of people who apply “intelligence” in the parser which fails in a 1000 places (ask me for real and I may come up with 20 examples). Graph is a very first command to fail (ask me about that and I need 2 A4 pages to lay it all out). Anyway, I too would attest that your “=” would be a proper boolean test, but I would try the If/Else too.
Of course you come up with this topic for a reason, and I am of the stance that I believe people first. For me to prove that they may be wrong. And thus so far you are correct. 🙂
If the If/Else still gives you the same result, try to move the Graph outside of all TimeFrame command. Thus, reset it to the fastest TF at the bottom of your program and then do the Graph again (after possible adjustment because of moving it out of the TF commands). You may be surprised on the results (yes, Graph s*cks).
You may try to use Print too (Print is decent, says me).
Still no dice ? then try to “fit” the two TF’s within each other by different factors. Thus, change the 1 minute to 10 minutes and/or change the 10 second to 1 second or 20 seconds etc. You will start to learn what’s going on really and possibly may even come to the conclusion that your assumptions on how to use the PRT programming language must be adjusted a little (I am thinking of your real code and where this could fail, you working on the proof in the same direction – which is human).Let’s for fun bet on a nice beer that in the end you’ll say “ahhhh, like that !”. It happened to me a 100 times, just because I assume PRT to have/be a normal programming language which makes it a killing job to “live in”. People without the experience won’t notice. People with the experience will hate it. Or in the end, get used to it.
I am used to it. 🙂09/07/2024 at 11:41 AM #237275My apologies, I neglected to mention that this was in ProBackTest and using GRAPH to output it.
Also I was using UpdateOnClose both for 1 Minute and Default (which was running on a 10 Seconds chart).
I moved the topic to ProOrder support.
09/07/2024 at 1:41 PM #237288My apologies, I neglected to mention that this was in ProBackTest and using GRAPH to output it.
Also I was using UpdateOnClose both for 1 Minute and Default (which was running on a 10 Seconds chart).
I moved the topic to ProOrder support.
Oops, thanks – as you can see I’m new to these forums (but not new to PRT, which I’ve been using for many years now)…
-
AuthorPosts
Find exclusive trading pro-tools on