[pshaiScript] Average Change Oscillator v2
stableDescription
Optimized version of the default script.
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.
-- ==============================================
-- == Functions ==
-- Here is the ACO itself. It's simple, but quite nice if I may say... ;)
local ACO = function(input, smoothing, smalength1)
local lookback = (smalength1 * 3) + 10 -- speed optimisation part 1
local source1 = Grab(input, 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
-- Calculate the data we want, which is a normal average
for i=1, tempLen-smoothing
do
values = Grab(temp, i-1, smoothing)
result[i] = Average(values)
end
local sma1 = SMA(result, smalength1)
return {Sub(result, sma1), sma1}
end
-- Inputs
local close = ClosePrices()
local smoothlen = Input('Period smoothing', 10)
local smalen1 = Input('SMA length', 20)
-- Calculate ACO
local aco = OptimizedForInterval(CurrentInterval(), function()
return ACO(close, smoothlen, smalen1)
end)
Plot(1, '', 0, DarkGray(75)) -- Zero-line
local acoPlot = Plot(1, 'ACO', aco[1][1], {color=Green, style=Spiked}) -- The ACO line..
PlotDoubleColor(acoPlot, 0.0, Red, Gray(15)) -- ...with some icing
Plot(1, 'SMA', aco[2][1], {color=Gray, style=Smooth}) -- The SMA of ACO
local rise = IsRising(aco[2], 3)
local fall = IsFalling(aco[2], 3)
-- Signal types #1: SMA of ACO is rising or falling
if (rise and not fall) then
PlotSignalBar(-2, 'rgb(0,128,0)') -- Buy signal
elseif (not rise and fall) then
PlotSignalBar(-2, 'rgb(128,0,0)') -- Sell signal
end
-- Signal types #2: ACO and its SMA crossover and crossunder
local acoLine = aco[1]
local acoSignal = aco[2]
if CrossOver(acoLine, acoSignal) then
DoLong()
elseif CrossUnder(acoLine, acoSignal) then
DoShort()
end
-- Other ways of interpreting ACO:
-- - ACO line crosses zero-line
-- - SMA of ACO crosses zero-line
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!