//Run this every 5 minutes void TimerElapsed(object sender, ElapsedEventArgs e) { FetchDataAsync(); } protected override void OnStateChange() { Print(State); if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "TestProj"; Calculate = Calculate.OnPriceChange; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = false; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; IsSuspendedWhileInactive = false; AddPlot(new Stroke(Brushes.Black), PlotStyle.Bar, "Plot1"); } else if (State == State.Configure){ FetchDataAsync(); //fetch the data the first time then timer takes over every 5mins System.Timers.Timer t = new System.Timers.Timer(); t.Interval = 50000; // Every 5 mins t.AutoReset = true; t.Elapsed += new ElapsedEventHandler(TimerElapsed); t.Start(); } }
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!
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
NinjaTrader
Fetching Data from Indicator
Collapse
X
-
Fetching Data from Indicator
My Indicator fetches some data from a web resource every 5 minutes. I have created a simple timer that calls an Asynchronous task. My question is, I don't know where to dispose of the timer or write this so it automatically disposes. Here is my Code:
Code:Last edited by swcooke; 01-04-2020, 11:27 PM.Tags: None
-
Hello swcooke,
bltdavid is giving a good suggestion.
Below is a link to an example of timer.
https://ninjatrader.com/support/forum/forum/ninjatrader-8/indicator-development/95391-nt8-sometimes-runs-onstatechange-termination-during-onbarupdate?p=777185#post777185Chelsea B.NinjaTrader Customer Service
- Likes 1
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by sastrades, 05-10-2024, 09:59 AM
|
3 responses
54 views
0 likes
|
Last Post
by rc5781
Today, 05:08 PM
|
||
Started by guyonabuffalo, Yesterday, 10:01 PM
|
2 responses
18 views
0 likes
|
Last Post Today, 04:52 PM | ||
Started by thumper57, Yesterday, 04:30 PM
|
5 responses
15 views
0 likes
|
Last Post
by thumper57
Today, 04:39 PM
|
||
Started by reynoldsn, 05-10-2024, 07:04 PM
|
5 responses
27 views
0 likes
|
Last Post Today, 04:36 PM | ||
Started by llanqui, Today, 11:10 AM
|
1 response
16 views
0 likes
|
Last Post Today, 04:02 PM |
Comment