I'm trying to have a rectangle, that once drawn, can access the bars inside it data.
I mannged to get the bars numbers, but couldn't access more.
will be happy to get any help
here is the code :
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
#endregion
//This namespace holds Drawing tools in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.DrawingTools
{
public class DynamicVolumeProfile : ShapeBase
{
public override object Icon { get { return Gui.Tools.Icons.DrawRectangle; } }
protected override void OnStateChange()
{
base.OnStateChange();
if (State == State.SetDefaults)
{
Name = "DynamicVolumeProfile";
ShapeType = ChartShapeType.Rectangle;
}
}
public override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
base.OnRender(chartControl, chartScale);
Stroke outlineStroke = OutlineStroke;
RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;
outlineStroke.RenderTarget = RenderTarget;
ChartPanel chartPanel = chartControl.ChartPanels[PanelIndex];
Point startPoint = StartAnchor.GetPoint(chartControl, chartPanel, chartScale);
Point endPoint = EndAnchor.GetPoint(chartControl, chartPanel, chartScale);
double width = endPoint.X - startPoint.X;
double height = endPoint.Y - startPoint.Y;
double strokePixAdjust = outlineStroke.Width % 2 == 0 ? 0.5d : 0d;
SharpDX.Vector2 centerPoint = (startPoint + ((endPoint - startPoint) / 2)).ToVector2();
SimpleFont TextFont = new Gui.Tools.SimpleFont() { Size = 10}; //new SimpleFont("Consolas", width/8);
TextFont.Size = 40;
SharpDX.DirectWrite.TextFormat textFormat = TextFont.ToDirectWriteTextFormat();
textFormat.TextAlignment = SharpDX.DirectWrite.TextAlignment.Center;
textFormat.WordWrapping = SharpDX.DirectWrite.WordWrapping.NoWrap;
SharpDX.RectangleF layoutRect = new SharpDX.RectangleF((float)(startPoint.X + strokePixAdjust),
(float)(startPoint.Y + strokePixAdjust),
(float)(width), (float)(height));
RenderTarget.DrawText(StartAnchor.SlotIndex.ToString() + " " + EndAnchor.SlotIndex.ToString(), textFormat, layoutRect, Brushes.Blue.ToDxBrush(RenderTarget));
textFormat.Dispose();
}
}
}

Comment