Indicator · Pine Script v5 · On the chart

Bakome Buy Sell

by BAKOME-Hub

This indicator plots a fast and a slow EMA, 5 and 13 by default, on the price chart and gives a buy or sell signal when they cross, optionally requiring the signal candle to close in the same direction.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code306
Settings10inputs
LicenceMIT
Last update5 months ago21 May 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

306 lines of Pine Script v5 from Bakome_Buy_Sell_Indicator_v5.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

Bakome_Buy_Sell_Indicator_v5.pine
//@version=5
indicator('Bakome buy sell mejor ', overlay=true)

// ============================================
// CONFIGURABLE PARAMETERS
// ============================================
emaFastLen = input.int(5, 'Fast EMA', minval=1)
emaSlowLen = input.int(13, 'Slow EMA', minval=1)
atrLen = input.int(14, 'ATR Period', minval=1)
atrMultSL = input.float(0.5, 'SL Multiplier (ATR)', minval=0.1, step=0.1)
riskReward = input.float(3.0, 'Risk:Reward (R:R)', minval=1.0, step=0.5)
confirmCandle = input.bool(true, 'Require candle confirmation')

// EMA Settings
showEmaFastLabel = input.bool(true, 'Show Fast EMA', group='EMAs')
emaFastColor = input.color(color.green, 'Fast EMA Color', group='EMAs')
showEmaSlowLabel = input.bool(true, 'Show Slow EMA', group='EMAs')
emaSlowColor = input.color(color.orange, 'Slow EMA Color', group='EMAs')

// ============================================
// EMA AND ATR CALCULATIONS
// ============================================
emaFast = ta.ema(close, emaFastLen)
emaSlow = ta.ema(close, emaSlowLen)
atr = ta.atr(atrLen)

// ============================================
// TREND LOGIC
// ============================================
bullTrend = emaFast > emaSlow
bearTrend = emaFast < emaSlow
trendChange = bullTrend != bullTrend[1]

// ============================================
// ENTRY SIGNALS
// ============================================
buyCondition1 = bullTrend and trendChange and close > open
sellCondition1 = bearTrend and trendChange and close < open
buyCondition2 = bullTrend and trendChange
sellCondition2 = bearTrend and trendChange

buySignal = confirmCandle ? buyCondition1 : buyCondition2
sellSignal = confirmCandle ? sellCondition1 : sellCondition2

// ============================================
// POSITION MANAGEMENT
// ============================================
var float entryPrice = na
var float stopLoss = na
var float takeProfitFinal = na
var bool inPosition = false
var string positionType = ''

// Arrays for intermediate TPs
var float[] tpLevels = array.new_float(0)
var bool[] tpHitFlags = array.new_bool(0)

// ============================================
// CLOSING POSITIONS
// ============================================
tpFinalHit = false
slHit = false
invalidated = false

// Check TP/SL in active position
if inPosition and positionType == 'LONG'
    if high >= takeProfitFinal
        tpFinalHit := true
        inPosition := false
        positionType := ''
    else if low <= stopLoss
        slHit := true
        inPosition := false
        positionType := ''

if inPosition and positionType == 'SHORT'
    if low <= takeProfitFinal
        tpFinalHit := true
        inPosition := false
        positionType := ''
    else if high >= stopLoss
        slHit := true
        inPosition := false
        positionType := ''

// Check intermediate TPs (mark only once)
if inPosition and array.size(tpLevels) > 0
    for i = 0 to array.size(tpLevels) - 1
        if not array.get(tpHitFlags, i)
            if positionType == 'LONG' and high >= array.get(tpLevels, i)
                array.set(tpHitFlags, i, true)
            else if positionType == 'SHORT' and low <= array.get(tpLevels, i)
                array.set(tpHitFlags, i, true)

// ============================================
// INVALIDATION AND NEW ENTRIES
// ============================================
// Variables to show signals
showBuySignal = false
showSellSignal = false
var string invalidatedType = ''

if buySignal
    // Only process if NO active LONG position
    if not inPosition or positionType != 'LONG'
        // Mark invalidation if there was a SHORT
        if inPosition and positionType == 'SHORT'
            invalidated := true
            invalidatedType := 'SELL'
            inPosition := false
        
        // New LONG entry
        entryPrice := close
        stopLoss := low - atr * atrMultSL
        risk = entryPrice - stopLoss
        takeProfitFinal := entryPrice + risk * riskReward
        
        // Create intermediate TPs
        array.clear(tpLevels)
        array.clear(tpHitFlags)
        numTPs = math.floor(riskReward)
        for i = 1 to numTPs - 1
            array.push(tpLevels, entryPrice + risk * i)
            array.push(tpHitFlags, false)
        
        inPosition := true
        positionType := 'LONG'
        showBuySignal := true

