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

Pixles to BarsAgo Function

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

    Pixles to BarsAgo Function

    Hi,
    For example, I want to DrawText which should be located to the right of the last bar on the chart, but if I measure the distance in bars then the text location will be different from daily to minute chart that's based on the space between bars...

    The solution I think is to have the distance measured in pixels rather, and convert it to bars accordingly, for example 100 pixels would equal to 3 bars on daily chart or 30 bars on minutes chart.. how to a achieve that (a function)?

    Any help would be highly appreciated.

    Thanks

    #2
    Hello Bassam,

    Thank you for your note,

    Please note that this kind of programming is unsupported and I don't have documentation on it.

    However, you can get the pixel value of each bar location by using ChartControl.GetXByBarIdx(Bars bar, int idx)

    This will return the pixel count at which the bar you requested is located. Additionally, you would need to use DrawString Graphics method as the DrawText requires that you use a BarsAgo number to place it.

    You can do the DrawString in the Plot method which an example can be found by going to Tools -> Edit NinjaScript -> Indicator -> CustomPlotSample

    http://msdn.microsoft.com/en-us/libr...rawstring.aspx
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thank you Cal.
      An example if someone is looking for the same.

      it will plot a "sample text" at last bar position.

      Code:
       #region Variables
      private StringFormat            stringFormat    = new StringFormat();
      private    SolidBrush                textBrush        = new SolidBrush(Color.Black);
      private    System.Drawing.Font        textFont        = new Font("Arial", 10);
        #endregion
      protected override void OnTermination()
             {
                  textBrush.Dispose();
                  stringFormat.Dispose();
              }
      public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
              {
                  
                  int pixles = ChartControl.GetXByBarIdx(BarsArray[0], Count);
                  textBrush.Color            = Color.Blue; // set text color
                  graphics.DrawString("Upper left corner", textFont, textBrush, bounds.X +pixles, bounds.Y + 300, stringFormat);
              
              }
      Last edited by bassam; 04-02-2014, 11:48 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by funk10101, Today, 12:02 AM
      0 responses
      3 views
      0 likes
      Last Post funk10101  
      Started by gravdigaz6, Yesterday, 11:40 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by MarianApalaghiei, Yesterday, 10:49 PM
      3 responses
      10 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by XXtrader, Yesterday, 11:30 PM
      0 responses
      4 views
      0 likes
      Last Post XXtrader  
      Started by love2code2trade, 04-17-2024, 01:45 PM
      4 responses
      28 views
      0 likes
      Last Post love2code2trade  
      Working...
      X