Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plot Series Historical Bars Erase, Clear, Reset... Example Code

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

    Plot Series Historical Bars Erase, Clear, Reset... Example Code

    I'm trying to erase or clear a previous plot when a new session starts, because the previous plot may have had a value of -9,000 and when the new plot starts at 0, the chart auto scale will make it difficult to view the newest plot values.

    Some topics in the forum have noted that you need to iterate through the series that is used to hold values for the plot, but i have not seen an example.

    I have written this code, and it seems to work correctly when tested on a playback connection.

    Code:
    // reset all previous values used in plot CountOfTrumpTweetsAgainstAmazon
    for( int seriesindex = 0; seriesindex < CountOfTrumpTweetsAgainstAmazon.Count; seriesindex++	)
    {	// reset the series value at this index pointer
    	CountOfTrumpTweetsAgainstAmazon[seriesindex] = 0.0;
    	Print("resetting series value at index " + seriesindex );
    }
    Please confirm this is the best practice, and there is no Series<T>.Clear() method which would be able to avoid the iteration through all bars in the historical series.


    The speed of this operation appears to be very fast when tested on a playback connection running at 1x speed, even though it is printing to the Ninjascript Output window at each bar index pointer as a debug test.

    Code:
    resetting series value at index 5417
    resetting series value at index 5418
    Please discuss if the speed of this reset would still be as fast when used in real-data data feed. I hypothesize it is simply a O(n) operation, and duration will depend upon the count of the number of bars in the series, the CPU speed and memory consumption, but it does not appear to be a bottleneck concern for me, since it is only done at the start of new session.

    #2
    Hello balltrader,

    Thank you for your note.

    There is no Series clear method and the loop you are using looks fine. There may be many ways to accomplish the same thing and would not be able to comment on what is best.

    Playback simulates real time and I would not expect a significant difference in the time it takes to run the loop.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    44 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    54 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    34 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    94 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    56 views
    0 likes
    Last Post PaulMohn  
    Working...
    X