Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Plots won't update or will only consider the bars on screen

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Plots won't update or will only consider the bars on screen

    Hello,

    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,

    #2
    Hello Convert,

    Thank you for the post.

    I reviewed the details provided however this specifically does not tell me what may be happening in your tests only that the problem likely revolves around either the calculation being done or OnRender.

    What I could suggest to move forward from this point would be to make a reduced test that we can work together on here on the forum. I won't necessarily be able to help with what you explained for the calculations but I can try to advise best practice surrounding your rendering of the calculated data.

    Can you provide a simple example of how you are currently rendering the data in the situation that is working best? It looks like the one where you are calculating inside of OnRender works but then fails when scaling. That is likely the most complete/working sample so I would suggest to try and make an example out of how you are trying to render from that file so we can further explore that. From the given details it sounds like potentially the bar indexes you are referencing are mixed up causing the scaling to further confuse the rendering.



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by llanqui, Today, 08:32 AM
    1 response
    5 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by lollers, Yesterday, 03:26 AM
    1 response
    51 views
    0 likes
    Last Post lollers
    by lollers
     
    Started by Salahinho99, 05-05-2024, 04:13 AM
    7 responses
    59 views
    0 likes
    Last Post Salahinho99  
    Started by knighty6508, 05-10-2024, 01:20 AM
    4 responses
    29 views
    0 likes
    Last Post knighty6508  
    Started by OllieFeraher, 05-09-2024, 11:14 AM
    6 responses
    19 views
    0 likes
    Last Post OllieFeraher  
    Working...
    X