Thank you.
There is an indicator from Tradingview user HPotter called "Trend Trader Strategy" originally developed by Andrew Abraham in 1998. I am using this indicator from the Tradingview and want to use it from the NT8, too.
I asked chatGPT to convert this and got some result but getting an error when compiling.
Below is the pine script for Tradingview.
indicator(title='Trend Trader Strategy', overlay=true)
Length = input.int(21, minval=1)
Multiplier = input.float(3, minval=0.000001)
avgTR = ta.wma(ta.atr(1), Length)
highestC = ta.highest(Length)
lowestC = ta.lowest(Length)
hiLimit = highestC[1] - avgTR[1] * Multiplier
loLimit = lowestC[1] + avgTR[1] * Multiplier
ret = 0.0
pos = 0.0
ret:= close > hiLimit and close > loLimit ? hiLimit :
close < loLimit and close < hiLimit ? loLimit : nz(ret[1], close)
pos:= close > ret ? 1 :close < ret ? -1 : nz(pos[1], 0)
if pos != pos[1] and pos == 1
alert("Color changed - Buy", alert.freq_once_per_bar_close)
if pos != pos[1] and pos == -1
alert("Color changed - Sell", alert.freq_once_per_bar_close)
barcolor(pos == -1 ? color.red : pos == 1 ? color.green : color.blue)
plot(ret, color=color.new(color.blue, 0), title='Trend Trader Strategy')
Then below is a conversion from the chatGPT but when I copy below code, NT8 script editor add more lines(180 lines total) and getting an error when I did compile.
Anyone can help me to convert this indicator to NT8 script? I don't really need to change the bar color like the tradingview indicator but at least can get a TTS indicator line on the chart.
THANK YOU!
using System;
using System.Drawing;
using NinjaTrader.NinjaScript;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
namespace NinjaTrader.NinjaScript.Strategies
{
public class TrendTraderStrategy : NinjaTrader.NinjaScript.Strategy
{
private int length;
private double multiplier;
private WMA avgTR;
private Highest highestC;
private Lowest lowestC;
private double hiLimit;
private double loLimit;
private double ret;
private int pos;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Trend Trader Strategy";
Name = "TrendTraderStrategy";
IsOverlay = true;
AddDataSeries(Data.BarsPeriodType.Minute, 1);
AddDataSeries(Data.BarsPeriodType.Minute, 60);
length = 21;
multiplier = 3;
avgTR = WMA(ATR(1), length);
highestC = Highest(Length);
lowestC = Lowest(Length);
hiLimit = highestC[1] - avgTR[1] * multiplier;
loLimit = lowestC[1] + avgTR[1] * multiplier;
ret = 0;
pos = 0;
}
}
protected override void OnBarUpdate()
{
ret = Close[0] > hiLimit && Close[0] > loLimit ? hiLimit :
Close[0] < loLimit && Close[0] < hiLimit ? loLimit : ret[1];
pos = Close[0] > ret ? 1 : Close[0] < ret ? -1 : pos[1];
if (pos != pos[1] && pos == 1)
Alert("Color changed - Buy", NinjaTrader.NinjaScript.Alert.FrequencyOncePerBarC lose);
if (pos != pos[1] && pos == -1)
Alert("Color changed - Sell", NinjaTrader.NinjaScript.Alert.FrequencyOncePerBarC lose);
BarColor = pos == -1 ? Color.Red : pos == 1 ? Color.Green : Color.Blue;
}
[NinjaTrader.NinjaScript.DrawingTools.DisplayName(" Trend Trader Strategy")]
public class TrendTraderStrategyPlot : Plot
{
protected override void OnCalculate()
{
Value[0] = ret;
}
}
TrendTraderStrategyPlot trendTraderStrategy;
[NinjaTrader.NinjaScript.Browsable(false)]
[Xml.Serialization.XmlIgnore]
public TrendTraderStrategyPlot TrendTraderStrategy
{
get
{
if (trendTraderStrategy == null)
trendTraderStrategy = new TrendTraderStrategyPlot();
return trendTraderStrategy;
}
}
}
}

Comment