NexusFi: Find Your Edge


Home Menu

 





Plotting text in indicator panel


Discussion in NinjaTrader

Updated
    1. trending_up 8,270 views
    2. thumb_up 9 thanks given
    3. group 4 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

Plotting text in indicator panel

  #1 (permalink)
 
ibiscmllc's Avatar
 ibiscmllc 
Parkland, FL, USA
 
Experience: Advanced
Platform: NinjaTrader
Broker: Kinetick, Amp Futures
Trading: ES, 6E
Posts: 17 since Aug 2010
Thanks Given: 0
Thanks Received: 6

I would like to draw a descriptive label for each row of dots in my indicator panel. It is not an issue drawing the text to the right of the plot using DrawText but there is apparently no parameter to draw it to the left of the row (so that the label is always visible even if I scroll the price chart to the left). I was told that this may require an overriding of the Plot method. Any good example out there or some sample code that could help me out?
Thanks!

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Trade idea based off three indicators.
Traders Hideout
How to apply profiles
Traders Hideout
Exit Strategy
NinjaTrader
Increase in trading performance by 75%
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
30 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
16 thanks
  #3 (permalink)
 MooreTech 
Orlando, Florida
 
Experience: Advanced
Platform: NinjaTrader, TradeStation, MultiCharts, eSignal, MetaTrader
Trading: ES
Posts: 57 since Aug 2010
Thanks Given: 6
Thanks Received: 73


Here's an example of overriding the plot method. If you want to plot the text on the left, you will probably want to increase the left margin by using:

ChartControl.MarginLeft = 20;

 
Code
                            
// 
// Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//

#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    
/// <summary>
    /// This is a sample for an indicator which with custom plotting.
    /// </summary>
    
[Description("This is a sample for an indicator using custom plotting.")]
    public class 
CustomPlotSample Indicator
    
{
        
#region Variables
        // Wizard generated variables
        // User defined variables (add any user defined variables below)
        
private StringFormat            stringFormat    = new StringFormat();
        private    
SolidBrush                textBrush        = new SolidBrush(Color.Black);
        private    
System.Drawing.Font        textFont        = new Font("Arial"10);
        
#endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        
protected override void Initialize()
        {
            
ChartOnly            true;
        }

        
/// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        
protected override void OnBarUpdate()
        {
        }

        
#region Miscellaneous
        /// <summary>
        /// Overload this method to handle the termination of an indicator. Use this method to dispose of any resources vs overloading the Dispose() method.
        /// </summary>
        
protected override void OnTermination()
        {
            
textBrush.Dispose();
            
stringFormat.Dispose();
        }

        
/// <summary>
        /// Called when the indicator is plotted.
        /// </summary>
        /// <param name="graphics">Graphics context</param>
        /// <param name="bounds">Paintable chart region</param>
        /// <param name="min">Min indicator value plotted</param>
        /// <param name="max">Max indicator value plotted</param>
        
public override void Plot(Graphics graphicsRectangle boundsdouble mindouble max)
        {
            
// Default plotting in base class. Uncomment if indicators holds at least one plot.
            // base.Plot(graphics, bounds, min, max);

            // fill the complete paintable region
            // note: although the rectangle is greater and even would start plotting at the left upper corner of the chart, 
            // it's clipped to the paintable region
            // the qualification 'InHitTest' is used to exclude the drawn rectangle from the mouse selection action
            
SolidBrush tmpBrush = new SolidBrush(Color.LightGray);
            if (!
InHitTest)
                
graphics.FillRectangle(tmpBrush, new Rectangle (0020002000));
            
tmpBrush.Dispose();

            
// plot a green line from the upper left to the lower right corner
            // all painting needs to go by bounds X/Y offset
            
Pen tmpPen = new Pen(Color.Green);
            
graphics.DrawLine(tmpPenbounds.Xbounds.Ybounds.bounds.Widthbounds.bounds.Height);

            
// plot a green line from the lower left to the upper right corner and apply 
            // apply AnitAlias to make the line look nicer
            // don't forget to reset after plotting -> smoothing has some performance impact
            
SmoothingMode oldSmoothingMode graphics.SmoothingMode;        // save current smoothing mode
            
graphics.SmoothingMode SmoothingMode.AntiAlias;                // apply smoothing mode
            
graphics.DrawLine(new Pen(Color.Green), bounds.Xbounds.bounds.Heightbounds.bounds.Widthbounds.Y);
            
graphics.SmoothingMode oldSmoothingMode;                        // restore smoothing mode
            
tmpPen.Dispose();

            
// plot text in the upper left corner at position 10/10
            
stringFormat.Alignment    StringAlignment.Near;                    // text is docked to the left
            
textBrush.Color            Color.Blue;                            // set text color
            
graphics.DrawString("Upper left corner"textFonttextBrushbounds.10bounds.10stringFormat);
            
            
// paint text at the lower left corner right to the bottom on background with an outline
            // 1) plot background rectangle
            
tmpBrush = new SolidBrush(Color.Red);
            
graphics.FillRectangle(tmpBrushbounds.10bounds.bounds.Height 2014019);
            
tmpBrush.Dispose();
            
// 2) plot outline
            
tmpPen = new Pen(Color.Black);
            
graphics.DrawRectangle(tmpPenbounds.10bounds.bounds.Height 2014019);
            
tmpPen.Dispose();
            
// 3) plot text
            
graphics.DrawString("Lower left corner"textFonttextBrushbounds.10bounds.bounds.Height 20stringFormat);
        }

        
#endregion

        #region Properties
        #endregion
    
}


Follow me on Twitter Reply With Quote




Last Updated on November 19, 2010


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts