NexusFi: Find Your Edge


Home Menu

 





Snapping Drawings to Nearest Tick


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Xav1029 with 5 posts (1 thanks)
    2. looks_two vvhg with 2 posts (2 thanks)
    3. looks_3 emun with 2 posts (1 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 4,248 views
    2. thumb_up 4 thanks given
    3. group 4 followers
    1. forum 10 posts
    2. attach_file 1 attachments




 
Search this Thread

Snapping Drawings to Nearest Tick

  #1 (permalink)
 
Xav1029's Avatar
 Xav1029 
Tampa, FL
 
Experience: Beginner
Platform: NinjaTrader, Sierra Chart
Broker: Mirus Futures/Zen-Fire
Trading: 6E, M6E, 6J
Posts: 1,375 since Dec 2011
Thanks Given: 1,452
Thanks Received: 3,377

Got an alert system I'm working on that sends alerts from SR lines. The indicator draws lines that can then be adjusted by the user. My question is when I am in adjust mode, how do I make sure that the lines I am adjusting get rounded to the nearest tick like the chart trader lines?

When the user clicks the draw/remove button, targets, stops, and SR lines are drawn or removed. When they get drawn, the indicator goes into adjust mode. While in adjust mode, all the levels are unlocked and can be moved by the user. When the user is moving these levels, I would like them to snap to rounded ticks like chart trader targets. Also, while the user is moving them, I would like the labels to be anchored to the lines so that they move with the lines in real time. Right now the values get snapped and the labels are moved once the user presses the set button.

Any ideas on how to do this? I was thinking to put it inside a timer, and round it 10x a second or something, but don't know if this would be the most efficient way to do it.



London Calling
Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Exit Strategy
NinjaTrader
Futures True Range Report
The Elite Circle
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
  #3 (permalink)
 vegasfoster 
las vegas
 
Experience: Intermediate
Platform: Sierra Chart
Broker: Velocity/IB
Trading: 6E
Posts: 1,145 since Feb 2010
Thanks Given: 304
Thanks Received: 844


Maybe make it so it rounds every mouse click? Then it will round as they drop it?

Reply With Quote
  #4 (permalink)
 
Xav1029's Avatar
 Xav1029 
Tampa, FL
 
Experience: Beginner
Platform: NinjaTrader, Sierra Chart
Broker: Mirus Futures/Zen-Fire
Trading: 6E, M6E, 6J
Posts: 1,375 since Dec 2011
Thanks Given: 1,452
Thanks Received: 3,377


vegasfoster View Post
Maybe make it so it rounds every mouse click? Then it will round as they drop it?

That is an option... I could run the timer, round, and move the labels as long as the left mouse button is being held. I will look into that option.

London Calling
Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #5 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824


Xav1029 View Post
That is an option... I could run the timer, round, and move the labels as long as the left mouse button is being held. I will look into that option.

Yes, I would tie it to mouse clicks too, only in adjust mode though, no need to run through it all the time.
Moving the labels real time is rather expensive, you would need to permanently get Y coordinate of the mouse while left button is down.
Flag or dynamic eventhandler when left mouse gets clicked in adjust mode, don't know which is cheaper. And then redraw the labels on mouse move (only if Y changes, no need to do it on X change, the checking will be cheaper than the redraw).

vvhg

Hic Rhodos, hic salta.
Reply With Quote
Thanked by:
  #6 (permalink)
 
Xav1029's Avatar
 Xav1029 
Tampa, FL
 
Experience: Beginner
Platform: NinjaTrader, Sierra Chart
Broker: Mirus Futures/Zen-Fire
Trading: 6E, M6E, 6J
Posts: 1,375 since Dec 2011
Thanks Given: 1,452
Thanks Received: 3,377


vvhg View Post
Yes, I would tie it to mouse clicks too, only in adjust mode though, no need to run through it all the time.
Moving the labels real time is rather expensive, you would need to permanently get Y coordinate of the mouse while left button is down.
Flag or dynamic eventhandler when left mouse gets clicked in adjust mode, don't know which is cheaper. And then redraw the labels on mouse move (only if Y changes, no need to do it on X change, the checking will be cheaper than the redraw).

vvhg

@vvhg could you post a snippet that would trigger an event every 100ms? I've never worked with timers, so don't know where to begin. Also do I use ChartControl.ActiveControl to figure out which object is selected? Since the lines are drawn internally, I know the tags. I don't want to adjust labels that don't need to be adjusted to keep it as "cheap" as possible lol. So I'm thinking to just return on the timer event if not in adjust mode. Then have a bool that is set to true on mouse down, false on mouse up. Return on the timer event if that bool is false. If it is in adjust mode, bool is true, and the active control is one of the drawn lines, then adjust the labels and rounded to the nearest tick. To save some cycles, I will just round and adjust the label. I will round the actual line y value to the nearest tick once the user locks("set") the levels.


Sent from my iPhone using Tapatalk

London Calling
Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #7 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824


Xav1029 View Post
@vvhg could you post a snippet that would trigger an event every 100ms? I've never worked with timers, so don't know where to begin. Also do I use ChartControl.ActiveControl to figure out which object is selected? Since the lines are drawn internally, I know the tags. I don't want to adjust labels that don't need to be adjusted to keep it as "cheap" as possible lol. So I'm thinking to just return on the timer event if not in adjust mode. Then have a bool that is set to true on mouse down, false on mouse up. Return on the timer event if that bool is false. If it is in adjust mode, bool is true, and the active control is one of the drawn lines, then adjust the labels and rounded to the nearest tick. To save some cycles, I will just round and adjust the label. I will round the actual line y value to the nearest tick once the user locks("set") the levels.


Sent from my iPhone using Tapatalk

Hmmm, I don't think a timer makes much sense, as you need the mouse move event either way (for the current Y value). Then starting and stopping the timer on mouse move would probably be more expensive than returning on the mouse move event. What you could better do is only subscribe to the event when needed, so in adjust mode.

You could have a look at the vvTrendLineTrader code for the mouse events, and at vvSuperGauge for converting mouse-Y to price if you need that. I can not provide any snippets now as I am away from the computer, so you would havet to wait until tomorrow.

Vvhg

Hic Rhodos, hic salta.
Reply With Quote
Thanked by:
  #8 (permalink)
 
Xav1029's Avatar
 Xav1029 
Tampa, FL
 
Experience: Beginner
Platform: NinjaTrader, Sierra Chart
Broker: Mirus Futures/Zen-Fire
Trading: 6E, M6E, 6J
Posts: 1,375 since Dec 2011
Thanks Given: 1,452
Thanks Received: 3,377


vvhg View Post
Hmmm, I don't think a timer makes much sense, as you need the mouse move event either way (for the current Y value). Then starting and stopping the timer on mouse move would probably be more expensive than returning on the mouse move event. What you could better do is only subscribe to the event when needed, so in adjust mode.

You could have a look at the vvTrendLineTrader code for the mouse events, and at vvSuperGauge for converting mouse-Y to price if you need that. I can not provide any snippets now as I am away from the computer, so you would havet to wait until tomorrow.

Vvhg

@vvhg I will take a look at those two tools. I just need to make sure that on the mousemove event, one of the levels are actually being moved. Off the top of your head, do you know if one of those two tools checks if you are moving lines in the mouse events? I'm not in front of my computer either, so can't check now.

London Calling
Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #9 (permalink)
 
Xav1029's Avatar
 Xav1029 
Tampa, FL
 
Experience: Beginner
Platform: NinjaTrader, Sierra Chart
Broker: Mirus Futures/Zen-Fire
Trading: 6E, M6E, 6J
Posts: 1,375 since Dec 2011
Thanks Given: 1,452
Thanks Received: 3,377

OK so I stole most of this code from @vvhg, and the rest I stole from NT support forum. This basic tool is just an example of what I was trying to do. What it does is check if a horizontal line is selected, and if it is it changes the color to red and adds a label. Just like the chart trader lines, once selected, you can move the line, and it will always round it to the nearest tick. The label follows the selected line. When a line is selected it is red, and returns to original color when you deselect it. Right now the label stays on the chart, and is not formatted, but I am tired and the point of this thread was to figure out how to do what I explained in the first post. Feel free to steal this code and make something useful out of it. I am working on an alert system that will use this, and once I finish the alert system, you will easily be able to create a strategy that uses the shell and be able to tie stops and targets to horizontal lines just like the chart trader Pretty much you will be able to run sophisticated ATM's and manage them just like the chart trader ATM's

London Calling
Attached Files
Elite Membership required to download: XavTickRoundLabelTest.zip
Visit my NexusFi Trade Journal Started this thread Reply With Quote
Thanked by:
  #10 (permalink)
 emun 
prague, czech republic
 
Experience: Advanced
Platform: NinjaTrader
Trading: NQ
Posts: 165 since May 2012
Thanks Given: 49
Thanks Received: 74



Xav1029 View Post
OK so I stole most of this code from @vvhg, and the rest I stole from NT support forum. This basic tool is just an example of what I was trying to do. What it does is check if a horizontal line is selected, and if it is it changes the color to red and adds a label. Just like the chart trader lines, once selected, you can move the line, and it will always round it to the nearest tick. The label follows the selected line. When a line is selected it is red, and returns to original color when you deselect it. Right now the label stays on the chart, and is not formatted, but I am tired and the point of this thread was to figure out how to do what I explained in the first post. Feel free to steal this code and make something useful out of it. I am working on an alert system that will use this, and once I finish the alert system, you will easily be able to create a strategy that uses the shell and be able to tie stops and targets to horizontal lines just like the chart trader Pretty much you will be able to run sophisticated ATM's and manage them just like the chart trader ATM's

It is great! But unfortunately it is not possible to change color of a line... It is the only disadvantage! Would it be possible to make available this change?
And I would also like to ask, how is it possible to add the label?

Reply With Quote




Last Updated on April 21, 2017


© 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