Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ta.dmi #53

Merged
merged 5 commits into from
Apr 26, 2023
Merged

Support ta.dmi #53

merged 5 commits into from
Apr 26, 2023

Conversation

tsuz
Copy link
Owner

@tsuz tsuz commented Apr 26, 2023

No description provided.

@tsuz
Copy link
Owner Author

tsuz commented Apr 26, 2023

This was tested using this code, much thanks to this script

Code
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tak215

//@version=5
indicator("go-pine CCI Test", overlay = false)

openval  = array.from(11.3, 12.9, 11.0, 19.2, 18.1, 19.4, 19.1, 10.6, 18.8, 17.1)
highval  = array.from(19.7, 19.1, 18.8, 19.6, 19.5, 19.8, 19.5, 19.9, 19.0, 17.6)
lowval   = array.from(11.1, 12.3, 10.3, 11.7, 11.2, 13.5, 12.9, 10.3, 12.4, 10.0)
closeval = array.from(16.5, 18.7, 18.2, 11.9, 19.3, 14.2, 14.4, 11.0, 14.7, 10.3)
volumeval= array.from(11.6, 13.0, 13.8, 15.9, 16.8, 19.1, 14.7, 11.7, 17.4, 15.0)

vals (index) =>
    if index >= 0 and array.size(closeval) > index
        [array.get(openval, int(index)),array.get(highval, int(index)),array.get(lowval, int(index)),array.get(closeval, int(index)), array.get(volumeval, int(index))]


[o, h, l, c, v] = vals(array.size(openval) - (last_bar_index - bar_index))

hlc3v = (h + l + c) / 3


dirmov(len) =>
	up = ta.change(high)
	down = -ta.change(low)
	plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
	minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
    tr = na(high[1])? high-low : math.max(math.max(high - low, math.abs(high - close[1])), math.abs(low - close[1]))
	truerange = ta.rma(tr, len)
	plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
	minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
	[plus, minus]

adx(dilen, adxlen) =>
	[plus, minus] = dirmov(dilen)
	sum = plus + minus
	adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)

dirmov_custom(highsrc, lowsrc, closesrc, len) =>
	up = ta.change(highsrc)
	down = -ta.change(lowsrc)
	plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
	minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
    tr = na(highsrc[1])? highsrc-lowsrc : math.max(math.max(highsrc - lowsrc, math.abs(highsrc - closesrc[1])), math.abs(lowsrc - closesrc[1]))
	truerange = ta.rma(tr, len)
	plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
	minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
	[plus, minus]

adx_custom(highsrc, lowsrc, closesrc, dilen, adxlen) =>
	[plus, minus] = dirmov_custom(highsrc, lowsrc, closesrc, dilen)
	sum = plus + minus
	adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)

[plus,minus]=dirmov_custom(high, low, close, 4)
adx2 = adx_custom(high,low,close, 4, 3)
// [plus,minus]=dirmov_custom(h, l, c, 4)
// adx2 = adx_custom(h,l,c, 4, 3)

[diplus, diminus, adx] = ta.dmi(4, 3)

plot(adx2-adx , color=color.white)
plot(diplus-plus , color=color.blue)
plot(diminus-minus , color=color.yellow)

@tsuz tsuz merged commit 2200f88 into main Apr 26, 2023
@tsuz tsuz mentioned this pull request Apr 26, 2023
@tsuz tsuz deleted the taku/dmi branch April 26, 2023 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant