Pine script for KAL’s ADX Overlap Technical Study with MACD Filter

in #pinescript6 years ago (edited)

Please find below the pine script code for KAL’s AOWL. It’s a method/study to find trending cryptocurrencies which uses two different periods (10, 5) ADX Overlap with a MACD Filter. The MACD filter may or may not be used. Also, the MACD filter may be tweaked too.

Sample Image of KAL’s AOWL pinescript code in Tradingview Looks as follows:

Description

  • Green shadow implies Trending Uptrend
  • Red shadow implies Trending Downward
  • Green dot implies DI+ crossed over DI- (Wait and watch for Uptrend)
  • Red dot implies DI+ crossed over DI- (Wait and watch for Downtrend)

I am a disabled man. Therefore, I am not able to write in detail here today. More Details will follow as time permits. Please let me know if I am missing anything…

Legal Disclaimer: I published here so I get replies from fellow viewers to educate myself and for my daily expenses. Hence, if anyone uses this script for making their decisions, I am not responsible for any failures incurred.

Safe Trading!
Kal Gandikota

PS: If you found this script interesting and edifying please follow and upvote.

PS2: Please kindly donate for my daily expenses (atleast as you would on streets) at the following addresses:

  • BTC Wallet: 1NeDC1GvpFa49DFLuT1v28ohFjqtoWXNQ5
  • ETH Wallet: 0x35e557F39A998e7d35dD27c6720C3553e1c65053
  • NEO Wallet: AUdiNJDW7boeUyYYNhX86p2T8eWwuELSGr

