NexusFi: Find Your Edge


Home Menu

 





Plot() with timer


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one ratfink with 5 posts (8 thanks)
    2. looks_two ToMerK with 4 posts (3 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 bobwest with 1 posts (0 thanks)
    1. trending_up 5,078 views
    2. thumb_up 11 thanks given
    3. group 1 followers
    1. forum 10 posts
    2. attach_file 0 attachments




 
Search this Thread

Plot() with timer

  #1 (permalink)
 ToMerK 
Tel Aviv Israel
 
Experience: Beginner
Platform: NinjaTrader
Broker: CQG
Trading: Futures
Posts: 21 since Feb 2015
Thanks Given: 30
Thanks Received: 13

Hi all,
After reading that the refreshing frequency of the drawn objects depends on a few events and the chart properties Display Update Interval I came across the option to override the Plot() method and calling it with a timer iterval.

I am trying to call the Plot() method as overridden in costumePlotSample indicator, that comes with NT7, but one thing I do not understand, how do I call the it from the timer event? Plot() didn't work because it needs 4 parameters.

How should I call Plot?

I would also appreciate it if you can tell me how the refresh will work after I use a 100ms interval. Will Plot() be called again from other events?

 
Code
        protected override void OnBarUpdate()
        {
			if (!initTimer && !Historical)
			{
				myTimerClock.Tick += new EventHandler(DoTime);
				myTimerClock.Interval = 100;
				myTimerClock.Start();
							
				initTimer    = true;
			}			
        }
        #region Timer Methods
	private void OnTimerTick(object sender, EventArgs e)
	{
		TriggerCustomEvent(UpdateTime, 0, myTimerClock.Interval);
	}

	private void DoTime(Object myObject, EventArgs myEventArgs)
	{
		TriggerCustomEvent(UpdateTime, 0, myTimerClock.Interval);
	}		

	private void UpdateTime(object state)
	{
		Plot();
		//ChartControl.Refresh();
	}
        #endregion

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
ZombieSqueeze
Platforms and Indicators
Request for MACD with option to use different MAs for fa …
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
67 thanks
NexusFi site changelog and issues/problem reporting
48 thanks
Battlestations: Show us your trading desks!
43 thanks
GFIs1 1 DAX trade per day journal
32 thanks
What percentage per day is possible? [Poll]
31 thanks

  #3 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425



ToMerK View Post
How should I call Plot?

I would also appreciate it if you can tell me how the refresh will work after I use a 100ms interval. Will Plot() be called again from other events?

In a nutshell you don't, and you don't want to be doing that anyway, trust me I'm a doctor.

The Plot parameters are generated with a validated graphics context from system update and paint events, you can't store or generate them yourself and there is no need to.

The way to change Plot frequency is in the Chart Properties, much less than 400ms is pointless as you are not going to see it anyway.

It will always get called by other events in any case, usually when price/values have moved or objects have been drawn and it's longer than the last time interval for display update.

Plot will always get called if there is a visible change required on the screen, you don't need to attempt a redirect or build a new refresh approach.

You can however call ChartControl.Refresh() if you absolutely want to create guaranteed screen paints independent of price moves, for example if you are showing a bar timer or such like. I do this myself at certain times in a couple of charts with a one second timer.

NB For simple things I find using Windows.Forms.Timers easier as they are running synchronously in the main event loop anyway, less accurate but less to handle.

Cheers

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
The following 2 users say Thank You to ratfink for this post:
  #4 (permalink)
 ToMerK 
Tel Aviv Israel
 
Experience: Beginner
Platform: NinjaTrader
Broker: CQG
Trading: Futures
Posts: 21 since Feb 2015
Thanks Given: 30
Thanks Received: 13

Thanks for the quick reply!

The problem I had before was that I used Draw commands in OnMarketData events that were updated only once in a few seconds even though my display update interval was set to 0.1 seconds. I did output to the data as well to the output window and saw that I have many events within this interval.

Doesn't this contradicts what you said that any change will be plotted as it arrives?

And another question, what is the difference between the Invalidate method to the refresh?

Started this thread Reply With Quote
The following user says Thank You to ToMerK for this post:
  #5 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425


ToMerK View Post
Thanks for the quick reply!

The problem I had before was that I used Draw commands in OnMarketData events that were updated only once in a few seconds even though my display update interval was set to 0.1 seconds. I did output to the data as well to the output window and saw that I have many events within this interval.

Doesn't this contradicts what you said that any change will be plotted as it arrives?

And another question, what is the difference between the Invalidate method to the refresh?

The changes will get output on your display update interval if price has moved, they may not become visible otherwise unless you have called Invalidate or Refresh. Normally I only draw using NT routines in OnBarUpdate or use low level graphics calls in Plot. I do use OnMarketData but have not used graphics from inside there so can't comment on that.

Little difference between Invalidate and Refresh, the former generates a queued paint event until all current processing is done then the Paint event will trigger, Refresh just triggers a Paint immediately.

Also in my experience the TriggerCustomEvent route is only necessary if NT bar indexes and such like are involved.

Cheers

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
The following user says Thank You to ratfink for this post:
  #6 (permalink)
 ToMerK 
Tel Aviv Israel
 
Experience: Beginner
Platform: NinjaTrader
Broker: CQG
Trading: Futures
Posts: 21 since Feb 2015
Thanks Given: 30
Thanks Received: 13

Is there a real difference between drawing in OnMarketDepth last events and in OnBarUpdate (if CalculateOnBarClose = false)?

Started this thread Reply With Quote
The following user says Thank You to ToMerK for this post:
  #7 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425


ToMerK View Post
Is there a real difference between drawing in OnMarketDepth last events and in OnBarUpdate (if CalculateOnBarClose = false)?

I don't know, I've just never tried it. I agree it is likely to be similar (and is in the same event loop) but you can get lots of OMD events (e.g. bid/ask/vol) without getting a price-moving OBU event.

Maybe email NT support to get clarification if you really need it. Alternatively you can just process data in OMD into a saved/active area and output NT gfx from OMD or a timer routine (adding an Invalidate or Refresh as needed if you are drawing something that can change without price or other indicator Values changing), or use low level gfx from Plot.

It's always worth thinking about when CPU work actually needs to be done for the brain to see something useful. More thinking along delayed processing lines would have lead to a lot less inefficient indicator code than NT7 has been typically been saddled with.

Cheers

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
The following user says Thank You to ratfink for this post:
  #8 (permalink)
 ToMerK 
Tel Aviv Israel
 
Experience: Beginner
Platform: NinjaTrader
Broker: CQG
Trading: Futures
Posts: 21 since Feb 2015
Thanks Given: 30
Thanks Received: 13

Thanks again!

A few more questions about the chartControl. The intellisense gives me many things to work with, is there a guide for this that someone wrote? If not can you please specify what are the methods you work with? And what is the chartPanel within the chartControl?

Started this thread Reply With Quote
The following user says Thank You to ToMerK for this post:
  #9 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425


ToMerK View Post
Thanks again!

A few more questions about the chartControl. The intellisense gives me many things to work with, is there a guide for this that someone wrote? If not can you please specify what are the methods you work with? And what is the chartPanel within the chartControl?

No guides available as it's all unsupported NT stuff although it does tend to behave fairly well. Best approach is to learn a bit about general Windows Forms Controls, fastest way is just to Google "C# <subject>". You will also find lots of existing code on futures.io (formerly BMT) and in the NT support forum areas.

The ChartPanel is the graphics subpane of the Window, so without borders.

Best other learning route is simple Prints on the variables, I have not found use for that many of the methods and prefer to avoid close coupled hooks if I can.

Final caveat is that NT8 uses a completely different foundation layer (WPF) instead of Forms, so maybe don't invest too heavily unless you are happy to do so. Personally I think Forms and NT7 will be still around for a long time but it will be interesting to see if the next generation does have better documented APIs.

Cheers

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
The following 2 users say Thank You to ratfink for this post:
  #10 (permalink)
 
bobwest's Avatar
 bobwest 
Western Florida
Site Moderator
 
Experience: Advanced
Platform: Sierra Chart
Trading: ES, YM
Frequency: Several times daily
Duration: Minutes
Posts: 8,157 since Jan 2013
Thanks Given: 57,292
Thanks Received: 26,253



ratfink View Post
Final caveat is that NT8 uses a completely different foundation layer (WPF) instead of Forms, so maybe don't invest too heavily unless you are happy to do so. Personally I think Forms and NT7 will be still around for a long time but it will be interesting to see if the next generation does have better documented APIs.

Won't it? Couldn't have much worse. (API documentation, that is.)

I don't want to barge in, but with NT8 presumably getting near to its release (anyone have any word on that??), I was going to say that getting too deeply into NT7, or perhaps doing very much with it at all, except purely surface stuff, may not be a great idea.

That said, I have stayed away from the NT8 beta project, not wanting more complication right now, and so I don't really know how NT8 will turn out. Are you in it, or do you otherwise have an idea?

Bob.

Reply With Quote





Last Updated on July 19, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts