NexusFi: Find Your Edge


Home Menu

 





Convert from Pine to NT8? Excellent Divergence Entries


Discussion in NinjaTrader

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




 
Search this Thread

Convert from Pine to NT8? Excellent Divergence Entries

  #1 (permalink)
 
pilotui's Avatar
 pilotui 
Oklahoma City OK/USA
 
Experience: Intermediate
Platform: Tradovate
Broker: Tradeovate
Trading: NQ/ES/NG
Posts: 143 since Apr 2012
Thanks Given: 119
Thanks Received: 153

Is anyone able to convert the below from TV to NT8? Thanks!

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0
// © wallneradam

//@version=4
study("Low-High Balance", "LHB", precision=4)

fast_len = input(8, "Fast MA Length", minval=1)
slow_len = input(15, "Slow MA Length", minval=1)
sig_len = input(3, "Smooth length", minval=1)
atr_len = input(8, "ATR length", minval=1)


hc = high - close
cl = close - low

lhd = (cl - hc) / atr(atr_len) * 2

fast = ema(lhd, fast_len)
slow = ema(lhd, slow_len)
sig = ema(fast - slow, sig_len) * 2

hist_color = sig > 0 ? (sig > sig[1] ? color.lime : color.green) : (sig < sig[1] ? #EF3232 : color.red )

plot(fast, "fast", color=color.lime, transp=30)
plot(slow, "slow", color=color.red, transp=30)
plot(sig, "sig", color=color.yellow, display=display.none, transp=30)
plot(sig, color=hist_color, title="Hist", style=plot.style_columns, transp=85)


hline(0, "Center", color=color.new(color.gray, 50), linestyle=hline.style_dashed)

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Deepmoney LLM
Elite Quantitative GenAI/LLM
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
  #2 (permalink)
 SamirOfSalem   is a Vendor
 
Posts: 73 since Jan 2020
Thanks Given: 23
Thanks Received: 42

Here's a quick conversion attempt. See how this compares with the TV version and if the graphs match

 
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;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion

//This namespace holds Indicators in this folder and is required. Do not change it. 
namespace NinjaTrader.NinjaScript.Indicators
{
	public class fioLoHiBalance : Indicator
	{
		private Series<double> hc;
		private Series<double> cl;
		private Series<double> lhd;
		private Series<double> fastMinusSlow;

		protected override void OnStateChange()
		{
			if (State == State.SetDefaults)
			{
				Description									= @"Requested by pilouti https://nexusfi.com/ninjatrader/59519-convert-pine-ninjatrader-8-excellent-divergence-entries.html";
				Name										= "Low-High Balance (fio)";
				Calculate									= Calculate.OnPriceChange;
				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;
				
				fast_len					= 8;
				slow_len					= 15;
				sig_len					= 3;
				atr_len					= 8;
				
				AddPlot(Brushes.Lime, "Fast");
				AddPlot(Brushes.Red, "Slow");
				AddPlot(new Stroke(Brushes.Yellow, 4), PlotStyle.Bar, "Sig");
				AddPlot(new Stroke(Brushes.Yellow, 1), PlotStyle.PriceBox, "Sig Line");
				Plots[2].AutoWidth = true;

				AddLine(new Stroke(Brushes.Gray, DashStyleHelper.Dash, 1), 0, "Hline");

			}
			else if (State == State.Configure)
			{
			}
			else if (State == State.DataLoaded)
			{				
				hc = new Series<double>(this);
				cl = new Series<double>(this);
				lhd = new Series<double>(this);
				
				fastMinusSlow = new Series<double>(this);
			}
		}

		protected override void OnBarUpdate()
		{
			if (CurrentBar < 1) return;
			//Add your custom indicator logic here.
			hc[0] = High[0]-Close[0];
			cl[0] = Close[0] - Low[0];
			
			lhd[0] = (cl[0]-hc[0]) / ATR(atr_len)[0] * 2;
			
			fast[0] = EMA(lhd, fast_len)[0];			
			slow[0] = EMA(lhd, slow_len)[0];
			fastMinusSlow[0] = fast[0]-slow[0];
			
			sig[0] = EMA(fastMinusSlow, sig_len)[0] * 2;
			sigLine[0] = sig[0];
			
			Brush hist_color = sig[0] > 0 ? (sig[0] > sig[1] ? Brushes.Lime : Brushes.Green) : (sig[0] < sig[1] ? Brushes.Pink : Brushes.Red );
			PlotBrushes[2][0] = hist_color;

		}

		#region Properties
		[NinjaScriptProperty]
		[Range(1, int.MaxValue)]
		[Display(Name="Fast_len", Description="Fast MA Length", Order=1, GroupName="Parameters")]
		public int fast_len
		{ get; set; }

		[NinjaScriptProperty]
		[Range(1, int.MaxValue)]
		[Display(Name="Slow_len", Description="Slow MA Length", Order=2, GroupName="Parameters")]
		public int slow_len
		{ get; set; }

		[NinjaScriptProperty]
		[Range(1, int.MaxValue)]
		[Display(Name="Sig_len", Description="Smooth Length", Order=3, GroupName="Parameters")]
		public int sig_len
		{ get; set; }

		[NinjaScriptProperty]
		[Range(1, int.MaxValue)]
		[Display(Name="Atr_len", Description="ATR Length", Order=4, GroupName="Parameters")]
		public int atr_len
		{ get; set; }

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

		[Browsable(false)]
		[XmlIgnore]
		public Series<double> slow
		{
			get { return Values[1]; }
		}

		[Browsable(false)]
		[XmlIgnore]
		public Series<double> sig
		{
			get { return Values[2]; }
		}
		
		[Browsable(false)]
		[XmlIgnore]
		public Series<double> sigLine
		{
			get { return Values[3]; }
		}

		#endregion

	}
}

#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
	public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
	{
		private fioLoHiBalance[] cachefioLoHiBalance;
		public fioLoHiBalance fioLoHiBalance(int fast_len, int slow_len, int sig_len, int atr_len)
		{
			return fioLoHiBalance(Input, fast_len, slow_len, sig_len, atr_len);
		}

		public fioLoHiBalance fioLoHiBalance(ISeries<double> input, int fast_len, int slow_len, int sig_len, int atr_len)
		{
			if (cachefioLoHiBalance != null)
				for (int idx = 0; idx < cachefioLoHiBalance.Length; idx++)
					if (cachefioLoHiBalance[idx] != null && cachefioLoHiBalance[idx].fast_len == fast_len && cachefioLoHiBalance[idx].slow_len == slow_len && cachefioLoHiBalance[idx].sig_len == sig_len && cachefioLoHiBalance[idx].atr_len == atr_len && cachefioLoHiBalance[idx].EqualsInput(input))
						return cachefioLoHiBalance[idx];
			return CacheIndicator<fioLoHiBalance>(new fioLoHiBalance(){ fast_len = fast_len, slow_len = slow_len, sig_len = sig_len, atr_len = atr_len }, input, ref cachefioLoHiBalance);
		}
	}
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
	public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
	{
		public Indicators.fioLoHiBalance fioLoHiBalance(int fast_len, int slow_len, int sig_len, int atr_len)
		{
			return indicator.fioLoHiBalance(Input, fast_len, slow_len, sig_len, atr_len);
		}

		public Indicators.fioLoHiBalance fioLoHiBalance(ISeries<double> input , int fast_len, int slow_len, int sig_len, int atr_len)
		{
			return indicator.fioLoHiBalance(input, fast_len, slow_len, sig_len, atr_len);
		}
	}
}

namespace NinjaTrader.NinjaScript.Strategies
{
	public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
	{
		public Indicators.fioLoHiBalance fioLoHiBalance(int fast_len, int slow_len, int sig_len, int atr_len)
		{
			return indicator.fioLoHiBalance(Input, fast_len, slow_len, sig_len, atr_len);
		}

		public Indicators.fioLoHiBalance fioLoHiBalance(ISeries<double> input , int fast_len, int slow_len, int sig_len, int atr_len)
		{
			return indicator.fioLoHiBalance(input, fast_len, slow_len, sig_len, atr_len);
		}
	}
}

#endregion

Attached Files
Elite Membership required to download: fioLoHiBalance.cs
Reply With Quote




Last Updated on April 2, 2023


© 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