NexusFi: Find Your Edge


Home Menu

 





Measure the distance between any two moving averages


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one KySt with 3 posts (1 thanks)
    2. looks_two forrestang with 1 posts (2 thanks)
    3. looks_3 bobwest with 1 posts (0 thanks)
    4. looks_4 SamirOfSalem with 1 posts (0 thanks)
    1. trending_up 4,947 views
    2. thumb_up 4 thanks given
    3. group 3 followers
    1. forum 6 posts
    2. attach_file 2 attachments




 
Search this Thread

Measure the distance between any two moving averages

  #1 (permalink)
 KySt 
Accokeek, USA
 
Experience: Intermediate
Platform: NT & TOS
Trading: ES RUT
Posts: 92 since Mar 2011
Thanks Given: 17
Thanks Received: 24

Good day,
I am looking for something similar to measure the distance between any two moving averages.
In the example, the distance is 15 ticks. It is preferable if it would calculate as the bar is building. The opposite is true if it were to the down side,-15 ticks. The opacity is nice, but can be an option to turn off. I really desire the output to be text in the corner of the chart. Is there such an indicator for NT8?

Thank you, Ky



Attached Thumbnails
Click image for larger version

Name:	image_676.png
Views:	271
Size:	5.4 KB
ID:	307147  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
What broker to use for trading palladium futures
Commodities
Trade idea based off three indicators.
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Footprint for strategy Builder
NinjaTrader
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Funded Trader platforms
33 thanks
Just another trading journal: PA, Wyckoff & Trends
23 thanks
Trading with Intuition
18 thanks
Self sabotage reframed
14 thanks
GFIs1 1 DAX trade per day journal
9 thanks
  #2 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,333 since Jun 2010
Thanks Given: 354
Thanks Received: 1,049


KySt View Post
Good day,
I am looking for something similar to measure the distance between any two moving averages.
In the example, the distance is 15 ticks. It is preferable if it would calculate as the bar is building. The opposite is true if it were to the down side,-15 ticks. The opacity is nice, but can be an option to turn off. I really desire the output to be text in the corner of the chart. Is there such an indicator for NT8?

Thank you, Ky

I was trying to think of a way to do this w/o building an indie, I.e., using an off the shelf indie to get the value you want, and I can't think of anything off-the-shelf. There may be, and I'm just not thinking of it?

If nobody comes up with an off-the-shelf solution, you can always ask in the "Want your ninjatrader indicator created for free?" in the elite sections, as this would be easy to do.

Just post an image(can be scribbled in MS paint) of what you'd want to see, and someone will take it up.

Reply With Quote
Thanked by:
  #3 (permalink)
 KySt 
Accokeek, USA
 
Experience: Intermediate
Platform: NT & TOS
Trading: ES RUT
Posts: 92 since Mar 2011
Thanks Given: 17
Thanks Received: 24



forrestang View Post
I was trying to think of a way to do this w/o building an indie, I.e., using an off the shelf indie to get the value you want, and I can't think of anything off-the-shelf. There may be, and I'm just not thinking of it?

If nobody comes up with an off-the-shelf solution, you can always ask in the "Want your ninjatrader indicator created for free?" in the elite sections, as this would be easy to do.

Just post an image(can be scribbled in MS paint) of what you'd want to see, and someone will take it up.

Good idea, thank you.

Started this thread Reply With Quote
  #4 (permalink)
 
bobwest's Avatar
 bobwest 
Western Florida
Site Moderator
 
Experience: Advanced
Platform: Sierra Chart
Trading: ES, YM
Frequency: Several times daily
Duration: Minutes
Posts: 8,172 since Jan 2013
Thanks Given: 57,542
Thanks Received: 26,292


KySt View Post
Good day,
I am looking for something similar to measure the distance between any two moving averages.
In the example, the distance is 15 ticks. It is preferable if it would calculate as the bar is building. The opposite is true if it were to the down side,-15 ticks. The opacity is nice, but can be an option to turn off. I really desire the output to be text in the corner of the chart. Is there such an indicator for NT8?

Thank you, Ky



If what you want is a plot of the difference over time, this is what the standard MACD indicator does. It typically only uses EMA's, but there are implementations where you can choose the MA type.

You can simply choose the two EMA lengths and you have it. It doesn't print the value as text on the main chart, and it also gives you another line to be looking at, so it's not exactly what you are asking for. But you can set the value to be shown on the lower panel where the indicator plot is (which is the default anyway). You don't have to show the MACD indicator's MA nor the difference bars if you don't want them, and you just have the plain MA difference over time. To calculate as the bar is building, set Calculate on Bar Close to false.

