Kurbelklaus

KK_Intraday MAs

Hey guys,

today I was browsing through intraday Charts looking at some moving averages. Basically what I wanted to see was whether the currency pair was trading below or above the moving average of the day/week/month. For a better understanding: The daily MA on a 15 minute Forex Chart would be the 96 MA.

I encountered the problem that i always had to change the settings for my MAs when changing the Time Interval, so I coded this here up. It is pretty simple but maybe somebody else has the same problem and can put it to use.

The script has some settings as listed below:
  • Choice which MAs to plot, (Daily, Weekly, Monthly)
  • Choice which type of MA to use (Simple, Exponential, Weighted)
  • Neccesary Settings for the correct calculation (e.g. Number of trading hours per day). These settings depend on the instrument you are using and should always be checked before using this script.

There are a few things to Note when using this script:
  • This script works for intraday charts only.
  • The monthly MA doesn't work on any Time Interval smaller than 15 minutes. Can't do anything about it unfortunately.

This is my first published Script, use it with caution and let me know what you think about it!
Script open-source

Nello spirito di condivisione promosso da TradingView, l'autore (al quale vanno i nostri ringraziamenti) ha deciso di pubblicare questo script in modalità open-source, così che chiunque possa comprenderlo e testarlo. Puoi utilizzarlo gratuitamente, ma il riutilizzo del codice è subordinato al rispetto del Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.

Vuoi usare questo script sui tuoi grafici?
study(title="KK_Intraday MAs",overlay=true)
//inputs
PD = input(false, title="Plot Daily MA")
PW = input(true, title="Plot Weekly MA")
PM = input(true, title="Plot Monthly MA")
MAT = input(1,minval=1,maxval=3,title="1=SMA, 2=EMA, 3=WMA")
HPD = input(24, title="Number of trading hours per day")
DPW = input(5, title="Number of trading days per Week")
WPY = input(52, title="Number of Weeks per Year")

//SMA generation
Simple = MAT == 1 ? true : false
Exponential = MAT == 2 ? true : false
Weighted = MAT == 3 ? true : false
BPD=round(60*HPD/interval)
BPW=round(60*HPD*DPW/interval)
BPM=round(60*HPD*DPW*WPY/(12*interval))
daily = Simple ? sma(close, BPD) : Exponential ? ema(close, BPD): Weighted ? wma(close, BPD) : na
weekly = Simple ? sma(close, BPW) : Exponential ? ema(close, BPW): Weighted ? wma(close, BPW) : na 
monthly = Simple ? sma(close, BPM) : Exponential ? ema(close, BPM): Weighted ? wma(close, BPM) : na

//Plotting
plot(PD and isintraday ? daily : na, color = green, linewidth = 3, title="Daily")
plot(PW and isintraday ? weekly : na, color = blue, linewidth = 3, title="Weekly")
plot(PM and isintraday ? monthly: na, color= black, linewidth = 3, title="Monthly")