Pivot Points Indicator

stable
By Strooth in Momentum Published June 2021 👁 1,433 views 💬 0 comments

Description

An indicator for signaling on pivot points - fib, cam, woodie, td and also mashed up my own custom one using a blend of them all and threw some bands in to help get an average which is used to help with trend reversals by keeping the pivots above the center for example. Can be called without any parameters and adjusted with the inputs on the left menu.

signal = CC_Pivots()
DoSignal(signal)
HaasScript
-- Author: -- Discord:  @strooth#4739

DefineCommand('Pivots', 'Pivot Points')
local types = {'Strooth', 'Fibonacci', 'Floor', 'Woodie', 'Camarilla', 'TomDemark'}
local triggers = {'1', '2', '3', '4'}
-- Parameters
InputGroupHeader('Pivot Points')
local name = DefineParameter(StringType, 'name', 'Unique name of the indicator.', false, 'Pivot Points', 'Text')
local interval = DefineParameter(NumberType, 'interval', 'Used interval for price data. Default is 0 and the main interval will be used.', false, InputInterval(name..' Interval', 15), 'Number,InputInterval')
local offset = DefineParameter(NumberType, 'offset', 'Used offset for price data. Default is 1.', false, Input(name..' Offset', 0), 'Number,InputInterval')
local type = DefineParameter(StringType, 'type', 'The type of pivots used.', false, InputOptions(name..' Type', types[1], types), 'String')
local trigger = DefineParameter(NumberType, 'trigger', 'The pivot to trigger signal.', false, InputOptions(name..' Trigger', triggers[1], triggers), 'String')
local market = DefineParameter(DynamicType, 'market', 'The market for the price data', false, PriceMarket(), 'PriceMarket()')
local chartIndex = DefineParameter(NumberType, 'chartIndex', 'The index on which to chart', false, 0, 'Number')
local plot = DefineParameter(BooleanType, 'plot', 'enable plotting on the chart', false, true, 'true/false')
DefineIntervalOptimization(interval)

-- Data
local H = Offset(HighPrices(interval, true, market, false), offset)
local L = Offset(LowPrices(interval, true, market, false), offset)
local C = Offset(ClosePrices(interval, true, market, false), offset)
local O = Offset(OpenPrices(interval, true, market, false), offset)
local P, R1, R2, R3, S1, S2, S3, R4, S4, signal 
local fib4 = (H - L) * 1.236
local fib3 = (H - L) * 1.000
local fib2 = (H - L) * 0.618
local fib1 = (H - L) * 0.382
-- floor
if type == types[2] or type == types[3] then 
P = (H + L + C) / 3
R1 = ((2 * P) - L) 
R2 = (P + H - L) 
R3 = (H + 2 * (P - L))
R4 = (H + 3 * (P - L))
S1 = ((2 * P) - H)
S2 = (P - H + L)
S3 = (L - 2 * (H - P))
S4 = (L - 3 * (H - P))
end 
-- fibs
if type == types[2] then 
R1 = R1 + fib1
R2 = R2 + fib2
R3 = R3 + fib3
R4 = R4 + fib4
S1 = S1 - fib1
S2 = S2 - fib2
S3 = S3 - fib3
S4 = S4 - fib4
end 
-- woodie
if type == types[4] then 
P = (H + L + (2 * C)) / 4
R1 = (2 * P) - L
R2 = P + H - L
S1 = (2 * P) - H
S2 = P - H + L
end 
-- camarilla
if type == types[5] then 
R4 = (H - L) * 1.1 / 2 + C
R3 = (H - L) * 1.1 / 4 + C
R2 = (H - L) * 1.1 / 6 + C
R1 = (H - L) * 1.1 / 12 + C
S1 = C - (H - L) * 1.1 / 12
S2 = C - (H - L) * 1.1 / 6
S3 = C - (H - L) * 1.1 / 4
S4 = C - (H - L) * 1.1 / 2
end 
-- tom demark
if type == types[6] then 
local X
if C < O then X = H + 2 * L + C end 
if C > O then X = 2 * H + L + C end 
if C == O then X = H + L + 2 * C end 
R1 = X / 2 - L
S1 = X / 2 - H
end 
-- strooth
if type == types[1] then 
P = (H + L + C) / 3
-- floor
local R1_flr = ((2 * P) - L) 
local R2_flr = (P + H - L) 
local R3_flr = (H + 2 * (P - L))
local R4_flr = (H + 3 * (P - L))
local S1_flr = ((2 * P) - H)
local S2_flr = (P - H + L)
local S3_flr = (L - 2 * (H - P))
local S4_flr = (L - 4 * (H - P))
-- fib
local R1_fib = R1_flr + fib1
local R2_fib = R2_flr + fib2
local R3_fib = R3_flr + fib3
local R4_fib = R4_flr + fib4
local S1_fib = S1_flr - fib1
local S2_fib = S2_flr - fib2
local S3_fib = S3_flr - fib3
local S4_fib = S4_flr - fib4
-- woodie
P = (H + L + (2 * C)) / 4
local R1_wd = (2 * P) - L
local R2_wd = P + H - L
local S1_wd = (2 * P) - H
local S2_wd = P - H + L
-- camarilla
local R4_cmrla = (H - L) * 1.1 / 2 + C
local R3_cmrla = (H - L) * 1.1 / 4 + C
local R2_cmrla = (H - L) * 1.1 / 6 + C
local R1_cmrla = (H - L) * 1.1 / 12 + C
local S1_cmrla = C - (H - L) * 1.1 / 12
local S2_cmrla = C - (H - L) * 1.1 / 6
local S3_cmrla = C - (H - L) * 1.1 / 4
local S4_cmrla = C - (H - L) * 1.1 / 2

