Search code examples
pine-scriptpine-script-v5tradingalgorithmic-trading

How to highlight the price when a candle crosses the previous candle which is closed above EMA100 line?


I'm new to pine script and I am trying to figure out how to make an indicator highlighting:

Price when the current candle cross below the wick low of previous candle + previous candle should be completely detached (even the wick) above the EMA100 line

Please help anyone :)

I tried something like this but it doesn't work :(

ema100 = ta.ema(close, 100) emaGapBelow = high < ema100 emaGapAbove = low > ema100 entryCandle = close < emaGapAbove

plotshape(entryCandle)


Solution

  • In pinescript the number in brackets is used to acces previous data. For example to get the previous low, you use :

    low[1]
    

    For your code, you should try :

    ema100 = ta.ema(close,100)
    currentcrossbelow = close < low[1]
    previousdetached = low[1] > ema100[1]
    
    if currentcrossbelow and previousdetached
        // Here, your conditions are met