Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Creating a new indicator..

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

    Creating a new indicator..

    Hello everyone, I wish you good work. The reason why I opened this topic; The 2 indicators I use are not available in Ninjatrader. I'm tired of paying other software programs to access these indicators, which I find very useful when investing.I have no coding knowledge. My 3 week attempts were unsuccessful..
    I am attaching the codes of the indicators.


    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    1 : Follow line indicator:

    --((Explanation=The FollowLine indicator is a trend following indicator. The blue/red lines are activated when the price closes above the upper Bollinger band or below the lower one.

    Once the trigger of the trend direction is made, the FollowLine will be placed at High or Low (depending of the trend).

    An ATR filter can be selected to place the line at a more distance level than the normal mode settled at candles Highs/Lows.))--

    1.1= Source code

    study(shorttitle="FLI", title="Follow Line Indicator", overlay=true)
    //
    BBperiod = input(defval = 21, title = "BB Period", type = input.integer, minval = 1)
    BBdeviations = input(defval = 1.00, title = "BB Deviations", type = input.float, minval = 0.1, step=0.05)
    UseATRfilter = input(defval = true, title = "ATR Filter", type = input.bool)
    ATRperiod = input(defval = 5, title = "ATR Period", type = input.integer, minval = 1)
    hl = input(defval = false, title = "Hide Labels", type = input.bool)
    //
    BBUpper=sma (close,BBperiod)+stdev(close, BBperiod)*BBdeviations
    BBLower=sma (close,BBperiod)-stdev(close, BBperiod)*BBdeviations
    //
    TrendLine = 0.0
    iTrend = 0.0
    buy = 0.0
    sell = 0.0
    //
    BBSignal = close>BBUpper? 1 : close<BBLower? -1 : 0
    //
    if BBSignal == 1 and UseATRfilter == 1
    TrendLine:=low-atr(ATRperiod)
    if TrendLine<TrendLine[1]
    TrendLine:=TrendLine[1]
    if BBSignal == -1 and UseATRfilter == 1
    TrendLine:=high+atr(ATRperiod)
    if TrendLine>TrendLine[1]
    TrendLine:=TrendLine[1]
    if BBSignal == 0 and UseATRfilter == 1
    TrendLine:=TrendLine[1]
    //
    if BBSignal == 1 and UseATRfilter == 0
    TrendLine:=low
    if TrendLine<TrendLine[1]
    TrendLine:=TrendLine[1]
    if BBSignal == -1 and UseATRfilter == 0
    TrendLine:=high
    if TrendLine>TrendLine[1]
    TrendLine:=TrendLine[1]
    if BBSignal == 0 and UseATRfilter == 0
    TrendLine:=TrendLine[1]
    //
    iTrend:=iTrend[1]
    if TrendLine>TrendLine[1]
    iTrend:=1
    if TrendLine<TrendLine[1]
    iTrend:=-1
    //
    buy:=iTrend[1]==-1 and iTrend==1 ? 1 : na
    sell:=iTrend[1]==1 and iTrend==-1? 1 : na
    //
    plot(TrendLine, color=iTrend > 0?color.blue:color.red ,style=plot.style_line,linewidth=2,transp=0,title= "Trend Line")
    plotshape(buy == 1 and hl == false? TrendLine-atr(8) :na, text='', style= shape.labelup, location=location.absolute, color=color.blue, textcolor=color.white, offset=0, transp=0,size=size.auto)
    plotshape(sell == 1 and hl == false ?TrendLine+atr(8):na, text='', style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, offset=0, transp=0,size=size.auto)
    //
    alertcondition(sell == 1 ,title="Sell",message="Sell")
    alertcondition(buy == 1 ,title="Buy",message="Buy")
    alertcondition(buy == 1 or sell == 1 ,title="Buy/Sell",message="Buy/Sell")

    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    2. Half trend indicator
    --((Explanation=A popular trend indicator based on ATR. Similar to the SuperTrend but uses a different trend's identification logic.))--

    2.1 Source code =

    study("HalfTrend", overlay=true)

    amplitude = input(title="Amplitude", defval=2)
    channelDeviation = input(title="Channel Deviation", defval=2)
    showArrows = input(title="Show Arrows", defval=true)
    showChannels = input(title="Show Channels", defval=true)

    var int trend = 0
    var int nextTrend = 0
    var float maxLowPrice = nz(low[1], low)
    var float minHighPrice = nz(high[1], high)

    var float up = 0.0
    var float down = 0.0
    float atrHigh = 0.0
    float atrLow = 0.0
    float arrowUp = na
    float arrowDown = na

    atr2 = atr(100) / 2
    dev = channelDeviation * atr2

    highPrice = high[abs(highestbars(amplitude))]
    lowPrice = low[abs(lowestbars(amplitude))]
    highma = sma(high, amplitude)
    lowma = sma(low, amplitude)

    if nextTrend == 1
    maxLowPrice := max(lowPrice, maxLowPrice)

    if highma < maxLowPrice and close < nz(low[1], low)
    trend := 1
    nextTrend := 0
    minHighPrice := highPrice
    else
    minHighPrice := min(highPrice, minHighPrice)

    if lowma > minHighPrice and close > nz(high[1], high)
    trend := 0
    nextTrend := 1
    maxLowPrice := lowPrice

    if trend == 0
    if not na(trend[1]) and trend[1] != 0
    up := na(down[1]) ? down : down[1]
    arrowUp := up - atr2
    else
    up := na(up[1]) ? maxLowPrice : max(maxLowPrice, up[1])
    atrHigh := up + dev
    atrLow := up - dev
    else
    if not na(trend[1]) and trend[1] != 1
    down := na(up[1]) ? up : up[1]
    arrowDown := down + atr2
    else
    down := na(down[1]) ? minHighPrice : min(minHighPrice, down[1])
    atrHigh := down + dev
    atrLow := down - dev

    ht = trend == 0 ? up : down

    var color buyColor = color.blue
    var color sellColor = color.red

    htColor = trend == 0 ? buyColor : sellColor
    htPlot = plot(ht, title="HalfTrend", linewidth=2, color=htColor)

    atrHighPlot = plot(showChannels ? atrHigh : na, title="ATR High", style=plot.style_circles, color=sellColor)
    atrLowPlot = plot(showChannels ? atrLow : na, title="ATR Low", style=plot.style_circles, color=buyColor)

    fill(htPlot, atrHighPlot, title="ATR High Ribbon", color=sellColor)
    fill(htPlot, atrLowPlot, title="ATR Low Ribbon", color=buyColor)

    buySignal = not na(arrowUp) and (trend == 0 and trend[1] == 1)
    sellSignal = not na(arrowDown) and (trend == 1 and trend[1] == 0)

    plotshape(showArrows and buySignal ? atrLow : na, title="Arrow Up", style=shape.triangleup, location=location.absolute, size=size.tiny, color=buyColor)
    plotshape(showArrows and sellSignal ? atrHigh : na, title="Arrow Down", style=shape.triangledown, location=location.absolute, size=size.tiny, color=sellColor)

    alertcondition(buySignal, title="Alert: HalfTrend Buy", message="HalfTrend Buy")
    alertcondition(sellSignal, title="Alert: HalfTrend Sell", message="HalfTrend Sell")

    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    I am ready to prepare resources to separate the confusion.. These indicators are very important to me. We have to achieve this goal..

    When I tried to write these codes in ninjascript, I couldn't. Dear ninjatrader users can benefit if we create these indicators and add them to the ecosystem. In this way, we make successful investments with the power of ninjatrader without paying for other software.

    With love..




    #2
    Hi Trader-yE, thanks for posting and welcome to the NinjaTrader forums.

    The support team will not be able to do custom conversions, but this topic will remain open indefinitely for community members that wish to contribute.

    Kind regards,
    -ChrisL

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    647 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    369 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    572 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X