[pshaiCmd] Average Change Oscillator

0 167 Views No Comments 9 months ago
  • ACO indicator custom command

    HaasScript Code
    -- ==============================================
    -- 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')
Login or Register to Comment

Unlock your crypto trading potential

Create a free account and enjoy everything we have to offer.

Join for Free