Reset indicator daily
Author: josephhfry
Creation Date: 5/28/2020 9:52 PM
profile picture

josephhfry

#1
I have a couple of intraday strategies that I have been testing that seem to perform well on the first day of the backtest period, but don't do so well on subsequent days due to the way that the indicators I use respond to wild overnight price fluctuations.

Is there a way to "reset" and indicator so it doesn't use any of the trends from the previous day? I know with many indicators you can just skip X bars... for example you can skip the SMA "period" to ensure that the values are inline with the data for the day, but other indicators like Parabolic2, don't have a "period"

For example, here is what Parabolic2 (0.02,0.02,0.1) looks like on 3/4/2020 on TZA when it carries over from the previous day:


While here is what it looks like if I start the chart on that same day:



The previous day's data completely changes how the indicator behaves, and impacts my back-testing as a result (since in reality I will be starting with fresh daily data when I go live).

This is just one example, but there have been numerous other indicators I have tried that caused me similar frustrations. Is there a simple way to "reset" an indicator every day?
profile picture

josephhfry

#2
Sorry to reply to myself, the example I used may not be ideal, since it appears that it stabilizes after a while (at 0.02, 0.02, 0.02 it takes almost 50 bars though); I could just wait that long to use the indicator. However it seems to still have some value before its stable.

The question still stands as there are other indicators that would be easier to work with if they could be reset. OBV comes to mind (its nice just to see if its positive or negative at a point it time without having to do any extra work to "zero" it).
profile picture

Eugene

#3
Sounds like you're trying to avoid the effect of a gap open on your indicator. Well, most any indicator requires seed data to build its first value. The .Value method, found in some indicators, woudn't work here either. I think it'd take you some considerable modification of the indicator's logic like Anchored VWAP which starts from certain date. If you're interested in a DIY and completely unsupported project then check out post #11 here: Anchored VWAP. But in the end it arrives at what I propose below, with much more effort from you. Let alone that if you load not enough seed bars for your strategy which starts fresh every day, you will end up with an unstable indicator value with all that it implies (see the WealthScript Programming Guide > Indicators > Stability of Indicators).

For simplicity's sake, let's put things in a different perspective. Don't start taking trades in your strategy until the indicator's "whip" is reflected in today's data. Determine the period it takes it for your indicator to account for any gap and stabilize, and only then take new entries.

As an alternative approach, choose only indicators responsive enough e.g. zero-lag indicators by Ehlers in TASCIndicators, reactive KAMA vs. sluggish SMA etc.
profile picture

josephhfry

#4
Thanks Eugene, that Anchored VWAP example makes perfect sense... not quite as easy as I'd hoped it would be, but certainly doable.

I realize that delaying trades until the data stabilizes, or choosing other indicators is the preferred method, and will/do use those options when appropriate for my strategies.... however there have been several instances where doing so wasn't practical and I gave up on a strategy as a result.

In the example I used above, I had a strategy working pretty well using Parabolic2 with some unusual values (0.02, 0.02, 0.01)... definitely not the way the indicator is intended to be used, but it gave me the desired result (identified when I was in long slow 'trends' that ADX couldn't see); however on days where there was a particularly large overnight change it wouldn't stabilize until after noon.

Anyway... thanks again!
profile picture

Eugene

#5
Glad I could be of assistance!
profile picture

josephhfry

#6
Eugene,

I think I spoke too soon. I am trying to borrow from the avwap post you provided realized that what I want to do is not as straight forward as I thought.

Correct me if I am wrong, but if I want to create a series containing the parabolic2 value that doesn't continue from the previous day, I would need calculate it manually on each bar and load the results into a custom dataseries?

Is there any way to create a new Bars object that only includes a subset of the bars (just bars > Bars.IntradayBarNumber(bar)) loaded manually in my execution loop. I thought maybe I could use setContext or getExternalSymbol to load another set of bars for the same stock, but of course they don't let you specify a date range.

And after studying how the parabolic SAR is calculated, there really isn't a stability issue doing what i suggest. I would argue that carrying it over from day to day is actually less accurate when used as an intraday indicator due to the way it uses a max acceleration factor to limit how fast it is allowed to move; large overnight delta + a low max AF can cause it to be inaccurate for a very long time, and the length of time varies based on the size of the overnight delta so it's impossible to predict when it is safe to trust the indicator.

Any ideas on how I can get around manually calculating it?
profile picture

josephhfry

#7
Sorry... responding to myself again; typing that message made me think and do some quick queries.

Based on some other posts:
https://www.wealth-lab.com/Forum/Posts/Trading-a-new-Bars-Object-32282
https://www.wealth-lab.com/Forum/Posts/Synthetic-Symbol-to-Bars-Object-SaveToFile-31576
https://www.wealth-lab.com/Forum/Posts/How-to-Clear-Bars-Object-38017

It looks like I could create a synthetic bars object... clear it at the start of the day, load it with OHLC data on each new bar, and finally use that to create a parabolic2 series on the daily data only. Finally, just copy this series values up to the custom series for plotting/backtesting.

Any flaw in this idea?
profile picture

josephhfry

#8
So... I figured I would give it a shot while I await your response and I think I am close. Gonna sleep on it and revisit in the AM.

Unfortunately, the indicator I apply to my custom Bars object is not getting calculated as I add bars.

I wonder if I am completely misunderstanding how indicators process. It was my assumption that every time a bar gets added, the indicator would be calculated? Is there a command I need to run after I add a bar to the Bars object to make the indicator calculate up to that point, or do I have to populate the object completely before I add the indicator?

I could probably do the latter using nested loops, but I don't understand how that would work with streaming data.

Would appreciate any clarification you can provide that might help me better understand how series indicators are processed so I can get this working. Here is what I have so far:

CODE:
Please log in to see this code.


profile picture

Eugene

#9
Hi Joseph,

Perhaps the most overlooked phrase in my replies on this forum is this: If you're interested in a DIY and completely unsupported project... ;) But I meant exactly what I said. Please dont count on me on this.

Furthermore, Bars.Add is an undocumented WealthScript method (see QuickRef) that is used by static data providers. You're employing it on your own (unsupported). But this doesn't seem to me to be the correct way to do it. The correct approach might be to create a custom Parabolic derived indicator which implements the Value method to return a value "on the fly" for a particular bar number. Use this as reference, there's a code example: Creating an Indicator Library in Wealth-Lab Pro > Providing a Static Value Method.

Additionally, you might want to download the source code of TASCIndicators library and find indicators implementing this method and use it as example:
CODE:
Please log in to see this code.


I'm not the best man for the job (no experience with the Value method). Good luck with your venture!
profile picture

josephhfry

#10
Eugene,

I completely understand that you cannot help me develop the solution. My question is far more general:

When applying an indicator using indicator.series() , when is that indicator calculated, how is recalculation triggered upon receipt of a new bar during streaming?

I made some changes to my code, and they work great, except it waits until the last bar of the day to apply the indicator so that the series is complete and it can calculate the whole thing. I simply want to know how to re-calculate the indicator when the underlying series changes.

For your reference here is the code that simulates what I want... it waits till the last bar of the day to create the indicator, then loops over all the bars that day, and copies the indicator values to the custom series that I am plotting. This is good enough for backtesting, but I'd like to make it work for streaming data as well.

CODE:
Please log in to see this code.
profile picture

Eugene

#11
QUOTE:
When applying an indicator using indicator.series() , when is that indicator calculated, how is recalculation triggered upon receipt of a new bar during streaming?

As per the FAQ: Is it necessary to have access to intra-bar tick data to daytrade with Wealth-Lab?
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).