Im trying to write an indicator with Pine Script for Trading View.
I want to write a EMA based on the 1-hour-chart and use it in the 5-minute-chart. Including a 8 and 34 tradingperiod (2 EMA). Is that possible?
Usefull to see the higher trend when I'm trading in the 5-minute-chart.
Its my first time i'm trying to write a code at all.
Unfortunately i dont have time to learn it.
It would be really nice, if there is someone who could give me some foray on how to solve that problem.
I have tried to find some guides with google, but there are only some on how to program a EMA.
Everything i found is:
//@version=3
// At the very start of the pine script we always declare the version we are going to use, // You can see, above we are using the version 3 of the pine script // The @version word in pine script must be commented at the begning of the script
study("Coding ema in pinescript", overlay=true)
// This is where we are defining the study, // A study function in the pinescipt is used to tell the pine script that we will be building an indicator // the use of " overlay=true ", lets the pine script know that you want to overlay the plot in the charts on to the // candlestick chart.
// now we define an EMA function, named pine_ema with 2 arguments x and y // the sole aim of this pine_ema function is to return the curent ema of the current candle closing price pine_ema(src, time_period) =>
alpha = 2 / (time_period + 1)
// we have defined the alpha function above
ema = 0.0
// this is the initial declaration of ema, since we dont know the first ema we will declare it to 0.0 [as a decimal]
ema := alpha * src + (1 - alpha) * nz(ema[1])
// this returns the computed ema at the current time
// notice the use of : (colon) symbol before =, it symbolises, that we are changing the value of ema,
// since the ema was previously declared to 0
// this is called mutable variale declaration in pine script
ema
// return ema from the function
_10_period_ema = pine_ema(close, 10) // here we just called our function with a src of close and time_period of value 10
plot(_10_period_ema, color=red, transp=30, linewidth=2) // now we plot the _10_period_ema