Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Convert from Pine to NT8? Excellent Divergence Entries
Updated April 2, 2023
trending_up
602 views
thumb_up
0 thanks given
group
2 followers
forum
1 posts
attach_file
1 attachments
Convert from Pine to NT8? Excellent Divergence Entries
March 30th, 2023, 11:51 AM
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)
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
April 2nd, 2023, 12:17 PM
Posts: 74 since Jan 2020
Thanks Given: 23
Thanks Received: 44
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
Last Updated on April 2, 2023