local rdiff1 = Max(R1, R1_flr, R1_fib, R1_wd, R1_cmrla)-Min(R1, R1_flr, R1_fib, R1_wd, R1_cmrla)
local rdiff2 = Max(R2_flr, R2_fib, R2_wd, R2_cmrla)-Min(R2_flr, R2_fib, R2_wd, R2_cmrla)
local sdiff1 = Max(S1, S1_flr, S1_fib, S1_wd, S1_cmrla)-Min(S1, S1_flr, S1_fib, S1_wd, S1_cmrla)
local sdiff2 = Max(S2_flr, S2_fib, S2_wd, S2_cmrla)-Min(S2_flr, S2_fib, S2_wd, S2_cmrla)
R1 = (rdiff1 + R1_flr + R1_fib + R1_wd + R1_cmrla)/4
R2 = (rdiff2 + R2_flr + R2_fib + R2_wd + R2_cmrla)/4
R1 = (R1 + R2) / 2
R3 = (rdiff2 + R3_flr + R3_fib + R3_cmrla)/3
R3 = (rdiff2 + R3_flr + R3_fib + R3_cmrla)/3
R3 = (R3 + R2) / 2
R4 = (rdiff2 + R4_cmrla + R4_fib) / 2
R3 = (R3 + R2) / 2


S1 = FilterBelow((S1_flr + S1_fib + S1_wd + S1_cmrla - sdiff1)/4 ,0)
S2 = FilterBelow((S2_flr + S2_fib + S2_wd + S2_cmrla - sdiff2)/4 ,0)
S1 = (S1 + S2) / 2
S3 = FilterBelow((S3_flr + S3_fib + S3_cmrla - sdiff2)/3,0)
S3 = (S3 + S2) / 2
S4 = FilterBelow(Average(S4_fib, S4_cmrla) - sdiff2,0)
S3 = (S3 + S4) / 2
end 

local last_R4 = Load('R4', R4)
local R4guid = Load('R4guid', NewGuid())
if last_R4 != R4 then 
    R4guid= NewGuid()
    last_R4 = R4
end 
local last_R3 = Load('R3', R3)
local R3guid = Load('R3guid', NewGuid())
if last_R3 != R3 then 
    R3guid= NewGuid()
    last_R3  = R3
end 
local last_R2 = Load('R2', R2)
local R2guid = Load('R2guid', NewGuid())
if last_R2 != R2 then 
    R2guid= NewGuid()
    last_R2  = R2
end 
local last_R1 = Load('R1', R1)
local R1guid = Load('R1guid', NewGuid())
if last_R1 != R1 then 
    R1guid= NewGuid()
    last_R1  = R1
end 
local last_S1 = Load('S1', S1)
local S1guid = Load('S1guid', NewGuid())
if last_S1 != S1 then 
    S1guid= NewGuid()
    last_S1  = S1
end 
local last_S2 = Load('S2', S2)
local S2guid = Load('S2guid', NewGuid())
if last_S2 != S2 then 
    S2guid= NewGuid()
    last_S2  = S2
end 
local last_S3 = Load('S3', S3)
local S3guid = Load('S3guid', NewGuid())
if last_S3 != S3 then 
    S3guid = NewGuid()
    last_S3  = S3
end 
local last_S4 = Load('S4', S4)
local S4guid = Load('S4guid', NewGuid())
if last_S4 != S4 then 
    S4guid= NewGuid()
    last_S4  = S4
