Hi All,
As discussed in the video, below are the steps to define fully customisable alert templates and alerts in pine script. This is a generic idea which can be implemented for any script.
Step 1. What all parameters(keys) need to be sent in alerts.
Step 2. Create a default alert template
Step 3. Create a user input where users can alter the default alert template
Step 4. Define your alert condition.
Step 5. Calculate the values for all the keys
Step 6. In the template, replace all keys with values and send alert
Sample script developed during the video.
As discussed in the video, below are the steps to define fully customisable alert templates and alerts in pine script. This is a generic idea which can be implemented for any script.
Step 1. What all parameters(keys) need to be sent in alerts.
Step 2. Create a default alert template
Step 3. Create a user input where users can alter the default alert template
Step 4. Define your alert condition.
Step 5. Calculate the values for all the keys
Step 6. In the template, replace all keys with values and send alert
Sample script developed during the video.
Pine Script®
//@version=5
indicator("Fully Customizable Alerts", overlay=true)
import HeWhoMustNotBeNamed/RecursiveAlerts/2 as ra
//Step 1. What all parameters(keys) need to be sent in alerts.
keys = array.from("{entry}", "{stop}", "{target1}", "{target2}")
//Step 2. Create a default alert template
template = '{\n
\t"entry" : {entry},\n
\t"stop" : {stop},\n
\t"target1" : {target1},\n
\t"target2" : {target2}\n
}'
//Step 3. Create a user input where users can alter the default alert template
inputTemplate = input.text_area(template, 'Alert Template')
//Step 4. Define your alert condition.
ma = ta.sma(close, 20)
condition = ta.crossover(close, ma)
atr = ta.atr(14)
if(condition)
//Step 5. Calculate the values for all the keys
entry = high + atr
stop = low - atr
risk = entry - stop
target1 = entry + risk
target2 = entry + 2*risk
//Step 6. In the template, replace all keys with values and send alert
values = array.from(str .tostring(entry), str .tostring(stop), str .tostring(target1), str .tostring(target2))
alertMessage = ra.updateAlertTemplate(inputTemplate, keys, values)
alert(alertMessage, alert.freq_once_per_bar)
plot(ma, "Moving Average")
indicator("Fully Customizable Alerts", overlay=true)
import HeWhoMustNotBeNamed/RecursiveAlerts/2 as ra
//Step 1. What all parameters(keys) need to be sent in alerts.
keys = array.from("{entry}", "{stop}", "{target1}", "{target2}")
//Step 2. Create a default alert template
template = '{\n
\t"entry" : {entry},\n
\t"stop" : {stop},\n
\t"target1" : {target1},\n
\t"target2" : {target2}\n
}'
//Step 3. Create a user input where users can alter the default alert template
inputTemplate = input.text_area(template, 'Alert Template')
//Step 4. Define your alert condition.
ma = ta.sma(close, 20)
condition = ta.crossover(close, ma)
atr = ta.atr(14)
if(condition)
//Step 5. Calculate the values for all the keys
entry = high + atr
stop = low - atr
risk = entry - stop
target1 = entry + risk
target2 = entry + 2*risk
//Step 6. In the template, replace all keys with values and send alert
values = array.from(str .tostring(entry), str .tostring(stop), str .tostring(target1), str .tostring(target2))
alertMessage = ra.updateAlertTemplate(inputTemplate, keys, values)
alert(alertMessage, alert.freq_once_per_bar)
plot(ma, "Moving Average")
Trial - trendoscope.io/trial
Subscribe - trendoscope.io/pricing
Blog - docs.trendoscope.io
Subscribe - trendoscope.io/pricing
Blog - docs.trendoscope.io
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.
Trial - trendoscope.io/trial
Subscribe - trendoscope.io/pricing
Blog - docs.trendoscope.io
Subscribe - trendoscope.io/pricing
Blog - docs.trendoscope.io
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.