The problem seems to be with the IF statement in OnBarUpdate(). None of the suggestions CoPilot gave me worked so here I am looking for a kind-hearted coder

Here's the pine script and ninjascript code. Thanks.
Pinescript
//@version=4 study(title="Fisher Transform with Distance from EMA", shorttitle="Fisher Distance from EMA", format=format.price, precision=2, resolution="") len = input(9, minval=1, title="Fisher Transform Length") emaLength = input(title="EMA Length", defval=50, type=input.integer) emaValue = ema(close*100000000, emaLength) distFromEMA = (close*100000000 - emaValue) high_ = highest(distFromEMA, len) low_ = lowest(distFromEMA, len) round_(val) => val > .99 ? .999 : val < -.99 ? -.999 : val value = 0.0 value := round_(.66 * ((distFromEMA - low_) / max(high_ - low_, .001) - .5) + .67 * nz(value[1])) fish1 = 0.0 fish1 := .5 * log((1 + value) / max(1 - value, .001)) + .5 * nz(fish1[1]) fish2 = fish1[1] hline(1.5, "1.5", color=#FFC5B5) hline(0.75,"0.75", color=#C6C6C6) hline(0, "0", color=#FFC5B5) hline(-0.75, "-0.75", color=#C6C6C6) hline(-1.5, "-1.5", color=#FFC5B5) plot(fish1, color=#0094FF, title="Fisher") plot(fish2, color=#FFD800, title="Trigger")
#region Using declarations
using System;
using System.ComponentModel;
using System.Windows.Media;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
using System.Xml.Serialization;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class FisherTransformWithDistanceFromEMA : Indicator
{
private int len = 9;
private int emaLength = 50;
private EMA ema;
private Series<double> distFromEMA;
private Series<double> value;
private Series<double> fish1;
private Series<double> fish2;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Fisher Transform with Distance from EMA";
Name = "Fisher Transform with Distance from EMA";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
}
else if (State == State.Configure)
{
ema = EMA(Close, emaLength);
distFromEMA = new Series<double>(this);
value = new Series<double>(this);
fish1 = new Series<double>(this);
fish2 = new Series<double>(this);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar >= len) return;
distFromEMA[0] = Close[0] * 100000000 - ema[0];
double high = MAX(distFromEMA, len)[0];
double low = MIN(distFromEMA, len)[0];
value[0] = Math.Min(Math.Max(.66 * ((distFromEMA[0] - low) / Math.Max(high - low, .001) - .5) + .67 * value[1], -.999), .999);
fish1[0] = .5 * Math.Log((1 + value[0]) / Math.Max(1 - value[0], .001)) + .5 * fish1[1];
fish2[0] = fish1[1];
PlotBrushes[0][0] = Brushes.Blue;
PlotBrushes[1][0] = Brushes.Yellow;
Values[0][0] = fish1[0];
Values[1][0] = fish2[0];
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> Fisher { get { return Values[0]; } }
[Browsable(false)]
[XmlIgnore]
public Series<double> Trigger { get { return Values[1]; } }
#endregion
}
}

Comment