CPR Indicator

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

Description

CPR (central pivots range) Indicator written for HaasScript. Can be used simply without any inputs or adjusted in the left menu. Usage

signal = CPR()
DoSignal(signal)
-- Feel free to donate to support my work or if my script helped you in any way <3 -- BTC Adress: 33MsEAbA8tg7SpohgnCpSrmPTBih2UkhxQ --
HaasScript
-- Author: -- Discord:  @strooth#4739
-- Feel free to donate to support my work or if my script helped you in any way &lt;3
-- BTC Adress: 33MsEAbA8tg7SpohgnCpSrmPTBih2UkhxQ
--
local name,signal,P, BC, TC = 'CPR',SignalNone
DefineCommand(name, 'Central Pivot Range')
InputGroupHeader(name)
local interval = DefineParameter(NumberType, 'interval', 'Used interval for price data. Default is 0 and the main interval will be used.', false, InputInterval(name..' Interval', 1440), 'Number,InputInterval')
local penetration = DefineParameter(NumberType, 'penetration', 'Penetration threshold of top and bottom before signal.(0 to Disable)', false, Input(name..' Penetration', 1, '0 to Disable'), 'Number,InputInterval')
local percent = DefineParameter(NumberType, 'spread', 'Percentage spread between top and bottom pivots. (0 to Disable)', false, Input(name..' Spread', 0, '0 to Disable'), 'Number,InputInterval')
local offset = DefineParameter(NumberType, 'offset', 'Used offset for price data. Default is 1.', false, Input(name..' Offset', 0), 'Number,InputInterval')
local plot = DefineParameter(BooleanType, 'plot', 'enable plotting the bands', false, true, 'true/false')
DefineIntervalOptimization(interval)
local cpr = function()
    return OptimizedForInterval(interval, function()
        local H = Offset(HighPrices(interval), offset)
        local L = Offset(LowPrices(interval), offset)
        local C = Offset(ClosePrices(interval), offset)
        P = (H + L + C) / 3
        BC = (H+L)/2
        TC = (P-BC)+P
        return {Center=P,Bottom=BC,Top=TC}
        end 
    )
end 
local output = function()
    local int = CurrentInterval()
    return OptimizedForInterval(int, function()
        local result = cpr()
        local longstate = IsTrue(result.Top > result.Center)
        local shortstate = IsTrue(result.Bottom > result.Center)
        local swing = IfElse(longstate, GetSwing(result.Top, result.Bottom), GetSwing(result.Bottom, result.Top))
        if swing  > percent and shortstate then
            if result.Bottom > CurrentPrice().high then 
                signal = GetCrossOverUnderSignal(CurrentPrice().high, SubPerc(result.Top,penetration))
                signal = MapSignal(signal, SignalLong, SignalShort)
            elseif CurrentPrice().high > result.Center and result.Bottom > CurrentPrice().low then 
                signal = GetCrossOverUnderSignal(CurrentPrice().high, result.Bottom)

            end 
        elseif swing > percent and longstate then
            if CurrentPrice().high > result.Top then 
                signal = GetCrossOverUnderSignal(CurrentPrice().low, AddPerc(result.Top,penetration))
                signal = MapSignal(signal, SignalShort, SignalLong)
            elseif result.Top > CurrentPrice().low and CurrentPrice().high > result.Bottom then 
                signal = GetCrossOverUnderSignal(CurrentPrice().high, result.Center)
            end 
        end 
        local last_p = Load('last_p', result.Center)
        local guid = Load('guid', NewGuid())
        if last_p != result.Center then 
            guid= NewGuid()
            last_p = result.Center
        end 
        if percent > 0 and plot then 
        Plot(1, 'CPR - Top and Bottom Spread %', swing)
        end 
        if plot then 
        Plot(0, 'CPR - Top Center Pivot', result.Top, {c=White,id=guid})
        Plot(0, 'CPR - Center Pivot', result.Center, {c=SkyBlue,id=guid})
        Plot(0, 'CPR - Bottom Center Pivot', result.Bottom, {c=White,id=guid})
        end 
        Save('last_p', last_p)
        Save('guid', guid)
        return signal 
    end 
    )
end 
DefineOutput(EnumType, output(), 'Support and Resistance')

1 Comment

Sign in to leave a comment.

U
universaltasks over 4 years ago

Namaste,
How can attach this CPR indicator on my Binance account.