NexusFi: Find Your Edge


Home Menu

 





Help Request for Multi Time Frame Indicator


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one w4w4w with 5 posts (5 thanks)
    2. looks_two Blash with 3 posts (2 thanks)
    3. looks_3 iq200 with 2 posts (2 thanks)
    4. looks_4 marpol with 1 posts (0 thanks)
    1. trending_up 3,480 views
    2. thumb_up 9 thanks given
    3. group 4 followers
    1. forum 11 posts
    2. attach_file 5 attachments




 
Search this Thread

Help Request for Multi Time Frame Indicator

  #1 (permalink)
w4w4w
Vienna Austria
 
Posts: 5 since Mar 2017
Thanks Given: 3
Thanks Received: 5

I'm having a hard time understanding how to program a multi timeframe NinjaTrader indicator.

What I'm trying to do is really simple:
I want to plot the value of a data series which was calculated using daily data and apply it to a minute chart.

As a simple example, let's say I had an indicator (please see HiLoOpen attached below) that calculates the average of the previous day high, the previous day low, and the current day open. This data would be saved in a data series called HiLoOpenPlot:

HiLoOpenPlot[0] = (High[1]+Low[1]+Open[0])/3

To make this DataSeries accessible from another indicator, I would include the following in the Properties region:

[Browsable(false)]
[XmlIgnore]
public Series<double> Callable_HiLoOpen
{
get { return HiLoOpenPlot; }
}

I have a second indicator called HiLoOpenINTRADAY (also attached below), which is supposed to draw the current value of HiLoOpenPlot[0] (calculated using day bars) as a horizontal line on a minute chart:

Draw.HorizontalLine(this,"HorizAtHiLoOpen",HiLoOpen().Callable_HiLoOpen[0],Brushes.Blue,DashStyleHelper.Solid,2);

Predictably, if I put HiLoOpenINTRADAY, on a minute chart it does not draw a horizontal line based on day bars, but rather on minute bars.

After reading through the Multi Time Frame & Instruments article in the NinjaTrader 8 Help Guide and the info on the AddDataSeries() method, I attempted to create another indicator -- HiLoOpenVersion2 (please see the indicator attached to this post). This indicator also isn't drawing the expected horizontal line.

At this point, I am at a loss as to how to proceed. I've spent the past three days and countless hours on this and I'm hitting a brick wall. I don't want to ask someone to do the coding for me, but I could really use some detailed guidance on how to approach this... it can't be too difficult to make this work.

Attached Files
Elite Membership required to download: HiLoOpen.zip
Elite Membership required to download: HiLoOpenINTRADAY.zip
Elite Membership required to download: HiLoOpenVersion2.zip
Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
REcommedations for programming help
Sierra Chart
NexusFi Journal Challenge - May 2024
Feedback and Announcements
ZombieSqueeze
Platforms and Indicators
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Bigger Wins or Fewer Losses?
24 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #3 (permalink)
 
Blash's Avatar
 Blash 
Chicago, IL
Legendary Market Chamois
 
Experience: None
Platform: NT8,NT7,TWS
Broker: InteractiveBrokers, S5T, IQFeed
Trading: The one I'm creating in the present....Index Futures mini/micro, ZF
Posts: 2,311 since Nov 2011
Thanks Given: 7,341
Thanks Received: 4,518



w4w4w View Post
I'm having a hard time understanding how to program a multi timeframe NinjaTrader indicator.

What I'm trying to do is really simple:
I want to plot the value of a data series which was calculated using daily data and apply it to a minute chart.

As a simple example, let's say I had an indicator (please see HiLoOpen attached below) that calculates the average of the previous day high, the previous day low, and the current day open. This data would be saved in a data series called HiLoOpenPlot:

HiLoOpenPlot[0] = (High[1]+Low[1]+Open[0])/3

To make this DataSeries accessible from another indicator, I would include the following in the Properties region:

[Browsable(false)]
[XmlIgnore]
public Series<double> Callable_HiLoOpen
{
get { return HiLoOpenPlot; }
}

I have a second indicator called HiLoOpenINTRADAY (also attached below), which is supposed to draw the current value of HiLoOpenPlot[0] (calculated using day bars) as a horizontal line on a minute chart:

Draw.HorizontalLine(this,"HorizAtHiLoOpen",HiLoOpen().Callable_HiLoOpen[0],Brushes.Blue,DashStyleHelper.Solid,2);

Predictably, if I put HiLoOpenINTRADAY, on a minute chart it does not draw a horizontal line based on day bars, but rather on minute bars.

After reading through the Multi Time Frame & Instruments article in the NinjaTrader 8 Help Guide and the info on the AddDataSeries() method, I attempted to create another indicator -- HiLoOpenVersion2 (please see the indicator attached to this post). This indicator also isn't drawing the expected horizontal line.

