trend test

stable
By AGreatEscape in Trading Bots Published March 2023 👁 916 views 💬 1 comments

Description

Trend test
HaasScript
-- HaasScript
DefineCommand("dirmov", Function(len)
    local up = Change(high)
    local down = -Change(low)
    local plusDM = (IsNaN(up) and NaN) or (up > down and up > 0 and up) or 0
    local minusDM = (IsNaN(down) and NaN) or (down > up and down > 0 and down) or 0
    local truerange = RMA(TrueRange(), len)
    local plus = FixNaN(100 * RMA(plusDM, len) / truerange)
    local minus = FixNaN(100 * RMA(minusDM, len) / truerange)
    return {plus, minus}
end)

DefineCommand("adx", Function(dilen, adxlen)
    local plus, minus = dirmov(dilen)
    local sum = plus + minus
    local adx = 100 * RMA(math.abs(plus - minus) / (sum == 0 and 1 or sum), adxlen)
    return adx
end)

-- Inputs
local atrPeriod = Input(10, "ATR Length")
local factor = Input(3.0, "Factor", 0.01, 0, 1)

-- Supertrend direction
local supertrend = SuperTrend(high, low, close, atrPeriod, factor)
local direction = supertrend[2]

-- ADX
local adxlen = Input(7, "ADX Smoothing")
local dilen = Input(7, "DI Length")
local sig = adx(dilen, adxlen)

-- Entry conditions
if direction < 0 and RSI(close, 21) < 66 and RSI(close, 3) > 80 and RSI(close, 28) > 49 and sig > 20 then
    Buy("My Long Entry Id", 120 / 100 * account.equity, open[1])
end

-- Exit conditions
if direction > 0 then
    ClosePosition("My Long Entry Id")
end

1 Comment

Sign in to leave a comment.

I
iddqd about 3 years ago

4. 29 May 2023 08:23:27 ERROR: The script is invalid.3. 29 May 2023 08:23:27 ERROR: SCRIPT ERROR: 'chunk_0:(4,4-9): ')' expected (to close '(' at line 2) near 'local'' at [4:4-9]2. 29 May 2023 08:23:27 Problem detected: ')' expected (to close '(' at line 2) near 'local'