Aleem trend indicator

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #250129 quote
    Stenozar
    Participant
    Master

    Ciao, chiedo la traduzione se possibile di un indicatore che pare interessante.

     

    //@version=5
    indicator(“Aleem Trend”, overlay=true)

    // Inputs for Supertrend and EMA
    atrLength = input.int(10, “ATR Length for Supertrend”, minval=1)
    factor = input.float(3.0, “Factor for Supertrend”, minval=0.1)
    length = input.int(200, “EMA Length”, minval=1)
    showStrend = input(false, title=”Show Supertrend Line”)
    showEma200 = input(false, title=”Show 200 EMA Line”)

    // EMA and Supertrend Calculations
    ema200 = ta.ema(close, length)
    [strend, _] = ta.supertrend(factor, atrLength)

    // Supertrend Direction
    bullish = strend < close
    bearish = strend > close

    // Define the crossing of the 200 EMA
    crossedAbove200EMA = (close > ema200) and (close[1] <= ema200)
    crossedBelow200EMA = (close < ema200) and (close[1] >= ema200)

    // Exit Signals
    trendChangeToBearish = bearish and not bearish[1]
    trendChangeToBullish = bullish and not bullish[1]

    var bool alreadyBought = false // This variable will track if we’ve already bought
    var bool alreadySold = false // This variable will track if we’ve already sold

    // Reset the buy/sell signal when the opposite signal is triggered
    if trendChangeToBearish
    alreadyBought := false
    if trendChangeToBullish
    alreadySold := false

    // Buy Signal
    buySignal = not alreadyBought and ((crossedAbove200EMA and bullish) or (trendChangeToBullish and close > ema200))
    if buySignal
    alreadyBought := true // Set the flag to true when buy signal is triggered

    // Sell Signal
    sellSignal = not alreadySold and ((crossedBelow200EMA and bearish) or (trendChangeToBearish and close < ema200))
    if sellSignal
    alreadySold := true // Set the flag to true when sell signal is triggered

    // Exit Buy Signal
    exitBuySignal = trendChangeToBearish and close > ema200
    if exitBuySignal
    alreadyBought := false // Reset the flag when exiting the buy

    // Exit Sell Signal
    exitSellSignal = trendChangeToBullish and close < ema200
    if exitSellSignal
    alreadySold := false // Reset the flag when exiting the sell

    // Signal Plots
    plotshape(series=buySignal, title=”Buy Signal”, location=location.belowbar, color=color.green, style=shape.labelup, text=”BUY”)
    plotshape(series=sellSignal, title=”Sell Signal”, location=location.abovebar, color=color.red, style=shape.labeldown, text=”SELL”)
    plotshape(series=exitBuySignal, title=”Exit Buy Signal”, location=location.abovebar, color=color.orange, style=shape.xcross, text=”EXIT”)
    plotshape(series=exitSellSignal, title=”Exit Sell Signal”, location=location.belowbar, color=color.orange, style=shape.xcross, text=”EXIT”)

    // Plot Supertrend and 200 EMA based on user input
    plot(showStrend ? strend : na, color=strend < close ? color.green : color.red, title=”Supertrend”, linewidth=2)
    plot(showEma200 ? ema200 : na, color=color.blue, title=”200 EMA”, linewidth=1)

    #250137 quote
    Iván González
    Moderator
    Master

    ecco qui:

    //-----------------------------------------//
    // PRC_Aleem Trend (by Aleemullahkhan)
    // version = 0
    // 28.08.2025
    // Iván González @ www.prorealcode.com
    // Sharing ProRealTime knowledge
    //-----------------------------------------//
    // --- Parámetros Configurables ---
    //-----------------------------------------//
    ONCE atrLength = 10       // Longitud ATR para Supertrend
    ONCE factor = 3.0         // Factor para Supertrend
    ONCE length = 200         // Longitud de la EMA
    ONCE showStrend = 1       // 1=Sí, 0=No - Mostrar Línea Supertrend
    ONCE showEma200 = 1       // 1=Sí, 0=No - Mostrar Línea EMA 200
    //-----------------------------------------//
    // --- Cálculos Principales ---
    //-----------------------------------------//
    ema200 = ExponentialAverage[length](close)
    strend = Supertrend[factor, atrLength]
    
    // --- Definición de la Dirección de la Tendencia ---
    bullish = (strend < close)
    bearish = (strend > close)
    
    // --- Detección de Cruces y Cambios de Tendencia ---
    crossedAbove200EMA = (close CROSSES OVER ema200)
    crossedBelow200EMA = (close CROSSES UNDER ema200)
    trendChangeToBearish = (bearish AND NOT bearish[1])
    trendChangeToBullish = (bullish AND NOT bullish[1])
    
    // --- Variables de Estado para Evitar Señales Repetidas ---
    ONCE alreadyBought = 0 // 1=Comprado, 0=No comprado
    ONCE alreadySold = 0   // 1=Vendido, 0=No vendido
    
    // --- Lógica de Reseteo de las Banderas ---
    IF trendChangeToBearish THEN
    alreadyBought = 0
    ENDIF
    
    IF trendChangeToBullish THEN
    alreadySold = 0
    ENDIF
    //-----------------------------------------//
    // --- Lógica de Señales de Entrada ---
    //-----------------------------------------//
    // Señal de Compra
    buySignal = (alreadyBought = 0) AND ((crossedAbove200EMA AND bullish) OR (trendChangeToBullish AND close > ema200))
    IF buySignal THEN
    alreadyBought = 1 // Activa la bandera para no volver a comprar
    ENDIF
    
    // Señal de Venta
    sellSignal = (alreadySold = 0) AND ((crossedBelow200EMA AND bearish) OR (trendChangeToBearish AND close < ema200))
    IF sellSignal THEN
    alreadySold = 1 // Activa la bandera para no volver a vender
    ENDIF
    
    //-----------------------------------------//
    // --- Lógica de Señales de Salida ---
    //-----------------------------------------//
    // Señal de Salida de Compra (cuando la Supertrend se vuelve bajista)
    exitBuySignal = trendChangeToBearish AND close > ema200
    IF exitBuySignal THEN
    alreadyBought = 0 // Resetea la bandera al salir
    ENDIF
    
    // Señal de Salida de Venta (cuando la Supertrend se vuelve alcista)
    exitSellSignal = trendChangeToBullish AND close < ema200
    IF exitSellSignal THEN
    alreadySold = 0 // Resetea la bandera al salir
    ENDIF
    //-----------------------------------------//
    // --- Dibujo de las Señales en el Gráfico ---
    //-----------------------------------------//
    offset = AverageTrueRange[14] * 0.5
    
    IF buySignal THEN
    DRAWARROWUP(barindex, low - offset) COLOURED("green")
    DRAWTEXT("BUY", barindex, low - offset * 2) COLOURED("green")
    ENDIF
    
    IF sellSignal THEN
    DRAWARROWDOWN(barindex, high + offset) COLOURED("red")
    DRAWTEXT("SELL", barindex, high + offset * 2) COLOURED("red")
    ENDIF
    
    IF exitBuySignal THEN
    DRAWTEXT("X", barindex, high + offset, sansserif,bold,20) COLOURED("orange")
    ENDIF
    
    IF exitSellSignal THEN
    DRAWTEXT("X", barindex, low - offset,sansserif,bold,20) COLOURED("orange")
    ENDIF
    //-----------------------------------------//
    // --- Dibujo Condicional de las Líneas ---
    //-----------------------------------------//
    plotStrend = UNDEFINED
    plotEma200 = UNDEFINED
    
    IF showStrend = 1 THEN
    plotStrend = strend
    ENDIF
    
    IF showEma200 = 1 THEN
    plotEma200 = ema200
    ENDIF
    
    // Coloreado dinámico para la línea de Supertrend
    strendColorR = 0
    strendColorG = 0
    strendColorB = 0
    
    IF bullish THEN
    strendColorR = 0
    strendColorG = 200
    strendColorB = 0
    ELSE
    strendColorR = 255
    strendColorG = 0
    strendColorB = 0
    ENDIF
    
    //-----------------------------------------//
    RETURN plotStrend COLOURED(strendColorR, strendColorG, strendColorB) AS "Supertrend", plotEma200 COLOURED("blue") AS "EMA 200"
    
    robertogozzi thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Aleem trend indicator


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
Stenozar @stenozar Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván González
5 months, 1 week ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 08/27/2025
Status: Active
Attachments: No files
Logo Logo
Loading...