Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Converting Tradingview indicator (Trend Trader Strategy) to NT8 script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Converting Tradingview indicator (Trend Trader Strategy) to NT8 script

    I'm so sorry. I found this indicator script. I want to delete this but can't find where to delete. I will delete when I know.
    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;
    }
    }
    }
    }

    Last edited by coldfish52; 03-01-2023, 11:22 PM.

    #2
    Hello coldfish52,

    Welcome to the NinjaTrader forums!

    This thread will remain open for any community members that would like to create this script at your request as a convenience to you.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.


    Should you be interested in creating the script yourself, below I am providing a link to a forum post with helpful resources on getting started with NinjaScript and C#.
    https://ninjatrader.com/support/foru...pts#post786040

    From our experience at this time ChatGpt is not currently able to generate valid compilable NinjaScripts that function as the user has intentioned. We often find that the generated code will call non-existent properties and methods.

    I would recommend creating a blank indicator, adding any inputs or plots in the new indicator window, and then trying to copy and logic you are able into OnBarUpdate().

    If you have questions about specific errors, post the full error message and line of code and we would be happy to provide direction.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    571 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    331 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    549 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    550 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X