At this point, I am at a loss as to how to proceed. I've spent the past three days and countless hours on this and I'm hitting a brick wall. I don't want to ask someone to do the coding for me, but I could really use some detailed guidance on how to approach this... it can't be too difficult to make this work.

Use this instead...

Close[0] (primary dataseries current closing price) vs Closes[0][0] (this is also the primary dataseries closing price) vs Closes[1][0] (this is the the first of the secondary dataseries added in the indicator and it's current closing price)

as I did here....
Quoting 
TotStkMarket52WkNHNL[0] = Closes[1][0] + Closes[2][0] + Closes[3][0];

also add this

Quoting 
(CurrentBars[0] <= BarsRequiredToPlot || CurrentBars[1] <= BarsRequiredToPlot)
return;

And remove your current CurrentBar code or comment it out.

Ron

...My calamity is My providence, outwardly it is fire and vengeance, but inwardly it is light and mercy...
The steed of this Valley is pain; and if there be no pain this journey will never end.
Buy Low And Sell High (read left to right or right to left....lol)
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
w4w4w
Vienna Austria
 
Posts: 5 since Mar 2017
Thanks Given: 3
Thanks Received: 5

Ron thanks for the quick reply.

I've logged out of my trading computer for the day as it is getting late where I live, but I will use your suggestion tomorrow morning and let you know how it goes.

Thanks again!

Reply With Quote
Thanked by:
  #5 (permalink)
w4w4w
Vienna Austria
 
Posts: 5 since Mar 2017
Thanks Given: 3
Thanks Received: 5

Ron, I made the changes suggested in your reply from yesterday:
 
Code
		private Double MyPriceLevel = 0;
		
		protected override void OnStateChange()
		{
			if (State == State.SetDefaults)
			{
				Description							= @"";
				Name								= "HiLoOpenVersion2";
				Calculate							= Calculate.OnPriceChange;
				IsOverlay							= true;
				DisplayInDataBox						= true;
				DrawOnPricePanel						= true;
				DrawHorizontalGridLines						= true;
				DrawVerticalGridLines						= true;
				PaintPriceMarkers						= true;
				ScaleJustification						= NinjaTrader.Gui.Chart.ScaleJustification.Right;
				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
				//See Help Guide for additional information.
				IsSuspendedWhileInactive					= true;
				BarsRequiredToPlot = 10;
			}
			else if (State == State.Configure)
			{
				AddDataSeries(BarsPeriodType.Day, 1);
			}
		}

		protected override void OnBarUpdate()
		{
			if(CurrentBars[0] <= BarsRequiredToPlot || CurrentBars[1] <= BarsRequiredToPlot)
				return;
			
			if (BarsInProgress == 1)
			{
				MyPriceLevel = (Highs[1][1]+Lows[1][1]+Opens[1][0])/3;
				Draw.HorizontalLine(this,"Horiz1",MyPriceLevel,Brushes.Gold,DashStyleHelper.Solid,2);
			}
			
			if (BarsInProgress == 0)
			{
				
			}
		}

These changes are reflected in the attached indicator file HiLoOpenVersion3.

An interesting problem has arisen: If I apply the indicator to a chart with an interval of day or higher, the expected horizontal line is drawn. However, if I apply the indicator to a chart with an interval of less than a day, the line isn't drawn.

Do you know of any way to get the line to plot on a chart with an intraday interval?

Attached Files
Elite Membership required to download: HiLoOpenVersion3.zip
Reply With Quote
Thanked by:
  #6 (permalink)
 
Blash's Avatar
 Blash 
Chicago, IL
Legendary Market Chamois
 
Experience: None
Platform: NT8,NT7,TWS
Broker: InteractiveBrokers, S5T, IQFeed
Trading: The one I'm creating in the present....Index Futures mini/micro, ZF
Posts: 2,311 since Nov 2011
Thanks Given: 7,341
Thanks Received: 4,518


w4w4w View Post
Ron, I made the changes suggested in your reply from yesterday:

 
Code
private Double MyPriceLevel = 0;



protected override void OnStateChange()

{

if (State == State.SetDefaults)

{

Description= @"";

Name= "HiLoOpenVersion2";

Calculate= Calculate.OnPriceChange;

IsOverlay= true;

DisplayInDataBox= true;

DrawOnPricePanel= true;

DrawHorizontalGridLines= true;

DrawVerticalGridLines= true;

PaintPriceMarkers= true;

ScaleJustification= NinjaTrader.Gui.Chart.ScaleJustification.Right;

//Disable this property if your indicator requires custom values that cumulate with each new market data event. 

//See Help Guide for additional information.

IsSuspendedWhileInactive= true;

BarsRequiredToPlot = 10;

}

else if (State == State.Configure)

{

AddDataSeries(BarsPeriodType.Day, 1);

}

}



protected override void OnBarUpdate()

{

if(CurrentBars[0] <= BarsRequiredToPlot || CurrentBars[1] <= BarsRequiredToPlot)

return;



if (BarsInProgress == 1)

{

MyPriceLevel = (Highs[1][1]+Lows[1][1]+Opens[1][0])/3;

Draw.HorizontalLine(this,"Horiz1",MyPriceLevel,Brushes.Gold,DashStyleHelper.Solid,2);

}



if (BarsInProgress == 0)

{



}

}




These changes are reflected in the attached indicator file HiLoOpenVersion3.



An interesting problem has arisen: If I apply the indicator to a chart with an interval of day or higher, the expected horizontal line is drawn. However, if I apply the indicator to a chart with an interval of less than a day, the line isn't drawn.



Do you know of any way to get the line to plot on a chart with an intraday interval?



I think it might be easier to just use:


Quoting 
Bars.GetDayBar(int tradingDaysBack).Open
Bars.GetDayBar(int tradingDaysBack).High
Bars.GetDayBar(int tradingDaysBack).Low
Bars.GetDayBar(int tradingDaysBack).Close

Instead of adding the same instrument to the chart in day bars. I think it will work then for any periodicity you want.

https://ninjatrader.com/support/helpGuides/nt8/en-us/?getdaybar.htm

You can use CurrentDayOHL() for the current days values. As you will see from the link.

Ron


Sent from my iPhone using futures.io

...My calamity is My providence, outwardly it is fire and vengeance, but inwardly it is light and mercy...
The steed of this Valley is pain; and if there be no pain this journey will never end.
Buy Low And Sell High (read left to right or right to left....lol)
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #7 (permalink)
 iq200 
London, UK
 
Experience: Intermediate
Platform: Ninjatrader, Tradestation
Broker: Kinetick, InteractiveBrokers
Trading: Equities, Futures
Posts: 408 since Jun 2010
Thanks Given: 145
Thanks Received: 278


w4w4w View Post
Ron, I made the changes suggested in your reply from yesterday:
 
Code
		private Double MyPriceLevel = 0;
		
		protected override void OnStateChange()
		{
			if (State == State.SetDefaults)
			{
				Description							= @"";
				Name								= "HiLoOpenVersion2";
				Calculate							= Calculate.OnPriceChange;
				IsOverlay							= true;
				DisplayInDataBox						= true;
				DrawOnPricePanel						= true;
				DrawHorizontalGridLines						= true;
				DrawVerticalGridLines						= true;
				PaintPriceMarkers						= true;
				ScaleJustification						= NinjaTrader.Gui.Chart.ScaleJustification.Right;
				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
				//See Help Guide for additional information.
				IsSuspendedWhileInactive					= true;
				BarsRequiredToPlot = 10;
			}
			else if (State == State.Configure)
			{
				AddDataSeries(BarsPeriodType.Day, 1);
			}
		}

		protected override void OnBarUpdate()
		{
			if(CurrentBars[0] <= BarsRequiredToPlot || CurrentBars[1] <= BarsRequiredToPlot)
				return;
			
			if (BarsInProgress == 1)
			{
				MyPriceLevel = (Highs[1][1]+Lows[1][1]+Opens[1][0])/3;
				Draw.HorizontalLine(this,"Horiz1",MyPriceLevel,Brushes.Gold,DashStyleHelper.Solid,2);
			}
			
			if (BarsInProgress == 0)
			{
				
			}
		}

These changes are reflected in the attached indicator file HiLoOpenVersion3.

An interesting problem has arisen: If I apply the indicator to a chart with an interval of day or higher, the expected horizontal line is drawn. However, if I apply the indicator to a chart with an interval of less than a day, the line isn't drawn.

Do you know of any way to get the line to plot on a chart with an intraday interval?

I did something similar recently. I plot on the lower timeframe when I have processed all the higher timeframes, on the last but one bar of the last secondary timeframe:

if (BarsInProgress > 0 && CurrentBar == (BarsArray[BarsArray.Count() - 1].Count - 2))
{
// Plot here
}

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #8 (permalink)
w4w4w
Vienna Austria
 
Posts: 5 since Mar 2017
Thanks Given: 3
Thanks Received: 5

Ron and iq200 thanks for the feedback! I've had little opportunity to work on this in the past few days. I will post back here as soon as I'm back up to speed on this.

Reply With Quote
Thanked by:
  #9 (permalink)
w4w4w
Vienna Austria
 
Posts: 5 since Mar 2017
Thanks Given: 3
Thanks Received: 5

I have made some progress, but its getting obvious that I've gone beyond my level of programming experience.

To illustrate the problem I'm having, the code below is supposed to draw a line at the level of the previous day's high on an intraday chart. Unfortunately, the line is at the high of two days ago.

I'm missing something in the code, but can't figure out what.

Could someone put me on the right track?

Please see the attached screen shot.
 
Code
	public class PrevHigh : Indicator
	{
		private Series<double> myEmptyIndexedSeries;
		private double PrevDayHigh = 0;
			
		protected override void OnStateChange()
		{
			if (State == State.SetDefaults)
			{
				Description							= @"";
				Name								= "PrevHigh";
				Calculate							= Calculate.OnPriceChange;
				IsOverlay							= true;
				DisplayInDataBox						= true;
				DrawOnPricePanel						= true;
				DrawHorizontalGridLines						= true;
				DrawVerticalGridLines						= true;
				PaintPriceMarkers						= true;
				ScaleJustification						= NinjaTrader.Gui.Chart.ScaleJustification.Right;
				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
				//See Help Guide for additional information.
				IsSuspendedWhileInactive					= true;
				BarsRequiredToPlot = 10;
			}
			else if (State == State.Configure)
			{
				AddDataSeries(BarsPeriodType.Day, 1);
			}
			else if (State == State.Historical)
			{
      			myEmptyIndexedSeries = new Series<double>(BarsArray[1]);
			}
		}

		protected override void OnBarUpdate()
		{
			if(CurrentBars[0] <= BarsRequiredToPlot || CurrentBars[1] <= BarsRequiredToPlot)
				return;
			
			if (BarsInProgress == 1)
			{
				PrevDayHigh = Highs[1][1];
			}
			
			if (BarsInProgress == 0)
			{
				Draw.Line(this,CurrentBar.ToString()+"PrevHi",false
					,1,
					PrevDayHigh
					,0,
					PrevDayHigh
					,Brushes.Goldenrod,DashStyleHelper.Solid,2);
			}
		}

Attached Thumbnails
Click image for larger version

Name:	chart.png
Views:	215
Size:	79.7 KB
ID:	231294  
Reply With Quote
Thanked by:
  #10 (permalink)
 
Blash's Avatar
 Blash 
Chicago, IL
Legendary Market Chamois
 
Experience: None
Platform: NT8,NT7,TWS
Broker: InteractiveBrokers, S5T, IQFeed
Trading: The one I'm creating in the present....Index Futures mini/micro, ZF
Posts: 2,311 since Nov 2011
Thanks Given: 7,341
Thanks Received: 4,518



w4w4w View Post
I have made some progress, but its getting obvious that I've gone beyond my level of programming experience.



To illustrate the problem I'm having, the code below is supposed to draw a line at the level of the previous day's high on an intraday chart. Unfortunately, the line is at the high of two days ago.



I'm missing something in the code, but can't figure out what.



Could someone put me on the right track?



Please see the attached screen shot.

 
Code
public class PrevHigh : Indicator

{

private Series<double> myEmptyIndexedSeries;

private double PrevDayHigh = 0;



protected override void OnStateChange()

{

if (State == State.SetDefaults)

{

Description= @"";

Name= "PrevHigh";

Calculate= Calculate.OnPriceChange;

IsOverlay= true;

DisplayInDataBox= true;

DrawOnPricePanel= true;

DrawHorizontalGridLines= true;

DrawVerticalGridLines= true;

PaintPriceMarkers= true;

ScaleJustification= NinjaTrader.Gui.Chart.ScaleJustification.Right;

//Disable this property if your indicator requires custom values that cumulate with each new market data event. 

//See Help Guide for additional information.

IsSuspendedWhileInactive= true;

BarsRequiredToPlot = 10;

}

else if (State == State.Configure)

{

AddDataSeries(BarsPeriodType.Day, 1);

}

else if (State == State.Historical)

{

      myEmptyIndexedSeries = new Series<double>(BarsArray[1]);

}

}



protected override void OnBarUpdate()

{

if(CurrentBars[0] <= BarsRequiredToPlot || CurrentBars[1] <= BarsRequiredToPlot)

return;



if (BarsInProgress == 1)

{

PrevDayHigh = Highs[1][1];

}



if (BarsInProgress == 0)

{

Draw.Line(this,CurrentBar.ToString()+"PrevHi",false

,1,

PrevDayHigh

,0,

PrevDayHigh

,Brushes.Goldenrod,DashStyleHelper.Solid,2);

}

}



NT8 does have PriorDayOHLC indicator..... maybe it would do the job you are looking for?

Ron


Sent from my iPhone using futures.io

...My calamity is My providence, outwardly it is fire and vengeance, but inwardly it is light and mercy...
The steed of this Valley is pain; and if there be no pain this journey will never end.
Buy Low And Sell High (read left to right or right to left....lol)
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on April 12, 2017


© 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