• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ChartPanel attributes from inside a Strategy?

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

    #16
    Once there's a bar on the chart, I can get price... I could even try to extrapolate and figure out the min max based on the Y of the hi and lo of the bar...

    But I fear this won't be precise enough.. And it's kind of a hack.

    Thanks...

    Comment


      #17
      Originally posted by BigWaveDave View Post
      Once there's a bar on the chart, I can get price... I could even try to extrapolate and figure out the min max based on the Y of the hi and lo of the bar...

      But I fear this won't be precise enough.. And it's kind of a hack.

      Thanks...
      Well, then it sounds as if you have to get your hands on the ChartHelper package. It does have a function in there, ConvertPriceToY.

      Comment


        #18
        Yes indeed it does... But it requires _min and _max... lol.

        Comment


          #19
          [solved]

          Forget it. Found the answer in this thread:

          http://www.ninjatrader.com/support/f...25145#poststop


          So, you must use Add(IndicatorName()) in the Strategy

          The question of how to reference that created object from somewhere within the Strategy is this...

          ....
          double chartMin = IndicatorName().Min;

          That's the piece I was missing. I'm new to C# and I'm not sure why the generic IndicatorName() references the object created within Add(). Or maybe this is a NT thing?

          This works for me.

          Thanks for all the help.

          Comment


            #20
            Originally posted by BigWaveDave View Post
            I need to be able to convert from mouse coords to price and time from within a Strategy. That's the kicker.

            I'm already aware of the ChartHelper class that provides such conversions (and the ChartControl undocumented members which I assume are relatively new).

            But, to convert from a Price to a Y coord requires knowing what the min price value on the Y axis is as well as the current pixel/tick ratio. This info, as far as I can tell, is only available through overriding Plot() in an Indicator.

            Sledge's suggestion is a good one. I can use an Indicator to cache the required values provided in the Plot override. And then access the cached values from my Strategy. The Strategy class doesn't implement Plot() from what I can tell.

            Obviously having an Indicator just for that purpose is not optimal and complicates distribution of my Strategy. So basically, I'm trying to see if I can get it done with the ChartControl functions.

            I'm new to NT, so any help would be appreciated.
            Let us try again.

            1. We want to know the tick to pixel ratio.

            Find highest high on chart. Use GetYByValue() to get the pixel position.
            Find lowest low on chart. Use GetYByValue() to get the pixel position.

            We now know the price range, and how many pixels it covers, so we can calculate the ratio.

            2. Use ChartControl.Bounds.Top (maybe unnecessary, as this should probably be identically equal to zero) and ChartControl.Bounds.Bottom to determine the entire pixel range of the chart.

            With that information, is should be possible to determine the bottom and top price on the chart axis, and hence the y-location of any price.

            e.g., We know the lowest price and its pixel, and we know the lowest pixel displayed.
            How many pixels between the lowest price and the bottom of the chart?
            Multiply that by the tick to pixel ratio, and we know how many ticks.
            Subtract from lowest price, and we know the lowest price displayed on the axis.

            Finding the scale top is just more arithmetical gymnastics based on the same technique. (It may even not be necessary, as the bottom of the scale provides a point of reference from which to calculate other things).

            I fully believe that you can code that all on your lonesome. If I have a few spare cycles, I might try to do it myself later. If you do code it, please be so kind as to share your effort with us. We can probably turn it into a function/method that folks can plunk into UserDefinedMethods.cs, or just into the particular class that they need it in.
            Last edited by koganam; 10-22-2012, 07:27 AM. Reason: Corrected spelling.

            Comment


              #21
              Yes, this would work. I pondered this in a previous post... but I fear it might not be accurate enough unless the highest high and the lowest low are at or near the bounds of the chart. For example, if the price axis is scaled way, way down, the pixel distance from highest high to lowest low would be small relative to the price range it represents. Calculating a ratio in this scenario wouldn't have a lot of precision... The real question is whether or not that lack of precision would be meaningful for the type of drawing that I'm doing. I'll have to think about that.

              For now, I'm simply using an Indicator and referencing it from my Strategy... That way I have 'relatively' direct access to the price Min and Max values. I have no idea if this approach is more efficient than yours.

              I honestly do appreciate the input.

              Thanks.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Hanstanz, Today, 04:44 AM
              0 responses
              6 views
              0 likes
              Last Post Hanstanz  
              Started by juniortut, Today, 04:38 AM
              0 responses
              5 views
              0 likes
              Last Post juniortut  
              Started by rojiinko, Today, 03:58 AM
              0 responses
              4 views
              0 likes
              Last Post rojiinko  
              Started by mreanuzlazx, Today, 01:30 AM
              0 responses
              4 views
              0 likes
              Last Post mreanuzlazx  
              Started by xinepev, Today, 12:33 AM
              0 responses
              4 views
              0 likes
              Last Post xinepev
              by xinepev
               
              Working...
              X