If this works for what you want, it's an out-of-the-box solution. Otherwise, as suggested, if you ask in the free indicator thread someone may be willing to do the minor changes necessary.

Bob.

When one door closes, another opens.
-- Cervantes, Don Quixote
Reply With Quote
  #5 (permalink)
 KySt 
Accokeek, USA
 
Experience: Intermediate
Platform: NT & TOS
Trading: ES RUT
Posts: 92 since Mar 2011
Thanks Given: 17
Thanks Received: 24


bobwest View Post
If what you want is a plot of the difference over time, this is what the standard MACD indicator does. It typically only uses EMA's, but there are implementations where you can choose the MA type.

You can simply choose the two EMA lengths and you have it. It doesn't print the value as text on the main chart, and it also gives you another line to be looking at, so it's not exactly what you are asking for. But you can set the value to be shown on the lower panel where the indicator plot is (which is the default anyway). You don't have to show the MACD indicator's MA nor the difference bars if you don't want them, and you just have the plain MA difference over time. To calculate as the bar is building, set Calculate on Bar Close to false.

If this works for what you want, it's an out-of-the-box solution. Otherwise, as suggested, if you ask in the free indicator thread someone may be willing to do the minor changes necessary.

Bob.

Hello Bob,
Thank you for replying. I'm seek the value of the MA spread, in +/-ticks, at the moment. I do not code, but gave the thought of MACD as the basis. I think the MACD uses the same MA type for all lines when calculating. Where as, I would have a couple different configurations (EMA/SMA, Double EMA/WMA...). The output can be in simple text in the corners of the charts. Graphing the chart is ok too, but the main objective to quickly see the numeric value. I did post this in the Free Indicator section as suggested.

Thank you, Ky

Started this thread Reply With Quote
Thanked by:
  #6 (permalink)
 SamirOfSalem   is a Vendor
 
Posts: 74 since Jan 2020
Thanks Given: 23
Thanks Received: 44

This was quickly put together from NinjaTrader's script wizard. Takes two SMA's and plots the difference along with a message in upper right corner. I hope it helps.



 
Code
namespace NinjaTrader.NinjaScript.Indicators
{
	public class KySt : Indicator
	{
        private SMA lowerMA;
        private SMA upperMA;
        
        protected override void OnStateChange()
		{
			if (State == State.SetDefaults)
			{
				Description									= @"Enter the description for your new custom Indicator here.";
				Name										= "KySt";
				Calculate									= Calculate.OnBarClose;
				IsOverlay									= false;
				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;
				PeriodLowerMA					= 8;
				PeriodUpperMA					= 14;
				AddPlot(Brushes.Orange, "Difference");
			}
			else if (State == State.Configure)
			{
			
			}
            else if (State == State.DataLoaded)
            {
                lowerMA = SMA(PeriodLowerMA);
                upperMA = SMA(PeriodUpperMA);
            }

		}

		protected override void OnBarUpdate()
		{
			//Add your custom indicator logic here.
            Difference[0] = upperMA[0] - lowerMA[0];
            string message = "Difference = " + Difference[0].ToString("#0.00") + "\n" + "In ticks = " + (Difference[0] / TickSize).ToString("#0.00");
            var tbDifference = Draw.TextFixed(this, "Fixed Text | Tick Difference", message, TextPosition.TopRight);
		}

		#region Properties
		[NinjaScriptProperty]
		[Range(1, int.MaxValue)]
		[Display(Name="Period of Lower SMA", Order=1, GroupName="Parameters")]
		public int PeriodLowerMA
		{ get; set; }

		[NinjaScriptProperty]
		[Range(1, int.MaxValue)]
		[Display(Name="Period of Upper SMA", Order=2, GroupName="Parameters")]
		public int PeriodUpperMA
		{ get; set; }

		[Browsable(false)]
		[XmlIgnore]
		public Series<double> Difference
		{
			get { return Values[0]; }
		}
		#endregion

	}
}

Reply With Quote
  #7 (permalink)
 vaibhavkamble 
Parsippany, NJ, USA
 
Experience: Beginner
Platform: NinjaTrader
Trading: Currency Futures, Futures, Treasuries, Bonds
Posts: 20 since Mar 2019
Thanks Given: 53
Thanks Received: 6

There is below indi available that lets you enter formula and operands can be most widely used NT8 indicators. I suppose you sould be able to calculate and plot difference between MA using this indi.



Reply With Quote
Thanked by:




Last Updated on December 11, 2020


© 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