NexusFi: Find Your Edge


Home Menu

 





Intersection of 3 rays


Discussion in NinjaTrader

Updated
    1. trending_up 2,152 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Intersection of 3 rays

  #1 (permalink)
stockgoblin
Canaduh
 
Posts: 22 since Aug 2011
Thanks Given: 3
Thanks Received: 3

Hi,

I have a custom indicator that draws rays from highs and lows and I would like to have another indicator that shows me when three rays intersect perfectly. Sometimes it looks like they do visually but they don't so an indicator would be helpful. I wrote an excel program to do this and used the slopes and y-intercepts to calculate the intersections and then checked all the three line combinations for a match. I assume I'll have to approach this problem differently as a ninjatrader custom indicator?

First: Do you think this is possible to achieve?

Second: Any ideas on how to approach this?

I was thinking of an "if the y values of rays are equal at certain bars" but the intersections hardly ever occur at exact bar x values. Hmmmm....


Thanks for any suggestions.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
About a successful futures trader who didn´t know anyth …
Psychology and Money Management
ZombieSqueeze
Platforms and Indicators
Cheap historycal L1 data for stocks
Stocks and ETFs
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
What broker to use for trading palladium futures
Commodities
 
  #3 (permalink)
 
aquarian1's Avatar
 aquarian1 
Point Roberts, WA, USA
 
Experience: Advanced
Platform: IB and free NT
Broker: IB
Trading: ES
Posts: 4,034 since Dec 2010
Thanks Given: 1,509
Thanks Received: 2,593


An interesting question.

If you have two lines that intersect (i'll get to 3 in a minute) then you would compute the intersection as the simultaneous solution of two linear equations: So y=mx+B and z=nx+C .

An example with a downward sloping line from Peak A and an upward sloping line from trough B:

Peak A= 1342 at 17:11 June 10, 2012 and the ray from peak A is downward sloping at -0.02 per minute.
So m=-0.02 and B=1342
Setting midnight of 10 June 2012 = minute zero, then the start time of your ray is 17*60+11 or minute 1031.

So Ray1 draws downward from 1342 at a slope of -0.02, starting from a peak at minute 1031 then it would be:
y=-0.02 * (x-1031) +1342. ; where x is in minutes and y in points.

So at 8:30am on June 11, 2012 minute is 1440+8*60+30 or 1950:
y=-0.02 * (1950-1031) +1342
y= -0.02 * 919 +1342
y= -18.38 + 1342
y=1323.62


Trough B = 1299.75 at 6:43 June 11, 2012 (or minute 1440+6*60+43 or 1843) and the ray is ascending at +0.01 points per minute. so n=+0.01 and C=1299.75. It's equation is :
z=+0.01 * (x-1843) + 1299.75

We are solving for x such the y=x ie the point level (price is the same)
y=-0.02 * (x-1031) + 1342.00 (eq1)
z=+0.01 * (x-1843) + 1299.75 (eq2)

y=z so;
0=y-z (eq3)

0=-0.02 * (x-1031) + 1342 +0.01 * (x-1843) + 1299.75
0.03x=81.30
x=81.30 / 0.03 (eq4)
x=2710

The lines cross at minute 2710 (=June 11, 2012 at 21:10)


Checking minute 2710
y=-0.02 * (x-1031) +1342
y=-0.02 * (2710-1031) +1342 = 1308.42

z=+0.01 * (x-1843) + 1299.75
z=+0.01 * (2710-1843) + 1299.75 = 1308.42

------ so at this point you would go back to (eq4) and write the generalized form of the solution and that would give you the time a value where your two rays crossed = intersection1
So you would plot a marker at 1308.42 at 21:10 on June 11 ( and perhaps text as well? "lines cross at 1308.42 at 21:10 June 11, 2012"

------------------re 3 points---------
A straight line can only cross another at one point and one point only.

Now you can see that odds are unlikely that Ray3 actually crosses Ray1 and Ray 2 at exactly intersection1, it might look like it but it is probably only close. This would be a perfect triangulation. The slope of Ray3 HAS TO BE an exact slope and only one slope for the starting point of Ray3 for Ray3 to cross at intersection 1. Ray3 is redundant - that is Ray3, (or Ray4 Ray5 Ray6 for that matter) do not change the intersection point of Ray1 and Ray2.

Using the same approach as above you can compute where Ray3 meets Ray1 = Intersection2. Then you can repeat and find out where Ray3 meets Ray2 = Intersection3.

Probably you will get three intersection points - perhaps close forming a tiny triangle.

So if you are using this for trading then you could probably average the three points or since all the points have to be very close for you to see them as crossing at the same point - OR just ignore Ray3 and Intersection2 and interection3. It isn't changing Intersection Point1.

I hope this helps

..........
peace, love and joy to you
.........
Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 
aquarian1's Avatar
 aquarian1 
Point Roberts, WA, USA
 
Experience: Advanced
Platform: IB and free NT
Broker: IB
Trading: ES
Posts: 4,034 since Dec 2010
Thanks Given: 1,509
Thanks Received: 2,593

On the generalized form of the equation you go back and put in the letters (the variables).

I'm a bit brain dead at the moment so if someone else reads this perhaps they can do that for this gentleman.

..........
peace, love and joy to you
.........
Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 
aquarian1's Avatar
 aquarian1 
Point Roberts, WA, USA
 
Experience: Advanced
Platform: IB and free NT
Broker: IB
Trading: ES
Posts: 4,034 since Dec 2010
Thanks Given: 1,509
Thanks Received: 2,593

You also have to decide what to do for times it doesn't trade so for ES
15:15 to 15:50 Mon-tues
and
15:15 to 17:00 Sunday for Friday.

..........
peace, love and joy to you
.........
Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 
aquarian1's Avatar
 aquarian1 
Point Roberts, WA, USA
 
Experience: Advanced
Platform: IB and free NT
Broker: IB
Trading: ES
Posts: 4,034 since Dec 2010
Thanks Given: 1,509
Thanks Received: 2,593

IF you only want to know the intersection after it happens you can just test for a reversal. So in the example above the decending ray is greater than the ascending ray until they cross and then it is less.

..........
peace, love and joy to you
.........
Visit my NexusFi Trade Journal Reply With Quote




Last Updated on June 18, 2012


© 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