![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jan 2008
Location: Madrid, Spain
Posts: 231
Thanks: 2
Thanked 0 times in 0 posts
|
Greetings,
I am doing an indicator for displaying the mouse coordinates in MouseMove event. The indicator calls the method "chart_MouseMove" when the mouse is moved but the text isn't updated. Is there any way for calling to Plot method ? Now the indicator works fine only when clickmouse or Alt+Tab windows or key press. ( I know that this doubt is beyond the scope of what you provide support for but I would be very grateful if you could help me ). Thanks very much. protectedoverridevoid OnBarUpdate() { if ((ChartControl != null) && (!_initMouseEvents)) { this.ChartControl.ChartPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove); _initMouseEvents = true; } } publicoverridevoid Plot(Graphics graphics, Rectangle bounds, double min, double max) { _boundsChart = bounds; _minChartPrice = min; _maxChartPrice = max; graphics.DrawString( "Y: " + _mouseOffset, fontTexto, brushTexto, 10, 280 ); } privatevoid chart_MouseMove(object sender, MouseEventArgs e) { if (ChartControl != null) { double price1 = ConvertYtoPrice ( e.Y ); _mouseOffset = price1 ; } } privatedouble ConvertYtoPrice (int i) { int _tickLength=0; if (TickSize < 1) _tickLength = TickSize.ToString ().Length-2; double chartscale = Math.Abs (_maxChartPrice - _minChartPrice); double boundAreaScale = _boundsChart.Bottom - _boundsChart.Y ; double ratio = (double)(chartscale)/ boundAreaScale ; double chartPrice = Math.Round ( (_minChartPrice ) + ((_boundsChart.Bottom -i) * ratio), _tickLength); return chartPrice; } |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Sorry, but as you already figured this clearly is beyond the scope what we provide support for, since coding at that level easily could screw up NT if you don't know exactly what you are doing.
As last resort you could contact a certified NinjaScript consultant: http://www.ninjatrader.com/webnew/pa...injaScript.htm
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
Hi cls71
Did you manage to make any progress with your code. I am also trying to capture the mouse/crosshair location and use this within an indicator. Basically my indicator is a drawing tool that can be used to measure the ticks between 2 points. The idea is to alt-click once at one point on the chart, then alt-click again on the 2nd point. A line should then appear between the two points as well as the distance between the two points. What I am missing is the X and Y coordinates of the two alt-mouse clicks. I have attached my code for you to have a look at and any suggestions/help would be much appreciated. The sample pic shows what I am trying to achieve. Currently my code has the X and Y coordinates fillled in, but I would like to use what you have done, if it works, and use chart clicked coordinates in my code. |
|
|
|
|
|
#4 | |
|
Senior Member
Join Date: Feb 2009
Posts: 285
Thanks: 2
Thanked 54 times in 41 posts
|
Quote:
http://www.ninjatrader-support2.com/...catid=3&id=245 |
|
|
|
|
|
|
#5 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
Hi bukkan,
Thanks for the info, I see that converting the xpos to barcount is fairly straight forward, however I am a little stumped on how to do the ypos - how can I determine the ypos and then convert it to price? As this is not always from a high to a low, I need to calc and convert the ypos too. |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Feb 2009
Posts: 285
Thanks: 2
Thanked 54 times in 41 posts
|
the said indi does not calculates the price scale as it is redundant for its need.
anyway, the bars itself contains the price value. isnt it. like Close[barcount] will give you the closing price of that bar. now you got to calculate a range and then some more calculation beween the pixel pts (where the mouse was clicked) and you will find what you need. |
|
|
|
|
|
#7 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
Thx again bukkan, will try and figure out how to do the range vertically. Have only just started programming this year, so this will be a challenge.
I see that cls71 has some code that converts Y to price so will try and modify that to suit my needs, if I can figure it out.
Last edited by traderT; 12-28-2009 at 06:56 AM.
|
|
|
|
|
|
#8 |
|
Member
Join Date: Jun 2009
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
|
NinjaTrader is broken wrt/ asynchronous events like this - it does not leave the Bars collection in a valid state outside the OnBarUpdate method, so you cannot access the historical values of the indicator or its Input.
however, here's what I have for bar & price: PHP Code:
|
|
|
|
|
|
#9 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
Hi Piersh, thanks for the info. One thing that I am concerned about is the fact that the "double price" is not correct when I print it to the Output window. Is this working a designed or is the maths wrong?
|
|
|
|
|
|
#10 | |
|
Member
Join Date: Jun 2009
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
PHP Code:
|
|
|
|
|
|
|
#11 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
I just added price to _min and it come out right as well, but your way is better - thanks again.
|
|
|
|
|
|
#12 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
Is there a way to do the calculations only on a mouse up, rather than using mousemove? Or should I continue to use mousemove and just grab the x and y coordinates on a mouseup?
|
|
|
|
|
|
#13 |
|
Member
Join Date: Jun 2009
Posts: 41
Thanks: 0
Thanked 0 times in 0 posts
|
|
|
|
|
|
|
#14 |
|
Senior Member
Join Date: Mar 2008
Location: UK West Sussex
Posts: 667
Thanks: 10
Thanked 11 times in 8 posts
|
I modified your great code Bukkan just so that it switches on and off effectively.
Unfortunately this code breaks in NT7 and I can't work out why - I have the same problem with another indicator- it works on a single chart but if you add another chart on the same panel the barclick returns the wrong number !! Edit - the text still appears btw but it is shifted approx 2 bars to the left If someone could help me with this I would be immensely grateful as it's unsupported.
Last edited by Mindset; 12-29-2009 at 02:50 AM.
|
|
|
|
|
|
#15 | |
|
Senior Member
Join Date: Feb 2009
Posts: 285
Thanks: 2
Thanked 54 times in 41 posts
|
Quote:
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| event-driven methods? | mktrend | General Programming | 8 | 04-29-2008 06:17 AM |
| Order Event Warning | Moda1 | Miscellaneous Support | 4 | 02-14-2008 09:44 AM |
| Live Events - Seen After the Event | jstockman | Miscellaneous Support | 3 | 09-26-2007 04:37 PM |
| Strategy Start/Stop Event | Json | Strategy Development | 1 | 05-01-2007 03:55 AM |
| Chaining strategy and event | afifio | ATM Strategies (Discretionary Trading) | 6 | 06-26-2005 01:52 PM |