pine script - How can i fixed EMA? - Stack Overflow

admin2025-04-16  4

I want to use the ema indicator that I put below as fixed. I want to set it as 1 day in any case. So period 1440 for 1 minute time frame = period 96 for 15 minute time frame is the same thing or period 48 for 30 minute time frame. How can I fix this?

indicator("EMA", "EMA", overlay=true)

length = input.int(1440, "Length")
lineColor = input.color(#000000, "Line-Color")
emaTop = ta.ema(input.source(high, "Top-Source"), length)
emaBot = ta.ema(input.source(low, "Bot-Source"), length)
fillColor =  close < emaBot ? input.color(color.rgb(255, 0, 0, 67), "Fill-Color-Below") : 
             close > emaTop ? input.color(color.rgb(27, 255, 27, 67), "Fill-Color-Above") : 
                              input.color(color.rgb(120, 123, 134, 67), "Fill-Color-Neutral")
pTop = plot(emaTop, color=lineColor)
pBot = plot(emaBot, color=lineColor)
fill(pTop, pBot, color=fillColor, fillgaps=true)

I want to use the ema indicator that I put below as fixed. I want to set it as 1 day in any case. So period 1440 for 1 minute time frame = period 96 for 15 minute time frame is the same thing or period 48 for 30 minute time frame. How can I fix this?

indicator("EMA", "EMA", overlay=true)

length = input.int(1440, "Length")
lineColor = input.color(#000000, "Line-Color")
emaTop = ta.ema(input.source(high, "Top-Source"), length)
emaBot = ta.ema(input.source(low, "Bot-Source"), length)
fillColor =  close < emaBot ? input.color(color.rgb(255, 0, 0, 67), "Fill-Color-Below") : 
             close > emaTop ? input.color(color.rgb(27, 255, 27, 67), "Fill-Color-Above") : 
                              input.color(color.rgb(120, 123, 134, 67), "Fill-Color-Neutral")
pTop = plot(emaTop, color=lineColor)
pBot = plot(emaBot, color=lineColor)
fill(pTop, pBot, color=fillColor, fillgaps=true)
Share Improve this question asked Feb 3 at 19:47 NotoriousNotorious 51 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

This is my updated answer after taking a fresh look at your question.

You can find the length relative to 1 day using timeframe.in_seconds():

length = timeframe.in_seconds("1D") / timeframe.in_seconds()
转载请注明原文地址:http://www.anycun.com/QandA/1744753153a87123.html