JaCrispy
JaCrispy

Reputation: 3

Incorporating open-source indicator into your strategy that pine doesn't have a built-in function for

I'm trying to create a pine strategy making use of the Chandelier Exit indicator. CE indicator plots a "Buy" and "Sell" notice on the chart at optimal conditions. How can I get my strategy to acknowledge these? From what I understand, the CE indicator is based on ATR. I hope I don't have to recreate the CE indicator from scratch using ta.atr.

I see a bunch of built in indicator functions to make use of such as ta.crossover, ta.ema, ta.macd, etc... But how to you incorporate an indicator into your strategy such as CE that doesn't have a built in function? The Indicator name seems to be 'CE (22,3)' and in the alert window the alert is called 'CE Buy'

Indicator is open source - here's the link: https://www.tradingview.com/script/AqXxNS7j-Chandelier-Exit/

I would just like to know when the BUY/SELL signal is true so I can move onto further analysis. Any info that would get me moving in the right direction would be highly appreciated :)

Thanks!

Upvotes: 0

Views: 783

Answers (1)

vitruvius
vitruvius

Reputation: 21342

Well, it is an open-source indicator so why not use its code in you strategy.

You don't need the whole code, only the buySignal and sellSignal.

length = input(title="ATR Period", type=input.integer, defval=22)
mult = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
useClose = input(title="Use Close Price for Extremums ?", type=input.bool, defval=true)

atr = mult * atr(length)

longStop = (useClose ? highest(close, length) : highest(length)) - atr
longStopPrev = nz(longStop[1], longStop) 
longStop := close[1] > longStopPrev ? max(longStop, longStopPrev) : longStop

shortStop = (useClose ? lowest(close, length) : lowest(length)) + atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop

var int dir = 1
dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir

buySignal = dir == 1 and dir[1] == -1
sellSignal = dir == -1 and dir[1] == 1

Then add your strategy on top of that.

Upvotes: 1

Related Questions