i have attempted to add alerts to the following Pivot point script but i can’t get it to function correct.
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
indicator("Example Pivot high/low",overlay = true, max_bars_back=5000)
pvtLength = input.int(20, "Left/Right Length", minval=1)
pvtHigh = ta.pivothigh(pvtLength, pvtLength)
pvtLow = ta.pivotlow (pvtLength, pvtLength)
proceed = not na(pvtHigh) or not na(pvtLow)
pvtLengthTemp = 3
pvtHighTemp = ta.pivothigh(pvtLengthTemp, pvtLengthTemp)
pvtLowTemp = ta.pivotlow (pvtLengthTemp, pvtLengthTemp)
proceedTemp = not na(pvtHighTemp) or not na(pvtLowTemp)
var x1 = 0
var x2 = 0
var x2Temp = 0
var pvtHigh1 = 0.
var pvtLow1 = 0.
var pvtHigh1Temp = 0.
var pvtLow1Temp = 0.
if proceed
x1 := x2
x2 := bar_index
if proceedTemp
x2Temp := bar_index
profileLength = x2 - x1
profileLengthTemp = x2Temp - pvtLengthTemp - x2 + pvtLength
// Pivot Points High/Low
var label tempHigh = na
var label tempLow = na
f_drawOnlyLabelX(_x, _y, _text, _xloc, _yloc, _color, _style, _textcolor, _size) =>
label.new(_x, _y, _text, _xloc, _yloc, _color, _style, _textcolor, _size)
if not na(pvtHigh)
f_drawOnlyLabelX(bar_index[pvtLength], pvtHigh, str.tostring(pvtHigh, format.mintick), xloc.bar_index, yloc.price, chart.fg_color, label.style_label_down, chart.bg_color, size.small)
pvtHigh1 := pvtHigh
label.delete(tempHigh[1])
if x2 - pvtLength > x2Temp - pvtLengthTemp
label.delete(tempLow[1])
if not na(pvtLow)
f_drawOnlyLabelX(bar_index[pvtLength], pvtLow , str.tostring(pvtLow , format.mintick), xloc.bar_index, yloc.price, chart.fg_color, label.style_label_up, chart.bg_color, size.small)
pvtLow1 := pvtLow
label.delete(tempLow[1])
if x2 - pvtLength > x2Temp - pvtLengthTemp
label.delete(tempHigh[1])
if not na(pvtHighTemp)
if pvtHighTemp > pvtHigh1Temp
label.delete(tempHigh[1])
tempHigh := label.new(bar_index[pvtLengthTemp], pvtHighTemp, '* ' + str.tostring(pvtHighTemp, format.mintick), xloc.bar_index, yloc.price, #284aa9, label.style_label_down, color.white, size.small)
pvtHigh1Temp := pvtHighTemp
if high > pvtHigh1Temp
label.delete(tempHigh[1])
if not na(pvtLowTemp)
if pvtLowTemp < pvtLow1Temp
label.delete(tempLow[1])
tempLow := label.new(bar_index[pvtLengthTemp], pvtLowTemp, '* ' + str.tostring(pvtLowTemp, format.mintick), xloc.bar_index, yloc.price, #284aa9, label.style_label_up, color.white, size.small)
pvtLow1Temp := pvtLowTemp
if low < pvtLow1Temp
label.delete(tempLow[1])
i Tried the following:
alertcondition(not na(tempHigh), title="Pivot TOP Alert", message="New Pivot TOP Signal")
alertcondition(not na(tempLow), title="Pivot BOTTOM Alert", message="New Pivot BOTTOM Signal")
The Result:
it works but if there is already a temporary pivot high/low then the alert triggers instantaneously once activated.
What i am expecting:
It needs to trigger the alerts with every new temporary pivot high/low regardless of any existing temporary pivots. For example lets say there is already a temp pivot high and i activate the top pivot alert then it must only trigger with the next new temp pivot high AND NOT trigger instantaneously because of the already existing temp pivot high.
P.S. i am not a wizard or a professional coder so i am finding this very difficult. Any assistance would be greatly appreciated
dawid theron is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.