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

Dans le véritable esprit de TradingView, l'auteur de ce script l'a publié en open-source, afin que les traders puissent le comprendre et le vérifier. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais la réutilisation de ce code dans une publication est régie par le règlement. Vous pouvez le mettre en favori pour l'utiliser sur un graphique.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.

Vous voulez utiliser ce script sur un graphique ?
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")