[pshaiCmd] Average Change Oscillator

stable
By pshai in Oscillators Published November 2019 👁 1,563 views 💬 0 comments

Description

ACO indicator custom command
HaasScript
-- ==============================================
-- Average Change Oscillator
-- Developed by pshai
-- ----------------------------------------------
-- Brief intro: ACO is a type of momentum strength indicator that
-- measures the average price change. It can be interpreted in
-- several ways and can be beneficial for confirming trends and reversals.
-- ==============================================

DefineCommand('ACO', 'Average Change Oscillator')

-- Parameters
local source = DefineParameter(ListNumberType, 'source', 'The price source.', true, ClosePrices(), 'ClosePrices, HLPrices, HLCPrices, OHLCPrices')
local period1 = DefineParameter(NumberType, 'period1', 'Smoothing period for the first average', false, 10, 'Number, Input')
local period2 = DefineParameter(NumberType, 'period2', 'Smoothing period for the second average', false, 20, 'Number, Input')

-- Optimization
local interval = CurrentInterval(source)
DefineIntervalOptimization(interval)

-- Data
local lookback = (period1 + period2) + 10 -- speed optimisation part 1
local source1 = Grab(source, 0, lookback) -- speed optimisation part 2
local source2 = Offset(source1, 1)
local temp = Sub(Div(source1, source2), 1.0) -- source1 / source2 - 1.0
local tempLen = #temp
local result = {}
local values

-- Magic
for i=1, tempLen-period1
do
    values = Grab(temp, i-1, period1)
    result[i] = Average(values)
end

local sma1 = SMA(result, period2)

-- Result
local finalResult = {Sub(result, sma1), sma1}

-- Output
DefineOutput(ListDynamicType, finalResult, 'Output values for ACO lines', 'Plot')
DefineOutputIndex(1, ListNumberType, 'aco', 'ACO values')
DefineOutputIndex(2, ListNumberType, 'signal', 'Signal values')

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!