PS3: For more information on ADX and MACD, please 'Google' or search here yourself.
PS4: This study is intended for research in creating automated Python Trading Systems using Pandas(https://steemit.com/python/@chipmaker/how-to-find-guidance-on-building-python-based-cryptocurrency-trading-bots).
Test this code out in your pine editor with a free account on https://www.tradingview.com. More details follow as time permits!

Sample Image of KAL’s AOWL pinescript code in Tradingview Looks as follows:

///////////////////////////////////////////////////////////////////////
//Author: KAL GANDIKOTA
// Kal's ADX Overlap with MACD Filter(Short: KAL'S AOWL) is a method/study
// to find trending cryptocurrencies which uses 
// two different periods (10, 5) ADX Overlap with a MACD Filter. 
// The MACD filter may or may not be used. Also, the MACD filter may be tweaked too.
//
// Copyright (C) JUNE 2018 KAL GANDIKOTA
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Please Kindly Donate for my Daily Expenses and Greater Works Than These
//
// BTC Wallet: 1NeDC1GvpFa49DFLuT1v28ohFjqtoWXNQ5
// ETH Wallet: 0x35e557F39A998e7d35dD27c6720C3553e1c65053
// NEO Wallet: AUdiNJDW7boeUyYYNhX86p2T8eWwuELSGr
// SteemID: chipmaker
// https://www.twitter.com/chipmaker_tweet
// https://steemit.com/@chipmaker
///////////////////////////////////////////////////////////////////////

study(title="Kal's ADX Overlap With MACD Filter", shorttitle="KALS_AOWL")

//ADX5
adx1_len_var = input(5, minval=1, title="DI Length")
adx1_lensig_var = input(5, title="ADX Smoothing", minval=1, maxval=50)
adx1_simpleBW = input(true, title="ADX in Simple Black and White")
adx1_exLevel=input(80,title="Exhaustion Level for ADX, default = 80")
adx1_brLevel=input(10,title="BreakOut Level for ADX, default = 20")

//ADX14
showADX2=input(false, title="Show ADX2?")
adx2_len_var = input(10, minval=1, title="DI Length for ADX2")
adx2_lensig_var = input(10, title="ADX2 Smoothing", minval=1, maxval=50)
adx2_simpleBW = input(true, title="ADX2 in Simple Black and White")
adx2_exLevel=input(50,title="Exhaustion Level for ADX2, default = 50")
adx2_brLevel=input(10,title="BreakOut Level for ADX2, default = 15")

//MACD Filter
macdFilter =input(true, title="MACD Filter")
fastLength = input(12, minval=1)
slowLength=input(26,minval=1)
signalLength=input(9,minval=1)

//ADX
chg_high = change(high)
chg_low  = -change(low)

f_plusDM(up, down) =>
    plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
    plusDM

f_minusDM(up, down) =>
    minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
    minusDM

f_trur(len) => 
    trur = rma(tr, len)
    trur

f_plus(len, plusDM, trur) => 
    plus = fixnan(100 * rma(plusDM, len) / trur)
    plus

f_minus(len, minusDM, trur) => 
    minus = fixnan(100 * rma(minusDM, len) / trur)
    minus

f_adx(len, lensig, plus, minus) => 
    sum = plus + minus
    adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
    adx

plusDM = f_plusDM(chg_high, chg_low)
minusDM = f_minusDM(chg_high, chg_low)

//ADX1
trur = f_trur(adx1_len_var)
plus=f_plus(adx1_len_var, plusDM, trur)
minus=f_minus(adx1_len_var, minusDM, trur)
adx=f_adx(adx1_len_var, adx1_lensig_var, plus, minus)

adx_rising = adx > adx[1]
adx_brex_check = adx > adx1_brLevel and adx <= adx1_exLevel
adx_rising_brex_check = adx_rising and adx_brex_check
PGM = (plus > minus)
PLM = (plus < minus)

adx1_c1 = adx_rising_brex_check and PGM
adx1_c2 = adx_rising_brex_check and PLM

dmColorADX = PGM ? green : (PLM ? red : blue)
plot(crossover(plus, minus) ? plus : crossunder(plus, minus) ? minus : na, style=circles, linewidth=4, color=dmColorADX, transp=0)

//Bar Colors
bwColorADX_condition = adx1_simpleBW ? (adx > adx[1]) : adx1_c1
bwColorADX = bwColorADX_condition ? color(black, 0) : color(white, 0)

plot(plus, color=green, title="+DI")
plot(minus, color=red, title="-DI")
plot(adx, color=bwColorADX, style=cross, linewidth=2, title="ADX1", transp=0)

//ADX2
trur2 = f_trur(adx2_len_var)
plus2 = f_plus(adx2_len_var, plusDM, trur2)
minus2 = f_minus(adx2_len_var, minusDM, trur2)
adx2 = f_adx(adx2_len_var, adx2_lensig_var, plus2, minus2)

adx2_rising = adx2 > adx2[1]
adx2_brex_check = adx2 > adx2_brLevel and adx2 <= adx2_exLevel
adx2_rising_brex_check = adx2_rising and adx2_brex_check
adx2PGM = (plus2 > minus2)
adx2PLM = (plus2 < minus2)

adx2_c1 = adx2_rising_brex_check and adx2PGM
adx2_c2 = adx2_rising_brex_check and adx2PLM

bwColorADX2_condition = adx2_simpleBW ? (adx2 > adx2[1]) : adx2_c1
bwColorADX2 = bwColorADX2_condition ? color(black, 0) : color(white, 0)

//ADX OVERLAP CONDITIONS
adxBuy_condition  = adx1_c1 and adx2_c1
adxSell_condition = adx1_c2 and adx2_c2

adx_BS_condition = adxBuy_condition or adxSell_condition

plot(showADX2 ? adx2:na, color=bwColorADX2, style=cross, linewidth=2, title="ADX2")

//MACD Filter Code
[macdLine, _, histLine] = macd(close, fastLength, slowLength, signalLength)

histA_IsUp = histLine > histLine[1] and histLine > 0
histA_IsDown = histLine < histLine[1] and histLine > 0
histB_IsDown = histLine < histLine[1] and histLine <= 0
histB_IsUp = histLine > histLine[1] and histLine <= 0

macd_BuyCond = macdFilter ? (histA_IsUp and macdLine > 0) : 1
macd_SellCond = macdFilter ? (histB_IsDown and macdLine < 0) : 1

//Trend Start
buyEntry = adxBuy_condition and macd_BuyCond
sellEntry = adxSell_condition and macd_SellCond

bgcolor(buyEntry ? color(lime,0): (sellEntry ? color(red, 0): na))

hline(5, title="5_ADX", color=green, linestyle=solid)
hline(10, title="10_ADX", color=green, linestyle=solid)
hline(20, title="20_ADX", color=yellow, linestyle=solid)
hline(30, title="30_ADX", color=blue, linestyle=solid)
hline(50, title="50_ADX", color=yellow, linestyle=solid)
hline(60, title="60_ADX", color=maroon, linestyle=solid)
hline(70, title="70_ADX", color=maroon, linestyle=solid)

// Alert
alertcondition(buyEntry or sellEntry, title="ADX5_14 Overlap", message="ADX Overlap Confirmed")
Sort:  

Congratulations @chipmaker! You received a personal award!

1 Year on Steemit

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!

Coin Marketplace

STEEM 0.16
TRX 0.16
JST 0.028
BTC 71174.86
ETH 2484.37
USDT 1.00
SBD 2.42