Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
698 views2 pages

Script RSI MACD

This document defines an indicator that calculates and plots the Moving Average Convergence Divergence (MACD) and Relative Strength Index (RSI) values. It takes inputs for the fast, slow and signal periods of the MACD, and the period for the RSI. Color and visibility settings can be configured for the MACD, RSI and combined RSI+MACD plots. The indicator draws arrow shapes to indicate buy and sell signals based on the indicator values.

Uploaded by

ngocdungocthuy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
698 views2 pages

Script RSI MACD

This document defines an indicator that calculates and plots the Moving Average Convergence Divergence (MACD) and Relative Strength Index (RSI) values. It takes inputs for the fast, slow and signal periods of the MACD, and the period for the RSI. Color and visibility settings can be configured for the MACD, RSI and combined RSI+MACD plots. The indicator draws arrow shapes to indicate buy and sell signals based on the indicator values.

Uploaded by

ngocdungocthuy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

instrument {

name = 'RSI MACD',


icon = 'indicators:MACD',
overlay = true
}

--Macd
fast = input (12, "front.platform.fast period", input.integer, 1, 250)
slow = input (26, "front.platform.fast period", input.integer, 1, 250)

-- Cal Macd

fastMA = ema(close, fast)


slowMA = ema(close, slow)

macd = fastMA - slowMA

signal = ema(macd, signal_period)

hist = macd - signal

--RSI

period = input (14, "RSI Period", input.integer, 1)


rsi_ovb = input (70, "RSI OVB", input.double, 0.01)
rsi_ovs = input (30, "RSI OVB", input.double, 0.01)
source = input (1, "Price Apply", input.string_selection, inputs.titles)
fn = input (averages.ssma, "front.newind.average", input.string_selection,
averages.titles)

local sourceSeries = inputs [source]


local averageFunction = averages [fn]

delta = sourceSeries - sourceSeries [1]

up = averageFunction (max (delta, 0), period)


down = averageFunction (max (-delta, 0), period)

rs = up / down
res = 100 - 100 / (1 + rs)

input_group{
"MACD Only",
macd_color_sell = input { default = "red", type = input.color },
macd_color_buy = input { default = "green", type = input.color },
macd_visible = input { default = true, type = input.plot_visibility }

input_group{
"RSI Only",
rsi_color_sell = input { default = "orange", type = input.color },
rsi_color_buy = input { default = "blue", type = input.color },
rsi_visible = input { default = true, type = input.plot_visibility }

}
input_group{
"RSI and Macd",
rsimacd_color_sell = input { default = "magenta", type = input.color },
rsimacd_color_buy = input { default = "aqual", type = input.color },
rsimacd_visible = input { default = true, type = input.plot_visibility }

--Plot Shape Arrow

SELL_MACD = macd[0] < macd[1] and macd[0] < macd[2] and macd[1] > macd[2] and macd
> 0
BUY_MACD = macd[0] > macd[1] and macd[0] > macd[2] and macd[1] < macd[2] and macd
< 0

plot_shape(SELL_MACD and macd_visible,"SELL_MACD", shape_style.triangledown,


shape_size.auto, macd_color_sell, shape_location.abovebar, 0, "", macd_color_sell)
plot_shape(BUY_MACD and macd_visible,"BUY_MACD", shape_style.triangleup,
shape_size.auto, macd_color_buy, shape_location.belowbar, 0, "", macd_color_buy)

SELL_RSI = res[0] < res[1] and res[0] < res[2] and res[1] > res[2] and res[1] >
rsi_ovb
BUY_RSI = res[0] > res[1] and res[0] > res[2] and res[1] < res[2] and res[1] <
rsi_ovs

plot_shape(SELL_RSI and rsi_visible,"SELL_RSI", shape_style.triangledown,


shape_size.auto, rsi_color_sell, shape_location.abovebar, 0, "", rsi_color_sell)
plot_shape(BUY_RSI and rsi_visible,"BUY_RSI", shape_style.triangleup,
shape_size.auto, rsi_color_buy, shape_location.belowbar, 0, "", rsi_color_buy)

-- RSI OVB/OVS + MACD


Sell_RSI_MACD = res[1] > rsi_ovb and macd[0] < macd[1] and macd[0] < macd[2] and
macd[1] > macd[2] and macd > 0
Buy_RSI_MACD = res[1] < rsi_ovs and macd[0] > macd[1] and macd[0] > macd[2] and
macd[1] < macd[2] and macd < 0

plot_shape(Sell_RSI_MACD and rsimacd_visible,"Sell_RSI_MACD",


shape_style.triangledown, shape_size.auto, rsimacd_color_sell,
shape_location.abovebar, 0, "", rsimacd_color_sell)
plot_shape(Buy_RSI_MACD and rsimacd_visible,"Buy_RSI_MACD", shape_style.triangleup,
shape_size.auto, rsimacd_color_buy, shape_location.belowbar, 0, "",
rsimacd_color_buy)

You might also like