[kob Cmnd] Advanced Mad Hatter Indicators: MACD

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

    • This topic was modified 3 weeks, 6 days ago by kobalt.
    • This topic was modified 3 weeks, 6 days ago by kobalt.
    • This topic was modified 2 weeks, 5 days ago by Team HaasScripts.
    HaasScript Code
    -- Define command
    DefineCommand("MadHatterMACDv2", "Custom MACD 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')
    
    DefineIntervalOptimization(interval)
    
    -- Input fields for the indicator. Add the name in front.
    InputGroupHeader('MadHatter MACD '..name)
    local interval = InputInterval('   MACD Interval', 1, 'The timeframe for MadHatter MACD.', 'MHB MACD Settings')
    local fastLength = Input(name..'  MACD Fast', 12, {group = "MHB MACD Settings"}) 
    local slowLength = Input(name..' MACD Slow', 26, {group = "MHB MACD Settings"}) 
    local signalLength = Input(name..'MACD Signal', 4, {group = "MHB MACD Settings"}) 
    
    -- Calculate the indicator
    local prices = ClosePrices(interval)
    local macdData =  MACD(prices, fastLength, slowLength, signalLength)
    local macd = macdData[1]
    local signal = macdData[2]
    local hist = macdData[3]
    
    local signal = SignalNone
    if macdData.macd < macdData.signal and IsRising(macdData.hist, 1) then
        signal = SignalLong
    elseif macdData.macd > macdData.signal and macdData.hist[1] >= macdData.hist[2] then
        signal = SignalLong
    elseif macdData.macd > macdData.signal and IsFalling(macdData.hist, 1)  then
        signal = SignalShort
    elseif macdData.macd < macdData.signal and macdData.hist[1] <= macdData.hist[2] then
        signal = SignalLong
    end
    
    -- Plot the indicator Use the chartIndex parameter.
    PlotHistogramSignals(chartIndex, 'MHB', macdData.hist, macdData.macd, macdData.signal)
    
    --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