NexusFi: Find Your Edge


Home Menu

 





a little programming question


Discussion in NinjaTrader

Updated
    1. trending_up 622 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 0 posts
    2. attach_file 2 attachments




 
Search this Thread

a little programming question

  #1 (permalink)
 futurewiz 
Stuttgart Deutschland
 
Experience: Beginner
Platform: Ninjatrader
Broker: CQG
Trading: FDAX, ES
Posts: 59 since Nov 2012
Thanks Given: 39
Thanks Received: 21

Hello,
maybe someone has a good idea:



It revolves around the display of yesterday's high or low, especially the text description.
The position of the description of the low is my starting point. this is the currently working variant.
However, if I use M1 as the timeframe, the description with the tag advancing will be out of sight and so I'm looking for ways to make the description move with it (slightly in front of the bars) in order to finally stay there for the session break line at the end of the day.
On the screenshot you can see the desater. The yesterday high line is garbage because the text descriptions are printed over and over again without deleting the previous one.

i tried to print the line after the text description to overwrite it, but you see the success.

Prigramming isn't my strong point and that's just a beauty flaw, but I find a clear screen with few lines and always knowing where I am is important for our business.

Maybe you have some tips.

A second question I would like to get rid of. Similar to the current lines I would like to display the VA high and VA low from yesterday as well. If you know an indicator that calculates the VA and only draws the lines into the new day without printing profiles.

Thank you very much for your help
futurewiz

 
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>
    /// Plots the high and low values from the session starting on the prior day.
    /// </summary>
    
[Description("Plots the high and low values from the session starting on the prior day.")]
    public class 
KnPriorDayHighAndLow Indicator
    
