indicator with exrem function (Pine script)

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #225979 quote
    srheufke
    Participant
    New
    I've found this code to remove excessive signals through exrem (Buy,Sell) function. How to translate the exrem section and further?
    
    //@version=5
    indicator(title='SuperTrend + MACD + EMA', overlay=true)
    
    //EMA
    fast_ema = ta.ema(close, 9)
    slow_ema = ta.ema(close, 18)
    plot(series=fast_ema, title='Fast EMA', color=#00FFFF, linewidth=1)
    plot(series=slow_ema, title='Slow EMA', color=#FF00FF, linewidth=1)
    
    //MACD
    fastInput = 12
    slowInput = 26
    [macdLine, signalLine, histLine] = ta.macd(close, fastInput, slowInput, 9)
    
    //Supertrend
    atrPeriod = 10
    factor = 3
    [supertrend, direction] = ta.supertrend(factor, atrPeriod)
    linecolor = direction < 0 ? #00ff00 : #ff0000
    plot(series=supertrend, title='Supertrend', color=linecolor, linewidth=1)
    
    // Conditions
    long_condition = barstate.isconfirmed and
                     fast_ema > slow_ema and
                     macdLine > signalLine and
                     close > supertrend
    
    short_condition = barstate.isconfirmed and
                     fast_ema < slow_ema and
                     macdLine < signalLine and
                     close < supertrend
    
    // Function to Remove Excessive Signals
    exrem(condition_1, condition_2) =>
        var entry_signal = 0
        entry_signal := condition_1 ? 1 : condition_2 ? -1 : entry_signal[1]
        entry = entry_signal != entry_signal[1]
        buy = entry and entry_signal == 1
        sell = entry and entry_signal == -1
        [buy, sell]
    
    // Signals
    [long_signal, short_signal] = exrem(long_condition, short_condition)
    
    // Plot
    plotshape(long_signal, style=shape.triangleup, color=#00FF00, text='BUY', textcolor=#FFFFFF, editable=false, location=location.belowbar, size=size.small)
    plotshape(short_signal, style=shape.triangledown, color=#FF0000, text='SELL', textcolor=#FFFFFF, editable=false, location=location.abovebar, size=size.small)
    
    #226001 quote
    jacquesgermain
    Participant
    Senior

    //below my conversion of your indicator :

    once signal=0
    //EMA
    fastema = ExponentialAverage[9](close)
    slowema = ExponentialAverage[18](close)

    //MACD
    macdl=MACDline[12,26,9](close)
    //Supertrend
    ST=Supertrend[3,10]
    // Conditions
    conditionA =st>=ST[1] and fastema > slowema and macdL > MACDSignal[12,26,9](close) and close > supertrend
    conditionb=st<ST[1]and fastema < slowema and macdL < MACDSignal[12,26,9](close) and close < supertrend
    if conditionA and not conditionA[1] then
    signal=1
    endif
    if conditionB and not conditionB[1] then
    signal=2
    endif
    if signal=1 and signal[1]=2 then
    DRAWARROWUP(barindex,ST)coloured(0,0,255)
    endif
    if signal=2 and signal[1]=1 then
    DRAWARROWDOWN(barindex,ST)coloured(255,0,0)
    endif
    return ST as “supertrend”

    srheufke, Msport71 and KumoNoJuzza thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

indicator with exrem function (Pine script)


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
srheufke @srheufke Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by jacquesgermain
2 years, 1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 01/05/2024
Status: Active
Attachments: 1 files
Logo Logo
Loading...