[kob] Advanced Mad Hatter Indicators: RSI

0 59 Views No Comments 4 weeks ago
  • MadHatter RSIV2 Added Input Menu Groups And Indicator Timeframe [kob] – Custom RSI signal implementation for Mad Hatter Extended v3.1 / Mad Hatter Basic

    • This topic was modified 4 weeks, 1 day ago by kobalt.
    • This topic was modified 3 weeks, 6 days ago by kobalt.
    HaasScript Code
    -- Define command
    DefineCommand("MadHatterRSIV2", "Custom RSI signal implementation for MadHatter")
    -- Added Input Menu Groups  [kob]
    -- Define command parameters.
    local chartIndex = DefineParameter(NumberType, 'chartIndex', 'The index on which to chart', true, 1, 'Number')
    local name = DefineParameter(StringType, 'name', 'Unique name of the indicator.', false, '', 'Text')
    local interval = DefineParameter(NumberType, 'interval', 'Used interval for price data. Default is 0 and the main interval will be used.', false, 0, 'Number,InputInterval')
    -- Input fields for the indicator. Add the name in front.
    InputGroupHeader('MadHatter RSI '..name)
    local interval = InputInterval(' RSI Interval', 1, 'The timeframe for MadHatter RSI.', 'MHB RSI Settings')
    local length = Input(name..' RSI Length', 14, {group = "MHB RSI Settings"}) 
    local buyLevel = Input(name..'RSI Buy Level', 30, {group = "MHB RSI Settings"}) 
    local sellLevel = Input(name..'RSI Sell Level', 70, {group = "MHB RSI Settings"}) 
    -- Calculate the indicator
    local prices = ClosePrices(interval)
    local rsi = RSI(prices, length)
    local signal = SignalNone
    if rsi < buyLevel and IsRising(rsi, 1) then
        signal = SignalLong
    elseif rsi[2] < buyLevel and IsRising(rsi, 1) then
        signal = SignalLong
    elseif rsi > sellLevel and IsFalling(rsi, 1) then
        signal = SignalShort
    elseif rsi[2] > sellLevel and IsFalling(rsi, 1) then
        signal = SignalShort
    -- Plot the indicator Use the chartIndex parameter.
    PlotLineBuySellZone(chartIndex, 'MHB RSI', rsi, buyLevel, sellLevel)
    ChartSetAxisOptions(chartIndex, RightAxis, 0, 100)
    --Return the custom signal.
    DefineOutput(EnumType, signal, 'Signal result', 'TradeBotContainer, IndicatorContainer, Signal Helpers')
Login or Register to Comment

Unlock your crypto trading potential

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

Join for Free