{
        
#region Variables

        // Wizard generated variables
        // User defined variables (add any user defined variables below)
        //OLD private DateTime     currentDate     = Cbi.Globals.MinDate;
        
private DateTime     currentDate     DateTime.Now;
        private 
DateTime    actualBarTime;  // for Line Description Printing
        
        
private double        currentOpen        0;
        private 
double        currentHigh        0;
        private 
double        currentLow        0;
        private 
double        currentClose    0;
        private 
double        priordayOpen    0;
        private 
double        priordayHigh    0;
        private 
double        priordayLow        0;
        private 
double        priordayClose    0;
        
        private 
bool        showHigh        true;
        private 
bool        showLow            true;
        
        
        private 
bool        showTextHigh            true;
        private 
string        showDescriptionHigh        "Y-High:";
        private 
Font         textFontHigh            = new Font("Arial"8fFontStyle.Regular);
        private 
Color         textColorHigh            Color.Green;
        private 
Color         outlineColorHigh        Color.Green;
        private 
Color         areaColorHigh            Color.Transparent;
        private 
int         zopacityHigh            0;
        
        private 
bool        showTextLow                true;
        private 
string        showDescriptionLow        "Y-Low:";
        private 
Font         textFontLow                = new Font("Arial"8fFontStyle.Regular);
        private 
Color         textColorLow            Color.Red;
        private 
Color         outlineColorLow            Color.Red;
        private 
Color         areaColorLow            Color.Transparent;
        private 
int         zopacityLow                0;        
        
        
#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()
        {
            
Add(new Plot(Color.GreenPlotStyle.Hash"Prior High"));
            
Add(new Plot(Color.RedPlotStyle.Hash"Prior Low"));
            
            
Plots[0].Pen.DashStyle DashStyle.Dash;
            
Plots[1].Pen.DashStyle DashStyle.Dash;
            
            
AutoScale             false;
            
Overlay                true;      // Plots the indicator on top of price
        
}

        
/// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        
protected override void OnBarUpdate()
        {
            if (
Bars == null)  // noch keine Bars da --> Warten
                
return;

            if (!
Bars.BarsType.IsIntraday// wenn größere Zeiteinheit als Intraday --> Fehler
            
{
                
DrawTextFixed("error msg""KN PriorDayHL only works on intraday intervals"TextPosition.BottomRight);
                return;
            }

            
// If the current date is not the same date as the current bar then its a new session !!! nur bei Sessionwechsel ausgeführt
            
if (currentDate != Bars.GetTradingDayFromLocal(Time[0]) || currentOpen == 0)
            {
                            
                
// The current day OHLC values are now the prior days value so set
                // them to their respect indicator series for plotting
                
if (currentOpen != 0)
                {
                    
priordayHigh    currentHigh;
                    
priordayLow        currentLow;
                    
                    if (
ShowHigh)  PriorHigh.Set(priordayHigh);
                    if (
ShowLow)   PriorLow.Set(priordayLow);
                    
                    
// Draw Description
                    
                    //if (showTextHigh)
                    //DrawText("highprice"+CurrentBar,true,showDescriptionHigh+"  "+Instrument.MasterInstrument.Round2TickSize(priordayHigh).ToString()+"   -",Time[3],priordayHigh,0,textColorHigh,textFontHigh,StringAlignment.Far,outlineColorHigh,areaColorHigh,ZopacityHigh);
                    //Time[3]
                    
if (showTextLow)
                    
DrawText("lowprice"+CurrentBar,true,showDescriptionLow+"  "+Instrument.MasterInstrument.Round2TickSize(priordayLow).ToString()+"   -",Time[3],priordayLow,0,textColorLow,textFontLow,StringAlignment.Far,outlineColorLow,areaColorLow,ZopacityLow);
                }
                
                
// Initilize the current day settings to the new days data
                
currentOpen     =     Open[0];
                
currentHigh     =     High[0];
                
currentLow        =    Low[0];
                
currentClose    =    Close[0];

                
currentDate     =     Bars.GetTradingDayFromLocal(Time[0]); 
            }
            else 
// The current day is the same day
            
{
                
// When will the Text Description printed (-1 is for the first print of the new day)
                
actualBarTime Time[-50]; 
                
                
// Set the current day OHLC values
                
currentHigh     =     Math.Max(currentHighHigh[0]);
                
currentLow        =     Math.Min(currentLowLow[0]);
                
currentClose    =    Close[0];
                
                
                
                if (
showTextHigh)
                    
DrawText("highprice"+CurrentBar,true,showDescriptionHigh+"  "+Instrument.MasterInstrument.Round2TickSize(priordayHigh).ToString()+"   -",actualBarTime,priordayHigh,0,textColorHigh,textFontHigh,StringAlignment.Far,outlineColorHigh,areaColorHigh,ZopacityHigh);
                
//if (showTextLow)
                //    DrawText("lowprice"+CurrentBar,true,showDescriptionLow+"  "+Instrument.MasterInstrument.Round2TickSize(priordayLow).ToString()+"   -",actualBarTime,priordayLow,0,textColorLow,textFontLow,StringAlignment.Far,outlineColorLow,areaColorLow,ZopacityLow);
            
                
if (ShowHighPriorHigh.Set(priordayHigh);
                if (
ShowLowPriorLow.Set(priordayLow);    
            }
        }

        
#region Properties
        
        
[Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
        
[XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
        
public DataSeries PriorHigh
        
{
            
get { return Values[0]; }
        }

        [
Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
        
[XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
        
public DataSeries PriorLow
        
{
            
get { return Values[1]; }
        }
        
// ==============================================================================================================================
        
[Browsable(true)]
        [
Gui.Design.DisplayNameAttribute("1.Show Yesterday High Line")]
        [
Category("Text Yesterday High Line")]
        public 
bool ShowHigh
        
{
            
get { return showHigh; }
            
set showHigh value; }
        }
        
        
        [
Description("Text marker")]
        [
Gui.Design.DisplayName ("2.Show Yesterday High Price")]
        [
Category("Text Yesterday High Line")]
        public 
bool ShowTextHigh
        
{
            
get { return showTextHigh; }
            
set showTextHigh value; }
        }
        
        [
Description("Text before Yesterday High Price")]
        [
Gui.Design.DisplayName ("3.Show Text Description")]
        [
Category("Text Yesterday High Line")]
        public 
string ShowDescriptionHigh
        
{
            
get { return showDescriptionHigh; }
            
set showDescriptionHigh value; }
        }
        
        [
XmlIgnore()]
        [
Description("Text Font")]
        [
Category("Text Yesterday High Line")]
        [
Gui.Design.DisplayNameAttribute("4.Text Font High")]
        public 
Font TextFont
        
{
            
get { return textFontHigh; }
            
set textFontHigh value; }
        }
        
        [
Browsable(false)]
        public 
string textFontSerializeHigh
        
{
            
get { return NinjaTrader.Gui.Design.SerializableFont.ToString(textFontHigh); }
            
set textFontHigh NinjaTrader.Gui.Design.SerializableFont.FromString(value); }
        }
        
        [
XmlIgnore]
        [
Description("Text Color")]
        [
Category("Text Yesterday High Line")]
        [
Gui.Design.DisplayNameAttribute("5.Text Color High")]
        public 
Color TextColorHigh
        
{
            
get { return textColorHigh; }
            
set textColorHigh value; }
        }
        
        [
Browsable(false)]
        public 
string textColorHighSerialize
        
{
            
get { return Gui.Design.SerializableColor.ToString(textColorHigh); }
            
set textColorHigh Gui.Design.SerializableColor.FromString(value); }
        }
        
        [
XmlIgnore]
        [
Description("Text Box Area Color")]
        [
Category("Text Yesterday High Line")]
        [
Gui.Design.DisplayNameAttribute("6.Text Box Area Color High")]
        public 
Color AreaColorHigh
        
{
            
get { return areaColorHigh; }
            
set areaColorHigh value; }
        }

        [
Browsable(false)]
        public 
