cannot calculate if MA20 and MA200 are close
Posted: Thu Feb 24, 2022 10:32 pm
Setting my first Pine steps and making all the basic errors.. appreciate help!
Purpose: trying to determine how close moving average 20 is to moving average 200
Thought: division of both should be close to 1.
However, the below calculation is true for all values?
Similar also for if I use 1 condition.
Looks like an issue with floats vs integer or rounding?
float ma1 = ta.sma(close, 20)
float ma2 = ta.sma(close, 200)
float xRatio = ma2/ma1
xUp = xRatio>0.8 and xRatio<1.2
plotchar(xUp, "xUp", "▲", location.top, size = size.tiny)
Purpose: trying to determine how close moving average 20 is to moving average 200
Thought: division of both should be close to 1.
However, the below calculation is true for all values?
Similar also for if I use 1 condition.
Looks like an issue with floats vs integer or rounding?
float ma1 = ta.sma(close, 20)
float ma2 = ta.sma(close, 200)
float xRatio = ma2/ma1
xUp = xRatio>0.8 and xRatio<1.2
plotchar(xUp, "xUp", "▲", location.top, size = size.tiny)