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

What color is the candle?

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

    What color is the candle?

    I have a custom indicator that paints the bar with one of several brushes and I need to be able to determine which one of them was used.. Of course, it's a simple matter to just look at it and see, but I want to use this information in a Strategy and need a way to extract the hex value of the brush that was used. It appears that the gdi32 GetPixel DllImport should do the job, but I'm unable to obtain the proper color using this approach. Please show me the proper method required to obtain this pixel value.

    #2
    I realized that I was a bit short on detail when posting the problem, so here is the code:

    SharpDX.Direct2D1.SolidColorBrush SharpDXRedBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Red);
    RenderTarget.FillRectangle(new SharpDX.RectangleF(BoxStartX, y, BoxWidth, BoxHeight), SharpDXRedBrush);
    uint pixel = GetPixel((BoxStartX + BoxWidth)/2, (y + BoxHeight)/2);
    Print("Center of Top rectangle " + ((pixel >> 16) & 0xFF) + " " + ((pixel >> 8) & 0xFF) + " " + (pixel & 0xFF));

    and this was the output: "Center of Top Rectangle 213 141 64" which is sort of gray and the actually displayed rectangle is Red as should be

    Comment


      #3
      Is the custom indicator something you built or something you have source code for? If so, why not store the information you need in a more computer friendly format? The indicator could store a Series<T>, perhaps an enum.

      Code:
      public enum BarColor
      {
           ColorOne,
           ColorTwo,
           ColorThree
      }
      
      public class SomeIndicator
      {
           public Series<BarColor> BarColor { get; private set; }
      }
      You would initialize the Series in State.Configure and have it updated in the OnBarUpdate when the color for the bar is also picked.

      I would suggest going one step further and changing the enum to represent the actual meanings behind the color instead of the color itself.

      Comment


        #4
        No, I only have access to the visual data that is displayed for the indicator and know only that one of several brushes was used to paint the bar. That is why I'm trying to access the data in this roundabout method. Why is the data not available? In the code example snippet above, you can see that I successfully created a red rectangle and when I attempt to access one of the pixels inside the rectangle with GetBit, it returns a completely different value than what I just created at that point, so the data that was just created on the display is not accessible on the canvas immediately after it is created.

        Comment


          #5
          Did you attach a debugger and look at the indicator? Perhaps you can use reflection to access the underlying data the indicator might be using when it determines how to color the chart. Its a shame the designers of the indicator didn't make the indicator more then just a visual presentation.

          Comment


            #6
            Hello vaughn,

            If the bar has BarBrushes set, you can check from this collection.


            If the bar has an original color you can check the ChartBars.Properties.ChartStyle.DownBrush.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by adeelshahzad, Today, 03:54 AM
            3 responses
            16 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by yertle, Today, 08:38 AM
            4 responses
            13 views
            0 likes
            Last Post yertle
            by yertle
             
            Started by bill2023, Yesterday, 08:51 AM
            6 responses
            27 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by NinjaTrader_ChelseaB, 01-08-2017, 06:59 PM
            80 responses
            19,667 views
            5 likes
            Last Post NinjaTrader_ChelseaB  
            Started by dappa, Today, 09:18 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X