string AreaColorHighSerialize
        
{
            
get { return Gui.Design.SerializableColor.ToString(areaColorHigh); }
            
set areaColorHigh Gui.Design.SerializableColor.FromString(value); }
        }        
        
        [
XmlIgnore]
        [
Description("Text Box Outline Color")]
        [
Category("Text Yesterday High Line")]
        [
Gui.Design.DisplayNameAttribute("7.Text Box Outline Color High")]
        public 
Color OutlineColorHigh
        
{
            
get { return outlineColorHigh; }
            
set outlineColorHigh value; }
        }

        [
Browsable(false)]
        public 
string OutlineColorHighSerialize
        
{
            
get { return Gui.Design.SerializableColor.ToString(outlineColorHigh); }
            
set outlineColorHigh Gui.Design.SerializableColor.FromString(value); }
        }
        
        [
Description("Zone Opacity")]
        [
Category("Text Yesterday High Line")]
        [
Gui.Design.DisplayNameAttribute("8.Text Box Opacity High")]
        public 
int ZopacityHigh
        
{
            
get { return zopacityHigh; }
            
set zopacityHigh value; }
        }
        
        
        
        
        
// ==============================================================================================================================
        
        
        
[Browsable(true)]
        [
Category("Text Yesterday Low Line")]
        [
Gui.Design.DisplayNameAttribute("10.Show Yesterday Low")]
        public 
bool ShowLow
        
{
            
get { return showLow; }
            
set showLow value; }
        }
        
        
        
        [
Description("Text marker")]
        [
Gui.Design.DisplayName ("2.Show Yesterday Low Price")]
        [
Category("Text Yesterday Low Line")]
        public 
bool ShowTextLow
        
{
            
get { return showTextLow; }
            
set showTextLow value; }
        }
        
        [
Description("Text before Yesterday Low Price")]
        [
Gui.Design.DisplayName ("3.Show Text Description")]
        [
Category("Text Yesterday Low Line")]
        public 
string ShowDescriptionLow
        
{
            
get { return showDescriptionLow; }
            
set showDescriptionLow value; }
        }
        
        [
XmlIgnore()]
        [
Description("Text Font")]
        [
Category("Text Yesterday Low Line")]
        [
Gui.Design.DisplayNameAttribute("4.Text Font Low")]
        public 
Font TextFontLow
        
{
            
get { return textFontLow; }
            
set textFontLow value; }
        }
        
        [
Browsable(false)]
        public 
string textFontSerializeLow
        
{
            
get { return NinjaTrader.Gui.Design.SerializableFont.ToString(textFontLow); }
            
set textFontLow NinjaTrader.Gui.Design.SerializableFont.FromString(value); }
        }
        
        [
XmlIgnore]
        [
Description("Text Color")]
        [
Category("Text Yesterday Low Line")]
        [
Gui.Design.DisplayNameAttribute("5.Text Color Low")]
        public 
Color TextColorLow
        
{
            
get { return textColorLow; }
            
set textColorLow value; }
        }
        
        [
Browsable(false)]
        public 
string textColorLowSerialize
        
{
            
get { return Gui.Design.SerializableColor.ToString(textColorLow); }
            
set textColorLow Gui.Design.SerializableColor.FromString(value); }
        }
        
        [
XmlIgnore]
        [
Description("Text Box Area Color")]
        [
Category("Text Yesterday Low Line")]
        [
Gui.Design.DisplayNameAttribute("6.Text Box Area Color Low")]
        public 
Color AreaColorLow
        
{
            
get { return areaColorLow; }
            
set areaColorLow value; }
        }

        [
Browsable(false)]
        public 
string AreaColorLowSerialize
        
{
            
get { return Gui.Design.SerializableColor.ToString(areaColorLow); }
            
set areaColorLow Gui.Design.SerializableColor.FromString(value); }
        }        
        
        [
XmlIgnore]
        [
Description("Text Box Outline Color")]
        [
Category("Text Yesterday Low Line")]
        [
Gui.Design.DisplayNameAttribute("7.Text Box Outline Color Low")]
        public 
Color OutlineColorLow
        
{
            
get { return outlineColorLow; }
            
set outlineColorLow value; }
        }

        [
Browsable(false)]
        public 
string OutlineColorLowSerialize
        