end 
local savg = (S1 + S2 + S3 + S4)/4
local ravg = (R1 + R2 + R3 + R4)/4
local cp = CurrentPrice()
local highx = Load('highx', cp.high)
local lowx = Load('lowx', cp.low)
local trend = Load('trend', NoPosition)
local lookback = 20
local isrising = IsRising(savg, lookback) and IsRising(ravg, lookback)
local isfalling = IsFalling(savg, lookback) and IsFalling(ravg, lookback)
local s_Slope = AddPerc(LINEARREG(savg, lookback, LR_Slope)*1000, 1)
local r_Slope = SubPerc(LINEARREG(ravg, lookback, LR_Slope)*1000, 1)
local s_Slope_lt0 = IsSmallerThan(s_Slope, 0)
local r_Slope_lt0 = IsSmallerThan(r_Slope, 0)
local s_Slope_gt0 = IsBiggerThan(s_Slope, 0)
local r_Slope_gt0 = IsBiggerThan(r_Slope, 0)
local lb = 1
local slopeup = Or(IsRising(s_Slope, lb),IsRising(r_Slope, lb))
local slopedown = Or(IsFalling(s_Slope, lb),IsFalling(r_Slope, lb))
ravg = SMA(ravg, lookback)
savg = SMA(savg, lookback)
local middle = (ravg+savg)/2
if R1 < middle then 
local diff = middle-R1
R1 = middle
R2 = R2 + diff
R3 = R3 + diff
R4 = R4 + diff
if S1 > savg then 
diff = S1 - savg 
S1 = savg
S2 = S2 - diff
S3 = S3 - diff
S4 = S4 - diff
end 
end 
if S1 > middle then 
local diff = S1 - middle 
S1 = middle
S2 = S2 - diff
S3 = S3 - diff
S4 = S4 - diff
if R1 < ravg then 
diff = ravg-R1
R1 = ravg
R2 = R2 + diff
R3 = R3 + diff
R4 = R4 + diff
end 
end 


Save('R1', last_R1)
Save('S1', last_S1)
Save('R1guid', R1guid)
Save('S1guid', S1guid)
if plot then 
Plot(0, 'R1', R1, {c=Red, id=R1guid})
Plot(0, 'S1', S1, {c=Green, id=S1guid})
Plot(0, 'RAVG', ravg, {c=Orange })
Plot(0, 'SAVG', savg, {c=Yellow})
Plot(0, 'Middle', middle, {c=White})
end 
--Plot(1, 's_Slope', s_Slope, White)
--Plot(1, 'r_Slope', r_Slope, SkyBlue)

local support, resistance 

if type != types[6] then 
    Save('R2', last_R2)
    Save('R2guid', R2guid)
    Save('S2', last_S2)
    Save('S2guid', S2guid)
    if plot then 
    Plot(0, 'R2', R2, {c=Fuchsia, id=R2guid})
    Plot(0, 'S2', S2, {c=Olive, id=S2guid})
    end 
    if type != types[4] then 
        Save('R3', last_R3)
        Save('R3guid', R3guid)
        Save('S3', last_S3)
        Save('S3guid', S3guid)
        if plot then 
        Plot(0, 'R3', R3, {c=Purple, id=R3guid})
        Plot(0, 'S3', S3, {c=Teal, id=S3guid})
        end 
        Save('R4', last_R4)
        Save('S4', last_S4)
        Save('R4guid', R4guid)
        Save('S4guid', S4guid)
        Plot(0, 'R4', R4, {c=Maroon, id=R4guid})
        Plot(0, 'S4', S4, {c=DarkGreen, id=S4guid})
        support = {savg, S1, S2, S3, S4}
        resistance = {ravg, R1, R2, R3, R4}
    else
        support = {savg, S1, S2}
        resistance = {ravg, R1, R2}
    end 
end 

local signal = SignalNone
for i=trigger, #support do 
    local s = support[i]
    if cp.bid < s and IsTrue(s_Slope_lt0, r_Slope_lt0) then 
        signal = SignalLong 
        
    end 
end 
for i=trigger, #resistance do 
    local r = resistance[i]
    if cp.ask > r and IsTrue(s_Slope_gt0, r_Slope_gt0) then 
        signal = SignalShort
    end 
end 


DefineOutput(ListDynamicType, {signal, support, resistance}, 'Support and Resistance')
DefineOutputIndex(1, EnumType, 'Signal', 'Signal')
DefineOutputIndex(2, ListDynamicType, 'Support', 'Support')
DefineOutputIndex(3, ListDynamicType, 'Resistance', 'Resistance')

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!