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!
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
NinjaTrader
Reference manually drawn trendline
Collapse
X
-
Originally posted by dukeb View PostIf I manually draw a trendline on a chart, is there a way to reference that trendline within a strategy?
-
Originally posted by dukeb View PostIf I manually draw a trendline on a chart, is there a way to reference that trendline within a strategy?
This guy here was looping through the ChartObjects to find where manually drawn horizontal lines were placed out.
This may or may not pick up trendlines. But it is something worth checking out.
Comment
-
DrawObject
This is right out of reference
foreach (IDrawObject draw in DrawObjects)
{
if (draw is ILine)
{
ILine drawnLine = (ILine) draw;
Print("Line Object: " + draw.Tag + " Manually Drawn: " + draw.UserDrawn);
}
}
I loaded a new chart then loaded this indicator and placed a couple of manually drawn trendlines on the chart.
1) The lines appear to be indexed (0,1 etc)
2) There is a large quantity of output. Is this because this is on a tic basis and not bars?
3) What is the purpose of the red code?
I get the same output with or without this code.
4) Very important. I can't seem to get a price value for various points on the trendline.
How is this done?
Thank you...
Duke
Comment
-
That's going to take some serious math to compute lines that aren't straight.
Originally posted by dukeb View PostThis is right out of reference
foreach (IDrawObject draw in DrawObjects)
{
if (draw is ILine)
{
ILine drawnLine = (ILine) draw;
Print("Line Object: " + draw.Tag + " Manually Drawn: " + draw.UserDrawn);
}
}
I loaded a new chart then loaded this indicator and placed a couple of manually drawn trendlines on the chart.
1) The lines appear to be indexed (0,1 etc)
2) There is a large quantity of output. Is this because this is on a tic basis and not bars?
3) What is the purpose of the red code?
I get the same output with or without this code.
4) Very important. I can't seem to get a price value for various points on the trendline.
How is this done?
Thank you...
Duke
Comment
-
Thankfully it's already handled.
I hacked up the PKPriceAlert2.
The usage of "Value" was incorrect in the post I referenced earlier. I'm sure I compiled that on my desktop at some point, but I can't find it. Wait - that was in NT 6.5. Now I remember.
I unknowingly upgraded this to NT7 version.
Be sure to check out the entire Print Statement to see what is available to you at each Y.
Code:#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; using System.Collections; using System.Collections.Generic; #endregion // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { /// <summary> /// Enter the description of your new custom indicator here /// </summary> [Description("Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen.")] public class PKPriceAlert2 : Indicator { #region Variables // Wizard generated variables private DateTime startTime; private bool uptrend = false; private string breakFloor = "Alert1.wav"; // Price Breaking Down thru horizontal line alert wav file private string breakCeiling = "Alert1.wav"; // Price Breaking Up thru horizontal line alert wav file // User defined variables (add any user defined variables below) #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() { CalculateOnBarClose = true; Overlay = true; this.startTime = DateTime.Now; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar < 1) return; if (startTime.Ticks < Time[0].Ticks ) return; List<ChartObject> ChartObjectArrayList = new List<ChartObject>(); foreach (ChartObject CO in this.ChartControl.ChartObjects) { if ( CO is NinjaTrader.Gui.Chart.ILine ) { ChartObjectArrayList.Add(CO); } } foreach(ChartObject CO in ChartObjectArrayList) { double PriceAlert = Math.Round(CO.Y,4); Print(CO.ToString() + " Horizontal Line Value= " + CO.Y + " PriceAlert=" + PriceAlert ); } } #region Properties [Description("")] [Category("Parameters")] public bool Uptrend { get { return uptrend; } set { uptrend = value; } } [Description("Price Breaking Down thru horizontal line alert wav file")] [Category("Alert")] public string BreakFloor { get { return breakFloor; } set { breakFloor = value; } } [Description("Price Breaking Down thru horizontal line alert wav file")] [Category("Alert")] public string BreakCeiling { get { return breakCeiling; } set { breakCeiling = 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 PKPriceAlert2[] cachePKPriceAlert2 = null; private static PKPriceAlert2 checkPKPriceAlert2 = new PKPriceAlert2(); /// <summary> /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen. /// </summary> /// <returns></returns> public PKPriceAlert2 PKPriceAlert2(bool uptrend) { return PKPriceAlert2(Input, uptrend); } /// <summary> /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen. /// </summary> /// <returns></returns> public PKPriceAlert2 PKPriceAlert2(Data.IDataSeries input, bool uptrend) { if (cachePKPriceAlert2 != null) for (int idx = 0; idx < cachePKPriceAlert2.Length; idx++) if (cachePKPriceAlert2[idx].Uptrend == uptrend && cachePKPriceAlert2[idx].EqualsInput(input)) return cachePKPriceAlert2[idx]; lock (checkPKPriceAlert2) { checkPKPriceAlert2.Uptrend = uptrend; uptrend = checkPKPriceAlert2.Uptrend; if (cachePKPriceAlert2 != null) for (int idx = 0; idx < cachePKPriceAlert2.Length; idx++) if (cachePKPriceAlert2[idx].Uptrend == uptrend && cachePKPriceAlert2[idx].EqualsInput(input)) return cachePKPriceAlert2[idx]; PKPriceAlert2 indicator = new PKPriceAlert2(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.Uptrend = uptrend; Indicators.Add(indicator); indicator.SetUp(); PKPriceAlert2[] tmp = new PKPriceAlert2[cachePKPriceAlert2 == null ? 1 : cachePKPriceAlert2.Length + 1]; if (cachePKPriceAlert2 != null) cachePKPriceAlert2.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cachePKPriceAlert2 = 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> /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen. /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.PKPriceAlert2 PKPriceAlert2(bool uptrend) { return _indicator.PKPriceAlert2(Input, uptrend); } /// <summary> /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen. /// </summary> /// <returns></returns> public Indicator.PKPriceAlert2 PKPriceAlert2(Data.IDataSeries input, bool uptrend) { return _indicator.PKPriceAlert2(input, uptrend); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { /// <summary> /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen. /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.PKPriceAlert2 PKPriceAlert2(bool uptrend) { return _indicator.PKPriceAlert2(Input, uptrend); } /// <summary> /// Sends an alert to the alert window when the price crosses any horizontal line manually drawn on the screen. /// </summary> /// <returns></returns> public Indicator.PKPriceAlert2 PKPriceAlert2(Data.IDataSeries input, bool uptrend) { 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.PKPriceAlert2(input, uptrend); } } } #endregion
Originally posted by dukeb View Post
Thank you...
DukeHTML Code:Name='Line' Time='8/8/2012 8:30:00 AM', StartBar='9108' StartY='1392.18' EndTime='8/8/2012 9:00:00 AM' EndBar='9138' EndY='1391.02' Horizontal Line Value= 1392.18252381616 PriceAlert=1392.1825 Name='Line' Time='8/8/2012 8:31:00 AM', StartBar='9109' StartY='1390.85' EndTime='8/8/2012 9:00:00 AM' EndBar='9138' EndY='1392.31' Horizontal Line Value= 1390.85000933148 PriceAlert=1390.85 Name='Line' Time='8/8/2012 8:30:00 AM', StartBar='9108' StartY='1392.18' EndTime='8/8/2012 9:00:00 AM' EndBar='9138' EndY='1391.02' Horizontal Line Value= 1392.18252381616 PriceAlert=1392.1825 Name='Line' Time='8/8/2012 8:31:00 AM', StartBar='9109' StartY='1390.85' EndTime='8/8/2012 9:00:00 AM' EndBar='9138' EndY='1392.31' Horizontal Line Value= 1390.85000933148 PriceAlert=1390.85
Comment
-
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by inanazsocial, Today, 01:15 AM
|
0 responses
2 views
0 likes
|
Last Post
by inanazsocial
Today, 01:15 AM
|
||
Started by trilliantrader, 04-18-2024, 08:16 AM
|
5 responses
22 views
0 likes
|
Last Post Today, 12:32 AM | ||
Started by Davidtowleii, Today, 12:15 AM
|
0 responses
3 views
0 likes
|
Last Post
by Davidtowleii
Today, 12:15 AM
|
||
Started by guillembm, Yesterday, 11:25 AM
|
2 responses
9 views
0 likes
|
Last Post
by guillembm
Yesterday, 11:58 PM
|
||
Started by junkone, 04-21-2024, 07:17 AM
|
9 responses
71 views
0 likes
|
Last Post
by jeronymite
Yesterday, 11:51 PM
|
Comment