Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Plotting line at wrong end

I want to plot a line on the high of the pivot low and not on the low of the pivot low. How can i do that?

//@version=5
indicator("Pivot crosses", "", true)

int activeLevelsInput = input(10)
int pivotLegsInput = input(5)

// When a pivot occurs, create a line and save it.
float pLo = ta.pivotlow(pivotLegsInput, pivotLegsInput)

var pivotLines = array.new<line>(activeLevelsInput)

if not na(pLo)
    line newPivotLine = line.new(bar_index - pivotLegsInput, pLo, bar_index, pLo)
    array.push(pivotLines, newPivotLine)

    // Delete the oldest line.
    line.delete(array.shift(pivotLines))

// Extend the lines.
if barstate.islast and barstate.isnew
    for pivotLine in pivotLines
        line.set_x2(pivotLine, bar_index)

// Check for crosses.
bool cross = false

for pivotLine in pivotLines
    float linePrice = line.get_y1(pivotLine)
    bool newCrossUp = close[1] < linePrice and close > linePrice
    bool newCrossDn = close[1] > linePrice and close < linePrice
    cross := cross or newCrossUp or newCrossDn

// Alert.

if cross
    alert("A cross has occurred")

plotchar(cross, "Cross", "X")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You are using pLo to set the y-axis of your line. pLo is assigned by ta.pivotlow() which will return the low price.

What you need to do is, figure out the bar index where there is a pivot low and get its high price.

You can easily do that with the history reference operator with using pivotLegsInput as your offset.

high_price = high[pivotLegsInput]
line newPivotLine = line.new(bar_index - pivotLegsInput, high_price, bar_index, high_price)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading