I have two working indicators that are modified versions of a single NT8 out-of-the box indicator. The problem is that they only work under certain conditions. They both do quite literally the exact same thing on screen when working properly, just go about it different ways. The gist of the mods are just some calculations that end up changing the color of the plot given certain criteria.
The first time I tried it, I did everything inside OnRender(), but that failed spectacularly. The help guide recommended doing all the math outside of OnRender(), so this is what I came up with the second time around:
(Please forgive me. Since all my programming experience comes from required introductory programming classes from several years ago, I have forgotten the technical names of some of what's below)
In OnRender(), a previously created list (copyList) is used to duplicate a portion of the information stored in a dictionary that is populated in OnMarketData()
- copylist is a private list that is created with the other private variables that are not part of a specific method
copyList is then sorted and passed into custom internal class (Calc()) using a foreach loop
Calc() has 2 methods, calc1 and calc 2.
-In calc1, another temporary list (tempList) is populated using the args passed into Calc(). tempList and some other simple arithmetic is needed for calc2.
-In calc2, tempList is simply looped through with some calculations performed
-These two methods update public variables within Calc() for use elsewhere
So to recap, OnRender()
1. copies/sorts a dict. into copyList
2. creates a new Calc() object which copyList is passed into
3. Calc() does math
4. public Calc() variables then used later in OnRender to determine whether certain parts of the plot change color.
The problem with this version is that while it does everything correctly on first render, it refuses to automatically update the plot as new data is made available. I suspect the problem lies with calling Calc() inside OnRender(), but I'm not sure.
After not knowing where to go with the last version, I wrote another that actually does all the math and everything else inside OnRender(), but prior to being drawn which was the problem on my first attempt. This final version also works exactly as expected and even auto updates, unlike the previous. However, if I zoom in on the price axis, it starts ignoring data as if the bars above and below what's currently visible on the chart do not exist at all. This is even more perplexing, but I imagine it has something to do with the way OnRender() behaves that I'm not aware of. Any suggestions here would be greatly appreciated.
Thanks again for your help,
Comment