'The variable corresponding to the length of ta.lowest () will always be a constant value. Why?
Excuse me, but let me ask you a question. The purpose of this script is to find the lowest price up to the recent high.
The problem I have is that the variable "distance" does not use the updated value in the calculation of "ta.lowest". The "distance" increases by +1 for each bar. This can be confirmed with plot. However, if I use the variable "distance" in "ta.lowest", it will always be a value of "11". (maybe initial value 10 + count up 1) Do you know why?
//@version=5
strategy("test")
var float hi_price = 0.0 //highest price
var int distance = 10 //Number of bars from the highest price
distance := distance + 1 //count up
float lowest = ta.lowest(low,distance) //lowest price up to the recent high
if(hi_price <= high)
hi_price := high
distance := 0
plot(distance) //confirming value of "distance"
plot(lowest) //confirming value of "lowest"
Solution 1:[1]
Go back to the start of the chart, I mean to the very first bar and you will see your script works there.
The issue is that:
- you always increase
distance - token/stock prices are usually the lowest when they start
As you increase distance every time, it is pointing the same location on every run (on every "next" bar you have progressed 1 bar, but increased lookback with 1 so your ta.lowest() goes back to the same bar every time).
And as tokens/stocks are the lowest around their start, you won't find any lower value usually. This is not true for every stock/token but that's the usual case.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | karatedog |
