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!
Open-source Skript

Ganz im Spirit von TradingView hat der Autor dieses Skripts es als Open-Source veröffentlicht, damit Trader es besser verstehen und überprüfen können. Herzlichen Glückwunsch an den Autor! Sie können es kostenlos verwenden, aber die Wiederverwendung dieses Codes in einer Veröffentlichung unterliegt den Hausregeln. Sie können es als Favoriten auswählen, um es in einem Chart zu verwenden.

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.

Möchten Sie dieses Skript auf einem Chart verwenden?
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")