{
            
get { return Gui.Design.SerializableColor.ToString(outlineColorLow); }
            
set outlineColorLow Gui.Design.SerializableColor.FromString(value); }
        }
        
        [
Description("Zone Opacity")]
        [
Category("Text Yesterday Low Line")]
        [
Gui.Design.DisplayNameAttribute("8.Text Box Opacity Low")]
        public 
int ZopacityLow
        
{
            
get { return zopacityLow; }
            
set zopacityLow value; }
        }
        
        
        
#endregion
    
}
}

#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    public 
partial class Indicator IndicatorBase
    
{
        private 
KnPriorDayHighAndLow[] cacheKnPriorDayHighAndLow null;

        private static 
KnPriorDayHighAndLow checkKnPriorDayHighAndLow = new KnPriorDayHighAndLow();

        
/// <summary>
        /// Plots the high and low values from the session starting on the prior day.
        /// </summary>
        /// <returns></returns>
        
public KnPriorDayHighAndLow KnPriorDayHighAndLow()
        {
            return 
KnPriorDayHighAndLow(Input);
        }

        
/// <summary>
        /// Plots the high and low values from the session starting on the prior day.
        /// </summary>
        /// <returns></returns>
        
public KnPriorDayHighAndLow KnPriorDayHighAndLow(Data.IDataSeries input)
        {
            if (
cacheKnPriorDayHighAndLow != null)
                for (
int idx 0idx cacheKnPriorDayHighAndLow.Lengthidx++)
                    if (
cacheKnPriorDayHighAndLow[idx].EqualsInput(input))
                        return 
cacheKnPriorDayHighAndLow[idx];

            
lock (checkKnPriorDayHighAndLow)
            {
                if (
cacheKnPriorDayHighAndLow != null)
                    for (
int idx 0idx cacheKnPriorDayHighAndLow.Lengthidx++)
                        if (
cacheKnPriorDayHighAndLow[idx].EqualsInput(input))
                            return 
cacheKnPriorDayHighAndLow[idx];

                
KnPriorDayHighAndLow indicator = new KnPriorDayHighAndLow();
                
indicator.BarsRequired BarsRequired;
                
indicator.CalculateOnBarClose CalculateOnBarClose;
#if NT7
                
indicator.ForceMaximumBarsLookBack256 ForceMaximumBarsLookBack256;
                
indicator.MaximumBarsLookBack MaximumBarsLookBack;
#endif
                
indicator.Input input;
                
Indicators.Add(indicator);
                
indicator.SetUp();

                
KnPriorDayHighAndLow[] tmp = new KnPriorDayHighAndLow[cacheKnPriorDayHighAndLow == null cacheKnPriorDayHighAndLow.Length 1];
                if (
cacheKnPriorDayHighAndLow != null)
                    
cacheKnPriorDayHighAndLow.CopyTo(tmp0);
                
tmp[tmp.Length 1] = indicator;
                
cacheKnPriorDayHighAndLow tmp;
                return 
indicator;
            }
        }
    }
}

// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
    public 
partial class Column ColumnBase
    
{
        
/// <summary>
        /// Plots the high and low values from the session starting on the prior day.
        /// </summary>
        /// <returns></returns>
        
[Gui.Design.WizardCondition("Indicator")]
        public 
Indicator.KnPriorDayHighAndLow KnPriorDayHighAndLow()
        {
            return 
_indicator.KnPriorDayHighAndLow(Input);
        }

        
/// <summary>
        /// Plots the high and low values from the session starting on the prior day.
        /// </summary>
        /// <returns></returns>
        
public Indicator.KnPriorDayHighAndLow KnPriorDayHighAndLow(Data.IDataSeries input)
        {
            return 
_indicator.KnPriorDayHighAndLow(input);
        }
    }
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    public 
partial class Strategy StrategyBase
    
{
        
/// <summary>
        /// Plots the high and low values from the session starting on the prior day.
        /// </summary>
        /// <returns></returns>
        
[Gui.Design.WizardCondition("Indicator")]
        public 
Indicator.KnPriorDayHighAndLow KnPriorDayHighAndLow()
        {
            return 
_indicator.KnPriorDayHighAndLow(Input);
        }

        
/// <summary>
        /// Plots the high and low values from the session starting on the prior day.
        /// </summary>
        /// <returns></returns>
        
public Indicator.KnPriorDayHighAndLow KnPriorDayHighAndLow(Data.IDataSeries input)
        {
            if (
InInitialize && input == null)
                throw new 
ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

            return 
_indicator.KnPriorDayHighAndLow(input);
        }
    }
}
#endregion 

Attached Files
Elite Membership required to download: KnPriorDayHighAndLow.cs
Started this thread Reply With Quote




Last Updated on March 10, 2019


© 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