if sellSignal
    // Only process if NO active SHORT position
    if not inPosition or positionType != 'SHORT'
        // Mark invalidation if there was a LONG
        if inPosition and positionType == 'LONG'
            invalidated := true
            invalidatedType := 'BUY'
            inPosition := false
        
        // New SHORT entry
        entryPrice := close
        stopLoss := high + atr * atrMultSL
        risk = stopLoss - entryPrice
        takeProfitFinal := entryPrice - risk * riskReward
        
        // Create intermediate TPs
        array.clear(tpLevels)
        array.clear(tpHitFlags)
        numTPs = math.floor(riskReward)
        for i = 1 to numTPs - 1
            array.push(tpLevels, entryPrice - risk * i)
            array.push(tpHitFlags, false)
        
        inPosition := true
        positionType := 'SHORT'
        showSellSignal := true

// ============================================
// VISUALIZATION
// ============================================
// EMAs
plot(emaFast, title='Fast EMA', color=color.new(emaFastColor, 0), linewidth=1, 
     display=showEmaFastLabel ? display.all : display.none)
plot(emaSlow, title='Slow EMA', color=color.new(emaSlowColor, 0), linewidth=1, 
     display=showEmaSlowLabel ? display.all : display.none)

// Entry Signals - KEY CHANGE: use showBuySignal and showSellSignal
plotshape(showBuySignal, 'BUY Signal', shape.labelup, location.belowbar, 
     color.new(color.lime, 0), text='BUY', textcolor=color.white, size=size.small)
plotshape(showSellSignal, 'SELL Signal', shape.labeldown, location.abovebar, 
     color.new(color.red, 0), text='SELL', textcolor=color.white, size=size.small)

