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!
Mã nguồn mở

Với tinh thần TradingView, tác giả của tập lệnh này đã xuất bản nó dưới dạng mã nguồn mở, vì vậy các nhà giao dịch có thể hiểu và xác minh nó. Chúc mừng tác giả! Bạn có thể sử dụng mã này miễn phí, nhưng việc sử dụng lại mã này trong một ấn phẩm chịu sự điều chỉnh của Nội quy nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?
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")