I know nothing about coding but what I do know is that I have been manually using the following script from tradingview and killing it everyday. Now if gekko could be coded to run this script I could get away from sitting infornt of a computer. lol
The script I have been using is located here: https://www.tradingview.com/script/H48ye...-Trend-V2/
Here is the code:
Bounty offered.. .003 BTC
The script I have been using is located here: https://www.tradingview.com/script/H48ye...-Trend-V2/
Here is the code:
Code:
//@version=2
// Constructs the trailing ATR stop above or below the price, and switches
// directions when the source price breaks the ATR stop. Uses the Average
// Directional Index (ADX) to switch between ATR multipliers. The higher
// multiplier is used when the ADX is rising, and the lower ATR multiplier
// is used with the ADX is falling. This ADX criteria further widens the gap
// between the source price and the trailing ATR stop when the price is trending,
// and lessens the gap between the ATR and the price when then price is not
// trending.
//
// The ATR-ADX stop is effectively a double adapative stop that trails the price,
// by both adapting to the true range of the price, and the average directional
// change. When the stop is below the price (long trade) the value never decreases
// until the price intersects the stop, and it reverses to being above the price
// (short trade). When the stop is above the price it will never increase until
// it is intersected by the price. As the true range and ADX change, the stop
// will move more quickly or more slowly.
//
// Version 2 adds four additional utilities.
//
// First, if the 'Above Threshold' box is checked,the falling (smaller) multiplier
// will be used regardless once the ADX rises above a certain threshold (default > 30).
// The ATR will effectively rise faster once the price enters 'very trendy' mode.
// Typically, ADX > 20/25 is used in classic ADX trading (which I have found
// unprofitable through backtesting). The idea behind this extra multiplier criteria
// is that once the price starts trending 'very' well, a top is most likely near,
// and when that top comes the price will quickly rebound. Experienced traders know
// exactly what I am describing. Play around with an ADX/DI indicator using this
// stop system in tandem and it will be found that many successful trades are entered
// when the market is not trending (i.e. < ADX < 25), and exited once/if the price
// enters 'very trendy' mode above 30 and the ATR changes (stopped out).
//
// Second, heiken-ashi bars can be introduced to the ATR stop system. This is the same
// thing as just switching the chart to Heiken Ashi mode, but without having to change
// the plotting type. I find this useful, so that things like pivot lines can be
// preserved to their correct calculations, while the benefit of heiken ashi bars can
// still be enjoyed.
//
// Third, Different source prices can be used. I have found that HLC3 is best because
// it keeps the price from being stopped out in very key areas, set as the default.
//
// Fourth, alert conditions are introduced so that the trader can be warned when the
// ATR-ADX changes. These can be used by right clicking the strategy and clicking
// "Add Alert...". Reference the bottom of the script for the names of the alert
// conditions.
//
// See also: http://www.fxtsp.com/1287-doubly-adaptive-profit-average-true-range-objectives/
study(title = "Adaptive ATR-ADX Trend V2", shorttitle = "Adaptive ATR V2", overlay = true)
//Mode
src = input(title = "Source", type = source, defval = hlc3)
atrLen = input(title = "ATR", type = integer, defval = 21, minval = 1, maxval = 100)
m1 = input(title = "ATR Multiplier - ADX Rising", type = float, defval = 3.5, minval = 1, step = 0.1, maxval = 100)
m2 = input(title = "ATR Multiplier - ADX Falling", type = float, defval = 1.75, minval = 1, step = 0.1, maxval = 100)
adxLen = input(title = "ADX", type = integer, defval = 14, minval = 1, maxval = 100)
adxThresh = input(title = "ADX Threshold", type = integer, defval = 30, minval = 1)
aboveThresh = input(true, title = "ADX Above Threshold uses ATR Falling Multiplier Even if Rising?")
useHeiken = input(false, title = "Use Heiken-Ashi Bars (Source will be ohlc4)")
// DI-Pos, DI-Neg, ADX
hR = change(high)
lR = -change(low)
dmPos = hR > lR ? max(hR, 0) : 0
dmNeg = lR > hR ? max(lR, 0) : 0
sTR = nz(sTR[1]) - nz(sTR[1]) / adxLen + tr
sDMPos = nz(sDMPos[1]) - nz(sDMPos[1]) / adxLen + dmPos
sDMNeg = nz(sDMNeg[1]) - nz(sDMNeg[1]) / adxLen + dmNeg
DIP = sDMPos / sTR * 100
DIN = sDMNeg / sTR * 100
DX = abs(DIP - DIN) / (DIP + DIN) * 100
adx = sma(DX, adxLen)
// Heiken-Ashi
xClose = ohlc4
xOpen = (nz(xOpen[1]) + nz(close[1])) / 2
xHigh = max(high, max(xOpen, xClose))
xLow = min(low, min(xOpen, xClose))
// Trailing ATR
v1 = abs(xHigh - xClose[1])
v2 = abs(xLow - xClose[1])
v3 = xHigh - xLow
trueRange = max(v1, max(v2, v3))
atr = useHeiken ? rma(trueRange, atrLen) : atr(atrLen)
m = rising(adx, 1) and (adx < adxThresh or not aboveThresh) ? m1 : falling(adx, 1) or (adx > adxThresh and aboveThresh) ? m2 : nz(m[1])
mUp = DIP >= DIN ? m : m2
mDn = DIN >= DIP ? m : m2
src_ = useHeiken ? xClose : src
c = useHeiken ? xClose : close
t = useHeiken ? (xHigh + xLow) / 2 : hl2
up = t - mUp * atr
dn = t + mDn * atr
TUp = max(src_[1], c[1]) > TUp[1] ? max(up, TUp[1]) : up
TDown = min(src_[1], c[1]) < TDown[1] ? min(dn, TDown[1]) : dn
trend = min(src_, min(c, close)) > TDown[1] ? 1 : max(src_, max(c, close)) < TUp[1]? -1 : nz(trend[1], 1)
stop = trend == 1 ? TUp : TDown
trendChange = change(trend)
// Plot
lineColor = not(trendChange) ? trend > 0 ? #00FF00DD : #FF0000DD : #00000000
shapeColor = trendChange ? trendChange > 0 ? #00FF00F8 : #FF0000F8 : #00000000
plot(stop, color = lineColor, style = line, linewidth = 1, title = "ATR Trend")
plotshape(trendChange ? stop : na, style = shape.circle, size = size.tiny, location = location.absolute, color = shapeColor, title = "Change")
alertcondition(trendChange > 0, title = "ATR-ADX Change Up", message = "ATR-ADX Change Up")
alertcondition(trendChange < 0, title = "ATR-ADX Change Down", message = "ATR-ADX Change Down")
// end