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!
See more
See less

Partner 728x90

Collapse

How to do a polygon hit test?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to do a polygon hit test?

    I want to test to see if an enclosing candle body is contained within a polygon (in this case the polygon is a price channel).

    When the price bar (which is also a polygon) leaves the enclosing polygon I need to set a condition.

    How would I do this in Ninjatrader, would I use windows GDI?
    Attached Files

    #2
    Hi DancesWithBears, you'll need to run the math calculations to determine if something lies inside the polygon. I'm not sure how you're drawing the polygon, but if it done by selecting points, you can find the slope (y=mx+b) of the relevant lines and then run some logic to see if the price bar is inside (or outside) the polygon.
    AustinNinjaTrader Customer Service

    Comment


      #3
      System.Windows.Shapes Namespace?

      Do I have access to the System.Windows.Shapes Namespace? Then I can use Polygon class

      Comment


        #4
        I don't see any reason why you wouldn't have access to System.Windows.Shapes. If you do use .Shapes, unfortunately we can't provide support for any issues arising from its use.

        Regardless, I took a look at the Polygon class in System.Windows.Shapes and you have to have points to create a polygon, so my previous point still stands about calculating the slope of the lines and running your own logic to determine position relative to that polygon.

        PS. I like your name. I was once a counselor known as "Dances With Wolves" at a nature/science camp for 6th graders in the Yampa Valley.
        Last edited by NinjaTrader_Austin; 08-05-2009, 01:28 PM.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Trying to avoid writing a hit test method

          Austin,

          Tried to add the
          using System.Windows.Shapes;
          but script doesn't compile. hmm?

          Your point stands about how to create polygon vertices for the channel lines.

          I am given y, and can derive m .
          i.e. the polygon using y = mx + b.
          then I move the line down via changing the b value to get my channel.

          Now I have four points that enclose that surface.

          I just want to create a polygon object because the class already supports hit testing (I don't want to test debug that logic if it exists.)
          via :
          Polygon.HitTestCore(GeometryHitTestParameters) Implements

          OnBarUpdate() I just supply the high of the current bar.

          If I can't use the Shapes namespace I might have to rethink.

          Originally posted by NinjaTrader_Austin View Post
          I don't see any reason why you wouldn't have access to System.Windows.Shapes. If you do use .Shapes, unfortunately we can't provide support for any issues arising from its use.

          Regardless, I took a look at the Polygon class in System.Windows.Shapes and you have to have points to create a polygon, so my previous point still stands about calculating the slope of the lines and running your own logic to determine position relative to that polygon.

          PS. I like your name. I was once a counselor known as "Dances With Wolves" at a nature/science camp for 6th graders in the Yampa Valley.

          Comment


            #6
            Originally posted by DancesWithBears View Post
            Austin,

            Tried to add the
            using System.Windows.Shapes;
            but script doesn't compile. hmm?
            Copy + paste from the MSDN entry:

            --------------------------------------------------
            Shape Class

            Provides a base class for shape elements, such as Ellipse, Polygon, and Rectangle.

            Namespace: System.Windows.Shapes
            Assembly: PresentationFramework (in PresentationFramework.dll)
            --------------------------------------------------

            Because of this, I think you'll need to add a reference to this PresentationFramework.dll for the "using System.Windows.Shapes;" statement to work. I'm not sure where this .dll file is located though. A general Google search might be of assistance.

            In addition, I wasn't aware there was a function for a "hit test." That method seems like it would be easiest by far.
            AustinNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by usazencort, Today, 01:16 AM
            0 responses
            1 view
            0 likes
            Last Post usazencort  
            Started by kaywai, 09-01-2023, 08:44 PM
            5 responses
            603 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by xiinteractive, 04-09-2024, 08:08 AM
            6 responses
            22 views
            0 likes
            Last Post xiinteractive  
            Started by Pattontje, Yesterday, 02:10 PM
            2 responses
            20 views
            0 likes
            Last Post Pattontje  
            Started by flybuzz, 04-21-2024, 04:07 PM
            17 responses
            230 views
            0 likes
            Last Post TradingLoss  
            Working...
            X