简体   繁体   中英

Get the Lowest price from last condition till now pine script

I want to find the lowest price from yellow candle till white candle ( 75 candles apart )

yellow bar = last condition

white bar = the condition happened now

I used some codes i don't know which are right or wrong. please help

// The problem with this code (barssince)is when the white bar happens it zeros the plot 
because the Long_Condition happens in that candle so it zeros the amount i want to use


since = barssince(Long_Condition)
lowest_price = lowest(since)

now with the plots there are some problems:

problem 1

plot(since, title = "bars back", color = color.blue)

in the picture attached you can see the blue plot zeros the amount that was counting which at the last candle it gave 74 and then when i want to get 75 it gives the zero.(from yellow bar to white bar it is 75 candles) and which basically the below code will be wrong and it doesn't run the script.

lowest_price = lowest(since)

Now, if i use this code which I don't know if it is right or wrong but here it is:

index_white = valuewhen(Long_Condition , bar_index , 0)

index_yellow = valuewhen(Long_Condition , bar_index , 1)

int final_index = index_white - index_yellow 

Lowest_price = lowest(final_index)
plot_1 = plot(final_index , color = color.blue)
plot_2 = plot(Lowest_price)

Now the plot_1 works great but when i add plot_2 to the script, it doesn't run it.

Isn't final_index Integer that Lowest(final_index) doesn't work?

please help me. Thanks

Picture 2 is coded with enabled plot_1 .

Click to see the Picture #1

Click to see the Picture #2

You can obtain these values with the use of additional variables to track the low and by using ta.valuewhen() to obtain the values necessary.

//@version=5
indicator("lowest between conditions", overlay = true)

long_condition = ta.crossover(ta.ema(close, 13), ta.ema(close, 30))

var float lowest_since_long = na
var int lowest_since_long_index = na

if long_condition
    lowest_since_long := low
    lowest_since_long_index := bar_index
else
    if low < lowest_since_long
        lowest_since_long := low
        lowest_since_long_index := bar_index


prev_long_low = ta.valuewhen(long_condition, lowest_since_long[1], 0)
prev_long_index = ta.valuewhen(long_condition, lowest_since_long_index[1], 0)

l = line.new(x1 = prev_long_index, y1 = prev_long_low, x2 = bar_index, y2 = prev_long_low, color = color.red)
line.delete(l[1])


plotshape(long_condition, color = color.lime, location = location.belowbar, size = size.small, style = shape.triangleup)

Sorry if I'm off topic but maybe you could help me. Do you know of a crypto trading platform that is good for customizing a lot of the token buying/selling conditions? Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM