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

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:




          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 Perr0Grande, Today, 08:16 PM
              0 responses
              2 views
              0 likes
              Last Post Perr0Grande  
              Started by elderan, Today, 08:03 PM
              0 responses
              5 views
              0 likes
              Last Post elderan
              by elderan
               
              Started by algospoke, Today, 06:40 PM
              0 responses
              10 views
              0 likes
              Last Post algospoke  
              Started by maybeimnotrader, Today, 05:46 PM
              0 responses
              12 views
              0 likes
              Last Post maybeimnotrader  
              Started by quantismo, Today, 05:13 PM
              0 responses
              7 views
              0 likes
              Last Post quantismo  
              Working...
              X