Firetron’s GetKeltnerSpread

1 46 Views No Comments 2 weeks ago
  • Creates a spread of prices based on Keltner channels.

    Custom Command Dependencies:
    Firetron’s XTR

    Test Code:

    local LogList = function (list)
    
      local text = ''
    
      for i = 1, #list do
    
        if i ~= 1 then
          text = text..', '
        end
    
        text = text..list[i]
    
      end
    
      Log(text)
    
    end
    
    local PlotOne = function (value, color, id, name)
    
      local lineOptions = LineOptions(
        color,     -- color
        Smooth,    -- style
        Solid,     -- deco
        1,         -- width
        0,         -- offset
        RightAxis, -- side
        id,        -- id
        true,      -- behind
        false      -- ignoreOnAxis
      )
    
      Plot(0, name, value, lineOptions)
    
    end
    
    local PlotAll = function (list, color, id, name)
    
      for i = 1, #list do
    
        PlotOne(list[i], color, id..i, name..i)
    
      end
    
    end
    
    local Execute = function ()
    
      local omni           = false
      local maType         = EmaType
      local maPeriod       = 20
      local trType         = 'average'
      local trPeriod       = 50
      local multiplierList = {2, 3, 4, 5}
      local interval       = 60
      local fullCandles    = true
      local market         = PriceMarket()
      local hlcStyle       = false
      local index          = 1
      local total          = 1
      local isPercent      = false
    
      Log(' ')
    
      local spread = CC_GetKeltnerSpread(omni, maType, maPeriod, trType, trPeriod, multiplierList, interval, fullCandles, market, hlcStyle, index, total, isPercent)
    
      LogList(spread.lowerList)
      Log('Lower Spread:')
      Log(' ')
    
      Log(spread.middle)
      Log('Middle:')
      Log(' ')
    
      LogList(spread.upperList)
      Log('Upper Spread:')
      Log(' ')
    
      PlotAll(spread.upperList, Red,    'upper',  'Upper ')
      PlotOne(spread.middle,    Yellow, 'middle', 'Middle')
      PlotAll(spread.lowerList, Green,  'lower',  'Lower ')
    
    end
    
    OptimizedForInterval(60, Execute)
    • This topic was modified 1 week, 4 days ago by Firetron. Reason: Fixed typo in comment
    • This topic was modified 1 week, 2 days ago by Firetron. Reason: Added maType parameter
    • This topic was modified 1 week, 2 days ago by Firetron. Reason: Added trType parameter
    • This topic was modified 1 week, 2 days ago by Firetron. Reason: Added link to dependency
    • This topic was modified 1 week, 2 days ago by Firetron. Reason: Fix for isPercent
    HaasScript Code
    Sign in or Register to view
Login or Register to Comment

Unlock your crypto trading potential

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

Join for Free