How to use an indicator in your pine strategy that doesn't have a built-in function?
Hello all. 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'
I would just like to know when the BUY signal is true so I can move onto further analysis.
Thanks!
Posted Apr 7, 2022, 8:00 PM UTC
Getting an indicator or multiple indicators into a strategy is a pretty straight forward affair. Just copy the code from the indicator code that is the indicator itself, basically the components below the line that looks similar to this:
indicator(title="My Indicator", shorttitle="My Indicator", overlay=true, timeframe="", timeframe_gaps=true)
As far as knowing when the Buy Signal would be triggered visually there are a few ways to do it. The easiest is just to use a plot:
plotshape(My_CE_Buy_Signal, title='CE Buy', location=location.abovebar, color=color.new(color.blue, 0), size=size.small, style=shape.cross, text='CE Buy')
if you are wanting to use the CE Buy/Sell Signal in an automated way in your code such as saying that other indicators can be active if the CE Buy Signal is true and has not triggered a CE Sell Signal, you can use variables to act as a switch.
var ce_Buy_Active =0
var ce_Sell_Active =0
if My_CE_Buy_Signal
ce_Buy_Active :=1
ce_Sell_Active :=0
if My_CE_Sell_Signal
ce_Buy_Active :=0
ce_Sell_Active :=1
Also keep in mind that depending on the Pine Version the indicator you are using is written in, it might need to be upgraded to the latest version of Pine. The debugger will let you know what the errors are line by line to make any changes.
Really appreciate this. Thanks a bunch.