Lazy Bear Wave Trend V3

stable
By ajd1107 in Momentum Published September 2022 👁 1,485 views 💬 0 comments

Description

A TradingView classic, previously converted by the mighty Kobalt. I added some signal options and adjusted 2 of the signal parameters to be a little more responsive. Big thanks to Kobalt for the original conversion!
HaasScript
-- Wave Trend by Lazy Bear
-- Converted by Kobalt 
-- Further inputs by Fogg and Kobalt
 
DefineCommand ('WaveTrendV3', 'WaveTrend with 3 Signal Options' )
 
-- Define command parameters.
local chartIndex = DefineParameter(NumberType, 'chartIndex', 'index to plot WaveTrendCross', false, 11, 'Number')
local name = DefineParameter(StringType, 'name', 'Unique name of the indicator.', false, 'WaveTrendCross', 'Text')
local interval = DefineParameter(NumberType, 'interval', '', false, 0, 'Number, InputInterval')
local isPlotting = DefineParameter(BooleanType, 'Plot', 'Enable or disable plotting when backtest etc.', false, true, 'true/false')

-- Input fields for the indicator.
local weak = Input('Weak Signals?', false, 'Weaker long/short signals', {group = "Wave Trend Cross Settings"})
local normal = Input('Normal Signals?', true, 'Normal Overbought/Oversold Signals', {group = "Wave Trend Cross Settings"})
local extreme = Input('Extreme Signals?', true, 'Extreme Overbought/Oversold Signals', {group = "Wave Trend Cross Settings"})
local n1 = Input("Channel Length", 10, {group = "Wave Trend Cross Settings"}) 
local n2 = Input("Average Length", 21, {group = "Wave Trend Cross Settings"}) 
local obLevel1 = Input("Over Bought Level 1", 53, {group = "Wave Trend Cross Settings"}) 
local obLevel2 = Input(" Over Bought Level 2", 60, {group = "Wave Trend Cross Settings"}) 
local obLevel3 = Input(" Extreme Over Bought Level", 77, {group = "Wave Trend Cross Settings"})
local osLevel1 = Input("Over Sold Level 1", -53, {group = "Wave Trend Cross Settings"}) 
local osLevel2 = Input("Over Sold Level 2", -60, {group = "Wave Trend Cross Settings"}) 
local osLevel3 = Input(" Extreme Over Sold Level", -77, {group = "Wave Trend Cross Settings"})

local isPlotShapes = Input('PlotShapes', true, 'Plot Shapes', 'Wave Trend Cross Settings')

-- Speed optimization
local buy1, sell1, buy2, sell2, buy3, sell3 = OptimizedForInterval(interval,
function()
    local ap = HLCPrices()
    local esa = EMA(ap, n1)
    local d = EMA(Abs(ap - esa), n1)
    local ci = (ap - esa) / (0.015 * d)
    local tci = EMA(ci, n2)
   
    local wt1 = tci
    local wt2 = SMA(wt1,4)
 
    local color1 = SkyBlue
    local color2 = Fuchsia(78)
    local l1 = Plot(chartIndex, "WT1", wt1, color1)
    local l2 = Plot(chartIndex, "WT2", wt2, color2)

    if isPlotting then
        ChartSetOptions(chartIndex, 'Wave Trend Cross', 0.3)
        ChartSetAxisOptions(chartIndex, RightAxis, -85, 85)
        PlotDoubleColor(l1, 0, color1)
        PlotDoubleColor(l2, 0, color2)
 
        local histo = Plot(chartIndex, "Histogram", wt1-wt2, DarkGreen)
        PlotHistogram(histo, Orange, true)
 
        PlotHorizontalLine(chartIndex, "Zero", DarkGray, 0)
        PlotHorizontalLine(chartIndex, "OB1", Maroon(72), obLevel1)
        PlotHorizontalLine(chartIndex, "OS1", DarkGreen(72), osLevel1)
        PlotHorizontalLine(chartIndex, "OB2", Maroon(88), obLevel2)
        PlotHorizontalLine(chartIndex, "OS2", DarkGreen(88), osLevel2)
        PlotHorizontalLine(chartIndex, "OB3", Red(64), obLevel3)
        PlotHorizontalLine(chartIndex, "OS3", Green(64), osLevel3)
    end

-- Caculate Buy & Sell Signal.
 
    local cbuy = CrossOver(wt1, wt2)
 
    local csell = CrossUnder(wt1, wt2)
 
    local weakcbuy = cbuy and wt1 
 
    local strongcbuy = wt2 < osLevel1
 
    local weakcsell = csell and wt1
 
    local strongcsell = wt2 > obLevel1
 
    local extremecbuy = wt2 < osLevel3
 
    local extremecsell = wt2 > obLevel3
 
    return weakcbuy, weakcsell, strongcbuy, strongcsell, extremecbuy, extremecsell
 
end)
 
local signal = SignalNone
 
if normal then 
    if buy2 then
        signal = SignalLong
        if isPlotting and isPlotShapes then
        PlotShape(0, ShapeSquare, DarkGreen, 3, false)
        end
    elseif sell2 then
        signal = SignalShort
        if isPlotting and isPlotShapes then

        PlotShape(0, ShapeSquare, Maroon, 3, true)
        end
    end
end
 
if weak then
    if buy1 then
        signal = SignalLong
        if isPlotting and isPlotShapes then
        PlotShape(0, ShapeCircle, Teal, 3, false)
        end
    elseif sell1 then
        signal = SignalShort
        if isPlotting and isPlotShapes then
        PlotShape(0, ShapeCircle, Orange, 3, true)
        end
    end
end
 
if extreme then
    if buy3 then
        signal = SignalLong
        if isPlotting and isPlotShapes then
        PlotShape(0, ShapeTriangleUp, Green, 6, false)
        end
    elseif sell3 then
        signal = SignalShort
        if isPlotting and isPlotShapes then
        PlotShape(0, ShapeTriangleDown, Red, 6, true)
        end
    end
end 
 
-- PlotSignalEnum(-2, signal)
DefineOutput(EnumType, signal, 'Signal result', 'TradeBotContainer, IndicatorContainer, Signal Helpers')

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!