// Final TP and SL
plotshape(tpFinalHit, 'FINAL TAKE PROFIT', shape.circle, location.abovebar, 
     color.new(#00ff00, 0), text='🎯 TP', 
     textcolor=#00ff00, size=size.small)

plotshape(slHit, 'STOP LOSS', shape.xcross, location.belowbar, 
     color.new(#ff0000, 0), text='SL', textcolor=color.white, size=size.small)

// Separate invalidation signals
plotshape(invalidated and invalidatedType == 'BUY', 'INVALIDATED BUY', shape.diamond, location.abovebar, 
     color.new(color.yellow, 0), text='INV BUY', textcolor=color.rgb(97, 100, 107), size=size.tiny)
plotshape(invalidated and invalidatedType == 'SELL', 'INVALIDATED SELL', shape.diamond, location.abovebar, 
     color.new(color.yellow, 0), text='INV SELL', textcolor=color.rgb(97, 100, 107), size=size.tiny)

// Intermediate TPs (mark only the first time reached)
var bool[] tpAlreadyMarked = array.new_bool(0)

// Initialize marker array when there is a new position
if showBuySignal or showSellSignal
    array.clear(tpAlreadyMarked)
    numTPs = math.floor(riskReward)
    for i = 1 to numTPs - 1
        array.push(tpAlreadyMarked, false)

// Show labels only once per TP
if inPosition and array.size(tpHitFlags) > 0 and array.size(tpAlreadyMarked) > 0
    for i = 0 to array.size(tpHitFlags) - 1
        // If TP is hit AND has not been marked before
        if array.get(tpHitFlags, i) and not array.get(tpAlreadyMarked, i)
            label.new(bar_index, high, 
                 'TP' + str.tostring(i + 1), 
                 style=label.style_label_down, 
                 color=color.new(color.green, 50), 
                 textcolor=color.white, 
                 size=size.tiny,
                 yloc=yloc.abovebar)
            array.set(tpAlreadyMarked, i, true)

// Risk management lines
var line entryLine = na
var line slLine = na
var line tpLineFinal = na
var line[] tpIntermediateLines = array.new_line(0)

if inPosition and positionType != ''
    // Entry
    if na(entryLine)
        entryLine := line.new(bar_index - 10, entryPrice, bar_index + 10, entryPrice, 
             color=color.new(color.white, 0), width=1, style=line.style_dashed)
    else
        line.set_xy1(entryLine, bar_index - 10, entryPrice)
        line.set_xy2(entryLine, bar_index + 10, entryPrice)
    
    // Stop Loss
    if na(slLine)
        slLine := line.new(bar_index, stopLoss, bar_index + 1, stopLoss, 
             color=color.new(color.red, 0), width=2)
    else
        line.set_xy1(slLine, bar_index, stopLoss)
        line.set_xy2(slLine, bar_index + 1, stopLoss)
    
    // Final Take Profit
    if na(tpLineFinal)
        tpLineFinal := line.new(bar_index, takeProfitFinal, bar_index + 1, takeProfitFinal, 
             color=color.new(color.green, 0), width=2)
    else
        line.set_xy1(tpLineFinal, bar_index, takeProfitFinal)
        line.set_xy2(tpLineFinal, bar_index + 1, takeProfitFinal)
    
    // Intermediate TPs (soft green lines)
    if array.size(tpIntermediateLines) == 0 and array.size(tpLevels) > 0
        for i = 0 to array.size(tpLevels) - 1
            tpLine = line.new(bar_index, array.get(tpLevels, i), bar_index + 1, 
                 array.get(tpLevels, i), color=color.new(color.green, 60), 
                 width=1, style=line.style_dotted)
            array.push(tpIntermediateLines, tpLine)
    else if array.size(tpIntermediateLines) > 0
        for i = 0 to array.size(tpIntermediateLines) - 1
            line.set_xy1(array.get(tpIntermediateLines, i), bar_index, array.get(tpLevels, i))
            line.set_xy2(array.get(tpIntermediateLines, i), bar_index + 1, array.get(tpLevels, i))
else
    if not na(entryLine)
        line.delete(entryLine)
        entryLine := na
    if not na(slLine)
        line.delete(slLine)
        slLine := na
    if not na(tpLineFinal)
        line.delete(tpLineFinal)
        tpLineFinal := na
    if array.size(tpIntermediateLines) > 0
        for i = 0 to array.size(tpIntermediateLines) - 1
            line.delete(array.get(tpIntermediateLines, i))
        array.clear(tpIntermediateLines)

// ============================================
// INFO TABLE
// ============================================
var table infoTable = table.new(position.top_right, 2, 5, 
     bgcolor=color.new(color.black, 85), border_width=1)

if barstate.islast
    table.cell(infoTable, 0, 0, 'Status:', text_color=color.white, text_size=size.small)
    table.cell(infoTable, 1, 0, inPosition ? positionType : 'No Position', 
          text_color=inPosition ? color.yellow : color.gray, text_size=size.small)
    
    if inPosition
        table.cell(infoTable, 0, 1, 'Entry:', text_color=color.white, text_size=size.small)
        table.cell(infoTable, 1, 1, str.tostring(entryPrice, '#.##'), 
             text_color=color.white, text_size=size.small)
        
        table.cell(infoTable, 0, 2, 'Stop Loss:', text_color=color.white, text_size=size.small)
        table.cell(infoTable, 1, 2, str.tostring(stopLoss, '#.##'), 
             text_color=color.red, text_size=size.small)
        
        table.cell(infoTable, 0, 3, 'Take Profit:', text_color=color.white, text_size=size.small)
        table.cell(infoTable, 1, 3, str.tostring(takeProfitFinal, '#.##'), 
             text_color=color.green, text_size=size.small)
        
        riskVal = math.abs(entryPrice - stopLoss)
        rewardVal = math.abs(takeProfitFinal - entryPrice)
        currentRR = rewardVal / riskVal
        
        table.cell(infoTable, 0, 4, 'R:R:', text_color=color.white, text_size=size.small)
        table.cell(infoTable, 1, 4, str.tostring(currentRR, '#.##') + ':1', 
             text_color=color.orange, text_size=size.small)

// ============================================
// ALERTS
// ============================================
alertcondition(showBuySignal, '🟢 BUY Signal', '📈 BUY on {{ticker}} | Price: {{close}}')
alertcondition(showSellSignal, '🔎 SELL Signal', '📉 SELL on {{ticker}} | Price: {{close}}')
alertcondition(tpFinalHit, '🎯 Final Take Profit', '✅ Final TP hit on {{ticker}} | Price: {{close}}')
alertcondition(slHit, '❌ Stop Loss', '🛑 SL triggered on {{ticker}} | Price: {{close}}')
alertcondition(invalidated, '⚠ Entry Invalidated', '⚠ Previous entry invalidated on {{ticker}} | New signal detected')

Overview

For each signal it draws an entry, an ATR-based stop loss and a final take profit set by a risk-reward ratio, with dotted intermediate target lines. An info table shows status and levels, and alerts cover signals, targets, stops and invalidation by an opposite signal.

Details

Published by

BAKOME-Hub on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Moving averages, Trend

Markets

Gold, Forex, Indices

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Fast EMAint5emaFastLen
Slow EMAint13emaSlowLen
ATR Periodint14atrLen
SL Multiplier (ATR)float0.5atrMultSL
Risk:Reward (R:R)float3.0riskReward
Require candle confirmationbooltrueconfirmCandle
Show Fast EMAbooltrueshowEmaFastLabel
Fast EMA Colorcolorcolor.greenemaFastColor
Show Slow EMAbooltrueshowEmaSlowLabel
Slow EMA Colorcolorcolor.orangeemaSlowColor
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec

Indicator v4 TrendMoving averages
Updated 11 days ago · GPL-3.0 GitHub repository of Adaptive Laguerre Filter
330 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
318 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 2 months ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
277 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated 2 days ago · MIT GitHub repository of NVDA Trend Ribbon
257 stars

Donald SPX - Options Trading is an overlay indicator designed for intraday SPX analysis. It plots a 200-period Weighted Moving Average (WMA) on the price chart while evaluating multi-timeframe market structure across Daily, 15-minute, 5-minute, and 2-minute ba

Indicator v5 Moving averagesTrend Repaints
Updated 6 weeks ago · None stated GitHub repository of Donald SPX - Options Trading

60K均線

by TaichiS
219 stars

This multi-timeframe indicator calculates and plots 20-period and 60-period simple moving averages from the 60-minute timeframe directly onto the price chart. The 20-period average displays as a green line, while the 60-period average appears in blue. It serve

Indicator v4 Moving averagesTrend Repaints
Updated 5 years ago · None stated GitHub repository of 60K均線

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers